Example #1
0
    def __show_all_flight_attendants():
        LogicAPI.update_states()  #UPDATES ALL STATES BEFOR DISPLAYING

        user_input = ""
        while user_input not in EmployeeUI.__NAVIGATION_BAR_OPTIONS:
            table_header_tuple = ("Name", "SSN", "Phone number",
                                  "Home address", "E-mail", "State")
            flight_attendants_list = LogicAPI.get_all_flight_attendants()
            flight_attendants_value_tuple = ([flight_attendant.get_name() for flight_attendant in flight_attendants_list],[flight_attendant.get_ssn() for flight_attendant in flight_attendants_list],\
            [flight_attendant.get_phonenumber() for flight_attendant in flight_attendants_list], [flight_attendant.get_home_address() for flight_attendant in flight_attendants_list],\
            [flight_attendant.get_email() for flight_attendant in flight_attendants_list], [flight_attendant.get_state() for flight_attendant in flight_attendants_list])
            table_height = len(flight_attendants_list)

            ComponentUI.print_frame_table_menu(table_header_tuple,
                                               flight_attendants_value_tuple,
                                               table_height,
                                               EmployeeUI.__FRAME_IN_USE_STR,
                                               "All flight attendants")
            user_input = ComponentUI.get_user_input()
            user_input = ComponentUI.remove_brackets(user_input)
            if not user_input.isdigit() or int(user_input) > table_height:
                continue
            table_index = int(user_input) - 1
            flight_attendant = flight_attendants_list[table_index]

            user_input = EmployeeUI.__show_employee(flight_attendant)

        return user_input
    def __show_airplanes_in_use():
        LogicAPI.update_states() #UPDATES ALL STATES BEFOR DISPLAYING


        ComponentUI.print_header(AirplanesUI.__FRAME_IN_USE_STR)
        print(TextEditor.format_text("All airplanes in use", TextEditor.UNDERLINE_TEXT))
        user_input = ""
        while user_input not in AirplanesUI.__NAVIGATION_BAR_OPTIONS:
            table_header_tuple = ("Name", "State", "Type", "Manufacturer", "Seats")
            airplanes_list = LogicAPI.get_all_airplanes_in_use()
            if airplanes_list:
                airplanes_getfunctions_tuple = ([airplane.get_name() for airplane in airplanes_list],[airplane.get_state() for airplane in airplanes_list],\
                [airplane.get_type() for airplane in airplanes_list], [airplane.get_manufacturer() for airplane in airplanes_list], [airplane.get_seat_count() for airplane in airplanes_list])
                table_height = len(airplanes_list)
                ComponentUI.print_frame_table_menu(table_header_tuple,airplanes_getfunctions_tuple, table_height, AirplanesUI.__FRAME_IN_USE_STR, "All airplanes in use")
                user_input = ComponentUI.get_user_input()
                user_input = ComponentUI.remove_brackets(user_input)
                if not user_input.isdigit() or int(user_input) > table_height:
                    continue
                table_index = int(user_input)-1
                airplane = airplanes_list[table_index]        

                user_input = AirplanesUI.__show_airplane(airplane)
            else:
                ComponentUI.print_header(AirplanesUI.__FRAME_IN_USE_STR)
                print(TextEditor.format_text("All airplanes in use", TextEditor.UNDERLINE_TEXT))
                ComponentUI.centered_text_message("There are no airplanes in use at the moment !","",3)

           
            return user_input
Example #3
0
    def __show_all_employees():
        LogicAPI.update_states()  #UPDATES ALL STATES BEFOR DISPLAYING

        user_input = ""
        while user_input not in EmployeeUI.__NAVIGATION_BAR_OPTIONS:
            table_header_tuple = ("Job title", "Name", "SSN", "Phone number",
                                  "Home address", "E-mail", "State")
            all_employees_list = LogicAPI.get_all_employees()
            employees_getfunctions_tuple = (["Pilot" if isinstance(employee, Pilot) else "Flight attendant" for employee in all_employees_list], [employee.get_name() for employee in all_employees_list],[employee.get_ssn() for employee in all_employees_list],\
            [employee.get_phonenumber() for employee in all_employees_list],[employee.get_home_address() for employee in all_employees_list],[employee.get_email() for employee in all_employees_list],\
            [employee.get_state() for employee in all_employees_list])
            table_height = len(all_employees_list)
            ComponentUI.print_frame_table_menu(table_header_tuple,
                                               employees_getfunctions_tuple,
                                               table_height,
                                               EmployeeUI.__FRAME_IN_USE_STR,
                                               "All employees")
            user_input = ComponentUI.get_user_input()
            user_input = ComponentUI.remove_brackets(user_input)
            if not user_input.isdigit() or int(user_input) > table_height:
                continue
            table_index = int(user_input) - 1
            employee = all_employees_list[table_index]

            user_input = EmployeeUI.__show_employee(employee)

        return user_input
