def run(self, item):
        edited_info = LL_API.get_edit_info(item)
        # Edit index must start on allowed index
        edit_index = 0
        while edited_info[edit_index][INDEX_OF_EDIT_PERMISSION_BOOL] == False:
            edit_index += 1
            if edit_index > len(edited_info) - 1:
                edit_index = 0

        while True:
            self.display(edited_info, edit_index, BUTTONS)
            user_input = self.get_input()

            if user_input.lower() == "b":
                return 0
            elif user_input.lower() == "c":
                new_info = []
                for info in edited_info:
                    new_info += [info[INDEX_OF_INFO]]
                item.set_info(new_info)
                self.change_item_func(item.get_id(), new_info)
                return 0

            elif user_input.lower() == "u":
                edit_index -= 1
                if edit_index < 0:
                    edit_index = len(edited_info) - 1
                while edited_info[edit_index][
                        INDEX_OF_EDIT_PERMISSION_BOOL] == False:
                    edit_index -= 1
                    if edit_index < 0:
                        edit_index = len(edited_info) - 1

            elif user_input.lower() == "d":
                edit_index += 1
                if edit_index > len(edited_info) - 1:
                    edit_index = 0
                while edited_info[edit_index][
                        INDEX_OF_EDIT_PERMISSION_BOOL] == False:
                    edit_index += 1
                    if edit_index > len(edited_info) - 1:
                        edit_index = 0

            else:
                edited_info[edit_index][INDEX_OF_INFO] = user_input
    def run(self, item):
        edit_info = LL_API.get_edit_info(item)
        # Edit index must start on allowed index
        edit_index = 0
        while edit_info[edit_index][INDEX_OF_EDIT_PERMISSION_BOOL] == False:
            edit_index += 1
            if edit_index > len(edit_info) - 1:
                edit_index = 0

        while True:
            self.display(edit_info, edit_index, BUTTONS)
            user_input = self.get_input()

            # User goes back
            if user_input.lower() == "b":
                return 0
            # User moves arrow up
            elif user_input.lower() == "u":
                edit_index -= 1
                if edit_index < 0:
                    edit_index = len(edit_info) - 1
                while edit_info[edit_index][INDEX_OF_EDIT_PERMISSION_BOOL] == False:
                    edit_index -= 1
                    if edit_index < 0:
                        edit_index = len(edit_info) - 1
            # User moves arrow down
            elif user_input.lower() == "d":
                edit_index += 1
                if edit_index > len(edit_info) - 1:
                    edit_index = 0
                while edit_info[edit_index][INDEX_OF_EDIT_PERMISSION_BOOL] == False:
                    edit_index += 1
                    if edit_index > len(edit_info) - 1:
                        edit_index = 0
            # User removes info
            elif user_input.lower() == "r":
                if edit_index == JOB_INDEX:
                    edit_info[JOB_INDEX][INDEX_OF_INFO] = "+"
                    edit_info[RANK_INDEX][INDEX_OF_INFO] = "+"
                elif edit_index == RANK_INDEX:
                    edit_info[RANK_INDEX][INDEX_OF_INFO] = "+"
            # User goes to a select window
            elif user_input == "":
                if edit_index == JOB_INDEX:
                    jobs = Employee.get_job_types()
                    job = self.select_job_window.run(jobs)
                    edit_info[RANK_INDEX][INDEX_OF_INFO] = "+"
                    if job == "pilot":
                        licences = Aircraft.get_model_types()
                        licence = self.select_licence_window.run(licences)
                        job = job + ":" + licence
                        edit_info[edit_index][INDEX_OF_INFO] = job
                    elif job == "cabin_crew":
                        edit_info[edit_index][INDEX_OF_INFO] = job
                elif edit_index == RANK_INDEX:
                    if edit_info[JOB_INDEX][INDEX_OF_INFO] != "+":
                        ranks = Employee.get_rank_types(edit_info[JOB_INDEX][INDEX_OF_INFO])
                        rank = self.select_rank_window.run(ranks)
                        edit_info[edit_index][INDEX_OF_INFO] = rank
                    else:
                        Error_Window.run("you need to select a job before you select rank")
                    

            # User confirms changes
            elif user_input == "c":
                new_info = []
                for info in edit_info:
                    new_info += [info[INDEX_OF_INFO]]
                item.set_info(new_info)
                self.change_item_func(item.get_id(), new_info)
                return 0
            # User inputs info
            else:
                if edit_index != JOB_INDEX and edit_index != RANK_INDEX:
                    if check_employee_input(user_input, edit_index):

                        edit_info[edit_index][INDEX_OF_INFO] = user_input
                    else:
                        Error_Window.run("Invalid information")
