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
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
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_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
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()
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
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_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_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