Example #4
0
    def __show_employee_voyages(employee):
        is_pilot = isinstance(employee, Pilot)

        user_input = ""

        info_header_tuple = ("Destination", "Airplane name", "Start time",
                             "End time", "State")

        while user_input not in EmployeeUI.__NAVIGATION_BAR_OPTIONS:
            ComponentUI.print_header(EmployeeUI.__FRAME_IN_USE_STR)
            print(
                TextEditor.format_text(
                    "Voyages for {}".format(employee.get_name()),
                    TextEditor.UNDERLINE_TEXT))

            ComponentUI.fill_window_and_print_action_line(1)

            user_input = input("Insert a week number: ").strip()

            if not user_input:
                continue

            voyages_list = []

            if user_input.isdigit():
                voyages_list = LogicAPI.get_all_pilot_voyages_in_a_week(employee, int(user_input)) if is_pilot\
                    else LogicAPI.get_all_flight_attendant_voyages_in_a_week(employee ,int(user_input))

            if not voyages_list:
                ComponentUI.print_header(EmployeeUI.__FRAME_IN_USE_STR)
                print(
                    TextEditor.format_text("Find employees voyages",
                                           TextEditor.UNDERLINE_TEXT))
                ComponentUI.centered_text_message(
                    "Could not find a voyage going for {} in week {}".format(
                        employee.get_name(), user_input), "", 3)

                return ComponentUI.get_user_input()

            else:
                voyage_info_tuple = ([voyage.get_flights()[0].get_arrival_location() for voyage in voyages_list],\
                [voyage.get_airplane().get_name() for voyage in voyages_list],\
                [voyage.get_schedule()[0] for voyage in voyages_list],\
                [voyage.get_schedule()[1] for voyage in voyages_list],\
                [voyage.get_state() for voyage in voyages_list])

                table_height = len(voyages_list)
                ComponentUI.print_frame_table_menu(info_header_tuple, voyage_info_tuple, \
                    table_height, ComponentUI.print_header(EmployeeUI.__FRAME_IN_USE_STR),"Voyages for {}".format(employee.get_name()))
                user_input = ComponentUI.get_user_input()
                user_input = ComponentUI.remove_brackets(user_input)
                if not user_input.isdigit() or int(user_input) > table_height:
                    continue
                table_index = int(user_input) - 1
                voyage = voyages_list[table_index]
                user_input = VoyageUI.show_voyage(voyage)

            return user_input
Example #5
0
    def __show_pilot_by_license_finder():
        LogicAPI.update_states()  #UPDATES ALL STATES BEFOR DISPLAYING

        user_input = ""

        info_header_tuple = ("Name", "SSN", "Phone number", "Home address",
                             "E-mail", "State")

        while user_input not in EmployeeUI.__NAVIGATION_BAR_OPTIONS:
            ComponentUI.print_header(EmployeeUI.__FRAME_IN_USE_STR)
            #display table of airplane types and return the type-name the of chosen one , head above the the table
            user_input = EmployeeUI.__airplane_type_picker(
                "Find pilots by license")

            if not user_input:
                continue

            user_input = user_input

            pilots_list = []

            pilots_list = LogicAPI.get_licensed_pilots(user_input)

            ComponentUI.print_header(EmployeeUI.__FRAME_IN_USE_STR)

            if not pilots_list:
                print(
                    TextEditor.format_text("Find pilots by license",
                                           TextEditor.UNDERLINE_TEXT))
                ComponentUI.centered_text_message(
                    "Could not find a pilot with a license for {}".format(
                        user_input), "", 3)
                user_input = ComponentUI.get_user_input()
                if not user_input:
                    return EmployeeUI.__show_pilot_by_license_finder()

                return user_input

            else:
                #print(TextEditor.format_text("Pilots with license for " + user_input, TextEditor.UNDERLINE_TEXT))
                pilot_info_tuple = ([pilot.get_name() for pilot in pilots_list],[pilot.get_ssn() for pilot in pilots_list],\
                [pilot.get_phonenumber() for pilot in pilots_list],[pilot.get_home_address() for pilot in pilots_list],[pilot.get_email() for pilot in pilots_list],\
                [pilot.get_state() for pilot in pilots_list])
                table_height = len(pilots_list)
                ComponentUI.print_frame_table_menu(
                    info_header_tuple, pilot_info_tuple, table_height,
                    EmployeeUI.__FRAME_IN_USE_STR,
                    "Pilots with license for " + user_input)
                user_input = ComponentUI.get_user_input()
                user_input = ComponentUI.remove_brackets(user_input)
                if not user_input.isdigit() or int(user_input) > table_height:
                    continue
                table_index = int(user_input) - 1
                employee = pilots_list[table_index]

                user_input = EmployeeUI.__show_employee(employee)

            return user_input
    def __show_all_airplane_types():
        ComponentUI.print_header(AirplanesUI.__FRAME_IN_USE_STR)
        print(TextEditor.format_text("All airplane types", TextEditor.UNDERLINE_TEXT))
        user_input = ""

        

        while user_input not in AirplanesUI.__NAVIGATION_BAR_OPTIONS:
            table_header_tuple = ("Type", "Manufacturer", "Seats")
                  
           
            airplane_type_list = LogicAPI.get_all_airplane_types()
            airplanes_type_getfunctions_tuple = ([aircraft_type.get_plane_type() for aircraft_type in airplane_type_list],[aircraft_type.get_manufacturer() for aircraft_type in airplane_type_list],\
                [aircraft_type.get_seat_count() for aircraft_type in airplane_type_list])
            table_height = len(airplane_type_list)

            ### - ONLY DISPLAY TABLE - ##

            ComponentUI.fill_in_table(table_header_tuple, airplanes_type_getfunctions_tuple, False)
            ComponentUI.fill_window_and_print_action_line(table_height+2) 


            #ComponentUI.print_frame_table_menu(table_header_tuple, airplanes_type_getfunctions_tuple, table_height, ComponentUI.print_header(AirplanesUI.__FRAME_IN_USE_STR),"All airplane types")
            user_input = ComponentUI.get_user_input()
            user_input = ComponentUI.remove_brackets(user_input)
            if not user_input.isdigit() or int(user_input) > table_height:
                    continue
            table_index = int(user_input)-1
            airplane = airplane_type_list[table_index]        

            user_input = AirplanesUI.__show_airplane(airplane)

        return user_input