Example #3
0
    def run(self, voyage):
        edit_index = 0
        #[aircraft, captain, [copilots], flight_service_manager, [flight_attendant]]
        edit_info = LL_API.get_edit_info(voyage)
        aircraft = edit_info[AIRCRAFT_INDEX]
        captain = edit_info[CAPTAIN_INDEX]
        copilot_list = edit_info[COPILOT_LIST_INDEX] + [None]
        flight_service_manager = edit_info[FLIGHT_SERVICE_MANAGER_INDEX]
        flight_attendant_list = edit_info[FLIGHT_ATTENDANT_LIST_INDEX] + [None]

        original_crew_list_with_none = [captain] + copilot_list + [flight_service_manager] + flight_attendant_list
        original_crew_list = []
        for employee in original_crew_list_with_none:
            if employee is not None:
                original_crew_list += [employee]

        original_aircraft_list = []
        if aircraft is not None:
            original_aircraft_list = [aircraft]

        available_employees = LL_API.get_available_employees(voyage.get_departure_time()) + original_crew_list
        available_aircraft = LL_API.get_available_aircraft(voyage.get_departure_time()) + original_aircraft_list
        for employee in available_employees:
            if employee.get_job() == "pilot":
                print(employee.get_licence())
            else:
                print()

        while True:
            edit_info = [aircraft, captain, copilot_list, flight_service_manager, flight_attendant_list]
            self.display(edit_info, edit_index, BUTTONS)
            user_input = self.get_input()
            item_selected, item_type_str = Voyage_Edit_Window.__get_edit_info_item_and_type(edit_info, edit_index)

            size_of_list = 3 + len(edit_info[COPILOT_LIST_INDEX]) + len(edit_info[FLIGHT_ATTENDANT_LIST_INDEX])
            # back is pressed
            if user_input.lower() == "b":
                return 0

            # if down is pressed
            elif user_input.lower() == "d":
                # amount of items - 1
                if edit_index == size_of_list - 1:
                    # arrow wrapping
                    edit_index = 0
                else:
                    edit_index += 1

            # if upp is pressed
            elif user_input.lower() == "u":
                if edit_index == 0:
                    edit_index = size_of_list - 1
                else:
                    edit_index -= 1

            elif user_input.lower() == "r":
                if item_type_str == "aircraft":
                    aircraft = None
                    captain = None
                    copilot_list = [None]
                    flight_service_manager = None
                    flight_attendant_list = [None]

                elif item_type_str == "captain":
                    captain = None

                elif item_type_str == "copilot":
                    edit_info.remove(item_selected)

                elif item_type_str == "flight_service_manager":
                    flight_service_manager = None

                elif item_type_str == "flight_attendant":
                    edit_info.remove(item_selected)

            elif user_input.lower() == "":
                if item_selected is None:
                    if item_type_str == "aircraft":
                        new_aircraft = self.select_aircraft_window.run(available_aircraft)
                        if new_aircraft is not None:
                            aircraft = new_aircraft

                    elif aircraft is not None:
                        if item_type_str == "captain":
                            available_captains = Voyage_Edit_Window.__filter_employees_by_rank(available_employees, "captain")
                            available_captains = Voyage_Edit_Window.__filter_pilots_by_licence(available_captains, aircraft)
                            new_captain = self.select_captain_window.run(available_captains)
                            if new_captain is not None:
                                captain = new_captain

                        elif item_type_str == "copilot":
                            available_copilots = Voyage_Edit_Window.__filter_employees_by_rank(available_employees, "copilot")
                            available_copilots = Voyage_Edit_Window.__filter_pilots_by_licence(available_copilots, aircraft)
                            available_copilots = list(set(available_copilots) - set(copilot_list))
                            new_copilot = self.select_copilot_window.run(available_copilots)
                            if new_copilot is not None:
                                copilot_list[-1] = new_copilot
                                copilot_list += [None]

                        elif item_type_str == "flight_service_manager":
                            available_flight_service_managers = Voyage_Edit_Window.__filter_employees_by_rank(available_employees, "flight_service_manager")
                            new_flight_service_manager = self.select_flight_service_manager_window.run(available_flight_service_managers)
                            if new_flight_service_manager is not None:
                                flight_service_manager = new_flight_service_manager

                        elif item_type_str == "flight_attendant":
                            available_flight_attendants = Voyage_Edit_Window.__filter_employees_by_rank(available_employees, "flight_attendant")
                            available_flight_attendants = list(set(available_flight_attendants) - set(flight_attendant_list))
                            new_flight_attendant = self.select_flight_attendant_window.run(available_flight_attendants)
                            if new_flight_attendant is not None:
                                flight_attendant_list[-1] = new_flight_attendant
                                flight_attendant_list += [None]
                else:
                    Error_Window.run("select + to add new item to voyage")

            # if user confirms voyage
            elif user_input.lower() == "c":
                employees =   [edit_info[CAPTAIN_INDEX]]\
                            + edit_info[COPILOT_LIST_INDEX]\
                            + [edit_info[FLIGHT_SERVICE_MANAGER_INDEX]]\
                            + edit_info[FLIGHT_ATTENDANT_LIST_INDEX]
                employee_ids = []

                voyage.manned_bool = False
                if edit_info[CAPTAIN_INDEX] is not None:
                    if len(edit_info[COPILOT_LIST_INDEX]) > 1:
                        if edit_info[FLIGHT_SERVICE_MANAGER_INDEX]:
                            voyage.manned_bool = True

                for employee in employees:
                    if employee is not None:
                        employee_ids += [employee.get_id()]
                voyage_info = [
                    edit_info[AIRCRAFT_INDEX].get_id(),
                    voyage.get_destination_id(),
                    voyage.get_departure_time(),
                    voyage.flight1_number,
                    voyage.flight2_number,
                    employee_ids,
                    voyage.manned_bool,
                    voyage.id_int
                ]
                LL_API.change_voyage(voyage.get_id(), voyage_info)
                voyage.set_info(voyage_info)
                return 0