Example #7
0
    def __show_all_flight_routes():

        user_input = ''

        #ComponentUI.print_header(FlightRouteUI.__FRAME_IN_USE_STR)
        #print(TextEditor.format_text("Show all flight routes", TextEditor.UNDERLINE_TEXT))

        while user_input not in FlightRouteUI.__NAVIGATION_BAR_OPTIONS:

            table_header = ("Destination", "Airport", "Country", "Flight-time",
                            "Distance", "Contact", "Emergency phone")
            flrt_list = LogicAPI.get_all_flight_routes()
            flight_routes_value_tuple = ([flightr.get_destination() for flightr in flrt_list],[flightr.get_airport_id() for flightr in flrt_list],\
                [flightr.get_country() for flightr in flrt_list],[flightr.get_flight_time() for flightr in flrt_list],[flightr.get_distance_from_iceland() for flightr in flrt_list],\
                    [flightr.get_contact_name() for flightr in flrt_list],[flightr.get_emergency_phone() for flightr in flrt_list])

            table_height = len(flrt_list)
            ComponentUI.print_frame_table_menu(
                table_header, flight_routes_value_tuple, table_height,
                FlightRouteUI.__FRAME_IN_USE_STR, "All flight routes")

            user_input = ComponentUI.get_user_input()

            user_input = ComponentUI.remove_brackets(user_input)
            if not user_input.isdigit() or int(user_input) > table_height:
                continue

            table_index = int(user_input) - 1

            selected_flrt = flrt_list[table_index]
            # senda inn í nýtt fall

            user_input = FlightRouteUI.__show_flight_route(selected_flrt)

        return user_input
Example #8
0
    def __airplane_type_picker(header="License"):

        #### PICK AIRPLANE TYPE BY TABLE LIST ###
        table_header_tuple = ("Type", "Manufacturer", "Seats")

        airplane_type_list = LogicAPI.get_all_airplane_types()
        airplanes_type_getfunctions_tuple = ([aircraft_type.get_plane_type() for aircraft_type in airplane_type_list],[aircraft_type.get_manufacturer() for aircraft_type in airplane_type_list],\
            [aircraft_type.get_seat_count() for aircraft_type in airplane_type_list])
        table_height = len(airplane_type_list)


        ComponentUI.print_frame_table_menu(table_header_tuple, airplanes_type_getfunctions_tuple, table_height,\
            ComponentUI.get_main_options()[2], header)

        user_input = ComponentUI.get_user_input(
            "Insert number of desired type: ")

        user_input = ComponentUI.remove_brackets(user_input)
        if not user_input.isdigit() or int(
                user_input) > table_height or not user_input:
            return None

        table_index = int(user_input) - 1
        chosen_table_line = airplane_type_list[table_index]
        ###                LINE PICKED           ##
        return chosen_table_line.get_plane_type()
Example #9
0
    def __show_employees_off_duty():
        LogicAPI.update_states()  #UPDATES ALL STATES BEFOR DISPLAYING

        ComponentUI.print_header(EmployeeUI.__FRAME_IN_USE_STR)
        print(
            TextEditor.format_text("All employees off duty",
                                   TextEditor.UNDERLINE_TEXT))
        user_input = ""
        while user_input not in EmployeeUI.__NAVIGATION_BAR_OPTIONS:
            table_header_tuple = ("Name", "SSN", "Phone number",
                                  "Home address", "E-mail", "State")
            employees_off_duty_list = LogicAPI.get_employees_off_duty()
            if employees_off_duty_list:
                employees_off_duty_value_tuple = ([employees_off_duty.get_name() for employees_off_duty in employees_off_duty_list],[employees_off_duty.get_ssn() for employees_off_duty in employees_off_duty_list],\
                [employees_off_duty.get_phonenumber() for employees_off_duty in employees_off_duty_list], [employees_off_duty.get_home_address() for employees_off_duty in employees_off_duty_list],\
                [employees_off_duty.get_email() for employees_off_duty in employees_off_duty_list], [employees_off_duty.get_state() for employees_off_duty in employees_off_duty_list])
                table_height = len(employees_off_duty_list)
                ComponentUI.print_frame_table_menu(
                    table_header_tuple, employees_off_duty_value_tuple,
                    table_height, EmployeeUI.__FRAME_IN_USE_STR,
                    "All employees off duty")
                user_input = ComponentUI.get_user_input()
                user_input = ComponentUI.remove_brackets(user_input)
                if not user_input.isdigit() or int(user_input) > table_height:
                    continue
                table_index = int(user_input) - 1
                employee_off_duty = employees_off_duty_list[table_index]

                user_input = EmployeeUI.__show_employee(employee_off_duty)

            else:
                ComponentUI.print_header(EmployeeUI.__FRAME_IN_USE_STR)
                print(
                    TextEditor.format_text("Employees off duty",
                                           TextEditor.UNDERLINE_TEXT))

                ComponentUI.centered_text_message(
                    "No employee is off duty at the moment", "", 3)
                user_input = ComponentUI.get_user_input()

            return user_input
    def __show_new_airplane_constructor():
               
        option_tuple = ("Name", "Type", "Manufacturer", "Seating capacity")

        valid_user_inputs = ComponentUI.make_valid_menu_options_tuple(len(option_tuple))

        input_message_tuple = ("Insert Name: ", "Insert Type: ", "Insert Manufacturer: ", "Insert Seating capacity: ")

        user_input_list = [""] * len(option_tuple)
        user_input_list.append(State.get_airplane_states()[0]) #State default value
        valid_for_submit_list = [False, False] # only 2 chosse here * len(option_tuple) #list that contains bools if all true then ok to submit


        user_input = ""



        while user_input not in AirplanesUI.__NAVIGATION_BAR_OPTIONS:

            ComponentUI.print_frame_constructor_menu(option_tuple, ComponentUI.get_main_options()[2],\
                 "New airplane", user_input_list, True, 1000, [2,3], True)

            user_input = ComponentUI.get_user_input()

            if not user_input:
                continue

            user_input = ComponentUI.remove_brackets(user_input)

            if user_input in valid_user_inputs:
                index = int(user_input) - 1


                if index == 0:
                    ComponentUI.print_frame_constructor_menu(option_tuple, ComponentUI.get_main_options()[2],\
                     "New airplane", user_input_list, False, index)
                    user_input = input(input_message_tuple[index]).strip()
                elif index == 1:

                    #### PICK AIRPLANE TYPE BY TABLE LIST ###
                    table_header_tuple = ("Type", "Manufacturer", "Seats")
                 
                    airplane_type_list = LogicAPI.get_all_airplane_types()
                    airplanes_type_getfunctions_tuple = ([aircraft_type.get_plane_type() for aircraft_type in airplane_type_list],[aircraft_type.get_manufacturer() for aircraft_type in airplane_type_list],\
                        [aircraft_type.get_seat_count() for aircraft_type in airplane_type_list])
                    table_height = len(airplane_type_list)


                    ComponentUI.print_frame_table_menu(table_header_tuple, airplanes_type_getfunctions_tuple, table_height,\
                        ComponentUI.get_main_options()[2], "New airplane")

                    user_input = ComponentUI.get_user_input("Insert number of desired type: ")

                    user_input = ComponentUI.remove_brackets(user_input)
                    if not user_input.isdigit() or int(user_input) > table_height or not user_input:
                        continue

                    table_index = int(user_input) - 1
                    chosen_table_line = airplane_type_list[table_index]
                    ###                LINE PICKED           ##


                    user_input_list[1] = chosen_table_line.get_plane_type()
                    user_input_list[2] = chosen_table_line.get_manufacturer()
                    user_input_list[3] = chosen_table_line.get_seat_count()
                    valid_for_submit_list[1] = True

                #Check if airplane name already exists
                if index == 0: 
                    user_input = user_input.capitalize()
                    if not LogicAPI.is_airplane_name_available(user_input):
                        user_input = user_input + " " + TextEditor.color_text_background("Airplane name already exists, another input is required", TextEditor.RED_BACKGROUND)
                        valid_for_submit_list[0] = False
                    else:
                        valid_for_submit_list[0] = True

                if index == 0:
                    user_input_list[index] = user_input
                
                user_input = ""

            elif user_input.startswith('s'):
                if all(valid_for_submit_list):

                    new_airplane = Airplane(
                        user_input_list[0],
                        user_input_list[1],
                        user_input_list[2],
                        user_input_list[3],
                        user_input_list[4]
                    )
                    LogicAPI.save_new_airplane(new_airplane)
                    user_input = "A new airplane has been registered"

                    break

        return user_input
    def __show_airplane(airplane):
        LogicAPI.update_states() #UPDATES ALL STATES BEFOR DISPLAYING

        user_input = ''
        user_input_list = [
            airplane.get_name(),
            airplane.get_type(),
            airplane.get_manufacturer(),
            airplane.get_seat_count(),
            airplane.get_state()
        ]
        valid_user_inputs = ["1"]
        option_tuple = ('Name', 'Type', 'Manufacturer', "Seats", 'State')          
        valid_for_submit_list = [False] #Can only change the name (one element) in this case (airplane)
        while user_input not in AirplanesUI.__NAVIGATION_BAR_OPTIONS:
            ComponentUI.print_frame_constructor_menu(option_tuple,\
            ComponentUI.get_main_options()[2], "Edit mode", user_input_list, True, 1000, [1,2,3,4])

            user_input = ComponentUI.get_user_input()
            user_input = ComponentUI.remove_brackets(user_input)
            if user_input in valid_user_inputs: 
                index = int(user_input) - 1
                ComponentUI.print_frame_constructor_menu(option_tuple,\
                    ComponentUI.get_main_options()[2], "Edit mode", user_input_list, False, 1000, [1,2,3,4])

                if(index == 0):
                    user_input = input("Insert name: ").strip()
                



                #Capitalize the first letters in the contacts name
                if index == 0:
                    if not user_input: #use existing name in case if user cancels or leaves it blank 
                        user_input = user_input_list[index]

                    airplane_name_list = []
                    for name in user_input.split():
                        airplane_name_list.append(name.capitalize())
                    user_input = " ".join(airplane_name_list)
                    valid_for_submit_list[0] = True

              
                
                user_input_list[index] = user_input
                user_input = ""
                   
            elif user_input.startswith('s'):
                if all(user_input_list):

                    edited_airplane = Airplane(
                        user_input_list[0],
                        user_input_list[1],
                        user_input_list[2],
                        user_input_list[3],
                        user_input_list[4]

                    )

                    LogicAPI.change_saved_airplane(airplane, edited_airplane)
                    
                    
                    user_input = "An airplane has been edited"
                    break
        return user_input
Example #12
0
    def __show_new_flight_route_constructor():

        valid_user_inputs = ComponentUI.make_valid_menu_options_tuple(
            len(FlightRouteUI.FLIGHT_ROUTE_OPTION_TUBLE))

        input_message_tuple = ("Insert Country: ", "Insert Destination: ", "Insert Airport id: ", "Insert Flight time(hh:mm): ",\
             "Insert Distance from Iceland in km: ", "Insert Contact name: ", "Insert Emergency phonenumber: ")

        user_input_list = [""] * len(FlightRouteUI.FLIGHT_ROUTE_OPTION_TUBLE)
        valid_for_submit_list = [False] * len(
            FlightRouteUI.FLIGHT_ROUTE_OPTION_TUBLE
        )  #list that contains bools if all true then ok to submit

        user_input = ""

        #flight_route_info_already_exists = False

        while user_input not in FlightRouteUI.__NAVIGATION_BAR_OPTIONS:

            ComponentUI.print_frame_constructor_menu(FlightRouteUI.FLIGHT_ROUTE_OPTION_TUBLE, \
                ComponentUI.get_main_options()[3], "New flight route", user_input_list, True)

            user_input = ComponentUI.get_user_input()

            if not user_input:
                continue

            user_input = ComponentUI.remove_brackets(user_input)

            if user_input in valid_user_inputs:
                index = int(user_input) - 1
                ComponentUI.print_frame_constructor_menu(FlightRouteUI.FLIGHT_ROUTE_OPTION_TUBLE,\
                     ComponentUI.get_main_options()[3], "New flight route", user_input_list, False, index)

                user_input = input(input_message_tuple[index]).strip()

                if not user_input:
                    continue

                #Capitalize the first letter of the Country and Destination
                if index == 0 or index == 1:
                    user_input = user_input[0].upper() + user_input[1:]
                    if user_input:
                        valid_for_submit_list[index] = True

                #Check if the airport id already exists
                elif index == 2:
                    if not LogicAPI.is_airport_id_available(user_input):
                        user_input = user_input + " " + TextEditor.color_text_background(
                            "Airport id already exists",
                            TextEditor.RED_BACKGROUND)
                        valid_for_submit_list[index] = False
                    else:
                        valid_for_submit_list[index] = True

                #Flight time test if format is right
                elif index == 3:
                    test_list = user_input.split(':')
                    error_msg_str = 'Time must be written in format of "hours:minutes"'

                    if ':' in user_input and len(test_list) == 2:
                        if all(test_list) and test_list[0].isdigit and len(test_list[0]) <= 2 and test_list[1].isdigit and len(test_list[1]) == 2\
                             and int(test_list[1])<60 and int(test_list[0])>=0 and int(test_list[1])>=0:
                            if len(test_list[0]) == 1:
                                user_input = "0" + user_input
                            valid_for_submit_list[index] = True
                        else:
                            user_input = user_input + " " + TextEditor.color_text_background(
                                error_msg_str, TextEditor.RED_BACKGROUND)
                            valid_for_submit_list[index] = False
                    else:
                        user_input = user_input + " " + TextEditor.color_text_background(
                            error_msg_str, TextEditor.RED_BACKGROUND)
                        valid_for_submit_list[index] = False

                #Distance from Iceland can not contain letters excluding 'km'
                elif index == 4:
                    if 'km' in user_input:
                        user_input = user_input.replace('km', '')
                        user_input = user_input.strip()
                    if not user_input.isdigit():
                        user_input = user_input + " " + TextEditor.color_text_background(
                            "Can not contain letters",
                            TextEditor.RED_BACKGROUND)
                        valid_for_submit_list[index] = False
                    else:
                        valid_for_submit_list[index] = True

                #Capitalize the first letters in the contacts name
                elif index == 5:
                    contact_name_list = []
                    for name in user_input.split():
                        contact_name_list.append(name.capitalize())
                    user_input = " ".join(contact_name_list)
                    valid_for_submit_list[index] = True

                #Remove any spaces or dashes from the phonenumber
                elif index == 6:
                    if '-' in user_input:
                        user_input = user_input.replace('-', '')
                    if '' in user_input:
                        user_input = user_input.replace(' ', '')

                    #Put a message on the screen indicating the phonenumber is invalid
                    if not user_input.isdigit():
                        user_input = user_input + " " + TextEditor.color_text_background(
                            "Can not contain letters",
                            TextEditor.RED_BACKGROUND)
                        valid_for_submit_list[index] = False
                    else:
                        valid_for_submit_list[index] = True

                user_input_list[index] = user_input
                user_input = ""

            elif user_input.startswith('s'):
                if all(valid_for_submit_list):

                    new_flight_route = FlightRoute(
                        user_input_list[0], user_input_list[1],
                        user_input_list[2], user_input_list[3],
                        str(user_input_list[4]) + "km", user_input_list[5],
                        user_input_list[6])
                    LogicAPI.save_new_flight_route(new_flight_route)
                    user_input = "A new flight route has been registered"
                    break

        return user_input
Example #13
0
    def __show_flight_route(flrt):

        user_input = ''
        user_input_list = [
            flrt.get_country(),
            flrt.get_destination(),
            flrt.get_airport_id(),
            flrt.get_flight_time(),
            flrt.get_distance_from_iceland(),
            flrt.get_contact_name(),
            flrt.get_emergency_phone()
        ]

        valid_user_inputs = ["6", "7", "(6)", "(7)"]
        valid_for_submit_list = [
            True, True, True
        ]  #only two input avalable // exeption from rule // last False is for if do nothing
        #ComponentUI.make_valid_menu_options_tuple(len(FlightRouteUI.FLIGHT_ROUTE_OPTION_TUBLE))

        # flight_route_info_already_exists = False
        while user_input not in FlightRouteUI.__NAVIGATION_BAR_OPTIONS:
            ComponentUI.print_frame_constructor_menu(FlightRouteUI.FLIGHT_ROUTE_OPTION_TUBLE,\
            ComponentUI.get_main_options()[3], "Edit mode", user_input_list, True, 1000, [0,1,2,3,4])

            user_input = ComponentUI.get_user_input()
            user_input = ComponentUI.remove_brackets(user_input)
            if user_input in valid_user_inputs:
                index = int(user_input) - 1
                valid_for_submit_list[2] = [True
                                            ]  # done somthing can submit if ok
                ComponentUI.print_frame_constructor_menu(FlightRouteUI.FLIGHT_ROUTE_OPTION_TUBLE,\
                    ComponentUI.get_main_options()[3], "Edit mode", user_input_list, False, index, [0,1,2,3,4])

                if (index == 5):
                    user_input = input("Insert new contact name: ").strip()
                elif (index == 6):
                    user_input = input(
                        "Insert new Emergency phonenumber: ").strip()

                #Capitalize the first letters in the contacts name
                if index == 5:
                    if not user_input:  #use existing name in case if user cancels or leaves it blank
                        user_input = user_input_list[index]

                    contact_name_list = []
                    for name in user_input.split():
                        contact_name_list.append(name.capitalize())
                    user_input = " ".join(contact_name_list)
                    valid_for_submit_list[0] = True

                #Remove any spaces or dashes from the phonenumber
                elif index == 6:
                    if not user_input:  #use existing phonenumber in case if user cancels or leaves it blank
                        user_input = user_input_list[index]

                    if '-' in user_input:
                        user_input = user_input.replace('-', '')
                    if '' in user_input:
                        user_input = user_input.replace(' ', '')

                    #Put a message on the screen indicating the phonenumber is invalid
                    if not user_input.isdigit():
                        user_input = user_input + " " + TextEditor.color_text_background(
                            "Can not contain letters",
                            TextEditor.RED_BACKGROUND)
                        valid_for_submit_list[1] = False
                    else:
                        valid_for_submit_list[1] = True

                user_input_list[index] = user_input
                user_input = ""

            elif user_input.startswith('s'):
                if all(valid_for_submit_list):

                    edited_flight_route = FlightRoute(
                        user_input_list[0], user_input_list[1],
                        user_input_list[2], user_input_list[3],
                        user_input_list[4], user_input_list[5],
                        user_input_list[6])

                    LogicAPI.change_saved_flight_route(flrt,
                                                       edited_flight_route)
                    #þarfnast skoðunnar(Kannski er þetta ok þar sem breytingar sjást, næ ekki að láta þetta virka heldur)
                    user_input = "A new flight route contact information has been edited"
                    break

        return user_input
Example #14
0
    def __show_employee(employee):
        LogicAPI.update_states()  #UPDATES ALL STATES BEFOR DISPLAYING

        user_input = ''
        user_input_list = []
        valid_user_inputs_bool_list = [True] * 7

        is_pilot = isinstance(employee, Pilot)

        user_input_list.append(employee.get_name())
        user_input_list.append(employee.get_ssn())
        user_input_list.append(employee.get_phonenumber())
        user_input_list.append(employee.get_home_address())
        user_input_list.append(employee.get_email())
        user_input_list.append(employee.get_state())

        valid_user_inputs = ["4", "5", "6"]
        invalid_user_input_index_list = [0, 1, 2, 6]

        if is_pilot:
            user_input_list.append(employee.get_license())
            valid_user_inputs_bool_list.append(True)
            valid_user_inputs.append("8")
            user_input_list.insert(0, "Pilot")
            option_tuple = ("Job title", "Name", "SSN", "Phonenumber",
                            "Home address", "Email", "State", "License")
        else:
            user_input_list.insert(0, "Flight Attendant")
            invalid_user_input_index_list.append(7)
            option_tuple = ("Job title", "Name", "SSN", "Phonenumber",
                            "Home address", "Email", "State")

        # employee_info_already_exists = False
        while user_input not in EmployeeUI.__NAVIGATION_BAR_OPTIONS:
            ComponentUI.print_frame_constructor_menu(option_tuple,\
            ComponentUI.get_main_options()[1], "Edit mode", user_input_list, True, 1000, invalid_user_input_index_list, print_check_voyages=True)

            user_input = ComponentUI.get_user_input()
            user_input = ComponentUI.remove_brackets(user_input)
            if user_input in valid_user_inputs:
                index = int(user_input) - 1
                ComponentUI.print_frame_constructor_menu(option_tuple,\
            ComponentUI.get_main_options()[1], "Edit mode", user_input_list, False, index, invalid_user_input_index_list)

                if index == 3:
                    user_input = input("Insert new phone number: ").strip()
                elif index == 4:
                    user_input = input("Insert new home address: ").strip()
                elif index == 5:
                    user_input = input("Insert new e-mail: ").strip()
                elif index == 7 and is_pilot:
                    user_input = EmployeeUI.__airplane_type_picker(
                        "Edit mode - choose license"
                    )  # input("Insert new license: ").strip() #Vantar sub menu

                if not user_input and (index == 2 or index == 3 or index == 4):
                    user_input = user_input_list[index]
                else:

                    user_input = EmployeeUI.__constructor_error_check(user_input, valid_user_inputs_bool_list,\
                            index, user_input_list)

            elif user_input.startswith('s'):
                if all(user_input_list) and all(valid_user_inputs_bool_list):

                    edited_employee = None

                    if is_pilot:
                        edited_employee = Pilot(
                            user_input_list[1],  #Name
                            user_input_list[2],  #SSN
                            user_input_list[3],  #Phonenumber
                            user_input_list[4],  #Home address
                            user_input_list[5],  #Email
                            user_input_list[6],  #State
                            user_input_list[7]  #License
                        )
                        LogicAPI.change_saved_pilot(employee, edited_employee)
                    else:
                        edited_employee = FlightAttendant(
                            user_input_list[1],  #Name
                            user_input_list[2],  #SSN
                            user_input_list[3],  #Phonenumber
                            user_input_list[4],  #Home address
                            user_input_list[5],  #Email
                            user_input_list[6]  #State
                        )
                        LogicAPI.change_saved_flight_attendant(
                            employee, edited_employee)

                    #þarfnast skoðunnar(Kannski er þetta ok þar sem breytingar sjást, næ ekki að láta þetta virka heldur)
                    user_input = "An employee has been edited"
                    break

            elif user_input.startswith('c'):
                user_input = EmployeeUI.__show_employee_voyages(employee)

        return user_input
Example #15
0
    def __show_employee_by_name_finder():
        LogicAPI.update_states()  #UPDATES ALL STATES BEFOR DISPLAYING

        user_input = ""

        info_header_tuple = ("Job title", "Name", "SSN", "Phone number",
                             "Home address", "E-mail", "State")

        while user_input not in EmployeeUI.__NAVIGATION_BAR_OPTIONS:
            ComponentUI.print_header(EmployeeUI.__FRAME_IN_USE_STR)
            print(
                TextEditor.format_text("Find employee by name or ssn",
                                       TextEditor.UNDERLINE_TEXT))

            ComponentUI.fill_window_and_print_action_line(1)

            user_input = input("Insert name or ssn: ").strip()

            employees = []

            if not user_input:
                continue

            #If he enters  a digit
            if user_input.isdigit():
                if '-' in user_input:
                    user_input = user_input.replace('-', '')
                if ' ' in user_input:
                    user_input = user_input.replace(' ', '')

                employees = LogicAPI.get_employee_by_ssn(user_input)

                ComponentUI.print_header(EmployeeUI.__FRAME_IN_USE_STR)
                print(
                    TextEditor.format_text("Find employee by name or ssn",
                                           TextEditor.UNDERLINE_TEXT))

                if not employees:
                    ComponentUI.centered_text_message(
                        "No employee found with the ssn: {}".format(
                            user_input), "", 3)

                    return ComponentUI.get_user_input()

                else:
                    employee_info_tuple =  (["Pilot" if isinstance(employee, Pilot) else "Flight attendant" for employee in employees], [employee.get_name() for employee in employees],[employee.get_ssn() for employee in employees],\
                    [employee.get_phonenumber() for employee in employees],[employee.get_home_address() for employee in employees],[employee.get_email() for employee in employees],\
                    [employee.get_state() for employee in employees])

                    table_height = len(employees)
                    ComponentUI.print_frame_table_menu(
                        info_header_tuple, employee_info_tuple, table_height,
                        EmployeeUI.__FRAME_IN_USE_STR, "Employee")
                    user_input = ComponentUI.get_user_input()
                    user_input = ComponentUI.remove_brackets(user_input)
                    if not user_input.isdigit() or int(
                            user_input) > table_height:
                        continue
                    table_index = int(user_input) - 1
                    employee = employees[table_index]

                    user_input = EmployeeUI.__show_employee(employee)

                return user_input
            else:
                name_list = []
                for name in user_input.split():
                    name_list.append(name.capitalize())

                user_input = " ".join(name_list)

                employees = LogicAPI.get_employee_by_name(user_input)

                ComponentUI.print_header(EmployeeUI.__FRAME_IN_USE_STR)
                print(
                    TextEditor.format_text("Find employee by name or ssn",
                                           TextEditor.UNDERLINE_TEXT))

                if not employees:

                    ComponentUI.centered_text_message(
                        "Could not find an employee named {}".format(
                            user_input), "", 3)

                    return ComponentUI.get_user_input()

                else:
                    employee_info_tuple =  (["Pilot" if isinstance(employee, Pilot) else "Flight attendant" for employee in employees], [employee.get_name() for employee in employees],[employee.get_ssn() for employee in employees],\
                    [employee.get_phonenumber() for employee in employees],[employee.get_home_address() for employee in employees],[employee.get_email() for employee in employees],\
                    [employee.get_state() for employee in employees])
                    table_height = len(employees)
                    ComponentUI.print_frame_table_menu(
                        info_header_tuple, employee_info_tuple, table_height,
                        EmployeeUI.__FRAME_IN_USE_STR, "Employee")
                    user_input = ComponentUI.get_user_input()
                    user_input = ComponentUI.remove_brackets(user_input)
                    if not user_input.isdigit() or int(
                            user_input) > table_height:
                        continue
                    table_index = int(user_input) - 1
                    employee = employees[table_index]

                    user_input = EmployeeUI.__show_employee(employee)

                return user_input
Example #16
0
    def __show_new_employee_constructor():
        input_message_tuple = ("Insert job title(" + TextEditor.format_text('f', TextEditor.BOLD_TEXT) + " for flight attendant, "\
            + TextEditor.format_text('p', TextEditor.BOLD_TEXT)+ " for pilot): ", "Insert Name: ", "Insert Social security number: ",\
            "Insert Phone number: ", "Insert Home address: ", "Insert E-mail: ", "Insert License: ")
        user_input = ""
        option_tuple = ("Job title", "Name", "Social security number",
                        "Phone number", "Home address", "E-mail", "License")
        user_input_list = [""] * len(option_tuple)
        valid_user_inputs = ComponentUI.make_valid_menu_options_tuple(
            len(option_tuple))
        valid_user_inputs_bool_list = [True] * len(option_tuple)
        while user_input not in EmployeeUI.__NAVIGATION_BAR_OPTIONS:

            greyed_out_option_index_list = [
                6
            ] if not user_input_list[0].lower().startswith('p') else []

            ComponentUI.print_frame_constructor_menu(option_tuple, EmployeeUI.__FRAME_IN_USE_STR, "New employeee",\
            user_input_list, True, greyed_out_option_index_list=greyed_out_option_index_list)
            user_input = ComponentUI.get_user_input()

            if not user_input:
                continue

            user_input = ComponentUI.remove_brackets(user_input)

            if user_input in valid_user_inputs:

                index = int(user_input) - 1

                #Don't allow the user to enter a license if the employee ain't a pilot
                if index == 6:
                    if not user_input_list[0].lower().startswith('p'):
                        continue


                ComponentUI.print_frame_constructor_menu(option_tuple, EmployeeUI.__FRAME_IN_USE_STR, "New employeee",\
                user_input_list, False, index)

                if index == 6:
                    #display table of airplane types and return the type-name the of chosen one , head above the the table
                    user_input = EmployeeUI.__airplane_type_picker(
                        "New employeee")
                else:
                    user_input = input(input_message_tuple[index]).strip()

                if not user_input:
                    continue

                user_input = EmployeeUI.__constructor_error_check(user_input,\
                     valid_user_inputs_bool_list, index, user_input_list)

            elif user_input.startswith('s'):
                job_title_str = user_input_list[0].lower()

                if all(user_input_list) and job_title_str.startswith(
                        'p') and all(valid_user_inputs_bool_list):

                    pilot = Pilot(user_input_list[1], user_input_list[2],
                                  user_input_list[3], user_input_list[4],
                                  user_input_list[5],
                                  State.get_employee_states()[0],
                                  user_input_list[6])
                    LogicAPI.save_new_pilot(pilot)

                    user_input = "A new pilot has been registered"

                    break

                elif all(user_input_list[:-1]) and job_title_str.startswith(
                        'f') and all(valid_user_inputs_bool_list[:-1]):

                    flight_attendant = FlightAttendant(
                        user_input_list[1], user_input_list[2],
                        user_input_list[3], user_input_list[4],
                        user_input_list[5], "Not scheduled for flight today")
                    LogicAPI.save_new_flight_attendant(flight_attendant)

                    user_input = "A new flight attendant has been registered"

                    break

        return user_input