<commit_before>"use strict";

define(['knockout', 'debug', 'flight', 'get', 'log', 'waypoints', 'nav/LNAV', 'nav/progress'], function (ko, debug, flight, get, log, waypoints, lnav, progress) {

    /**
     * ViewModel function for knockout bindings
     */
    function ViewModel () {
        var self = this;

        /*************************
         * General Modal Actions *
         *************************/
        var _opened = ko.observable(false);
        self.opened = ko.pureComputed({
            read: function () {
                return _opened();
            },
            write: function (boolean, viewmodel) { // jshint unused:false
                _opened(boolean);
            }
        });

        self.modalWarning = ko.observable();
        log.warn = ko.pureComputed({ // Prints modal warning, disappears after 5 seconds
    		read: function () {
    			return self.modalWarning();
    		},
    		write: function (warningText) {
    			self.modalWarning(warningText);
    			setTimeout(function () { self.modalWarning(undefined); }, 5000);
    		}
    	});

        /***********
         * RTE Tab *
         ***********/
        self.departureAirport = flight.departure.airport;
        self.arrivalAirport = flight.arrival.airport;
        self.flightNumber = flight.number;
        self.route = waypoints.route;
        self.nextWaypoint = waypoints.nextWaypoint;
        self.saveWaypoints = waypoints.saveData;
        self.retrieveWaypoints = waypoints.loadFromSave;
        self.addWaypoint = waypoints.addWaypoint;
        self.activateWaypoint = waypoints.activateWaypoint;
        self.shiftWaypoint = waypoints.shiftWaypoint;
        self.removeWaypoint = waypoints.removeWaypoint;

        /***************
         * DEP/ARR Tab *
         ***************/
        self.fieldElev = flight.fieldElev;
        self.todDist = flight.todDist;
        self.todCalc = flight.todCalc;

        // List of departure runways based on departure airport
        self.departureRwyList = ko.pureComputed(function () {
            return get.runway(self.departureAirport());
        });

        // Selected departure runway and name
        self.departureRunway = flight.departure.runway;
        self.departureRwyName = ko.pureComputed(function () {
            return self.departureRunway().runway;
        });

        // List of SIDs based on departure airport and runway
        self.SIDList = ko.pureComputed(function () {
            return get.SID(self.departureAirport(), self.departureRwyName());
        });

        // Selected SID name
        self.SID = flight.departure.SID;
        self.SIDName = ko.pureComputed(function () {
            return self.SID().name;
        });

        // List of arrival runways based on arrival airport
        self.arrivalRwyList = ko.pureComputed(function () {
            return get.runway(self.arrivalAirport());
        });

        // Selected arrival runway and name
        self.arrivalRunway = flight.arrival.runway;
        self.arrivalRunwayName = ko.pureComputed(function () {
            return self.arrivalRunway().runway;
        });

        // List of STARs based on arrival airport and runway
        // FIXME: STARs do not necessarily need a runway at first
        self.STARs = ko.pureComputed(function () {
            return get.STAR(self.arrivalAirport(), self.arrivalRunwayName());
        });

        // Selected STAR name
        self.STAR = flight.arrival.STAR;
        self.STARName = ko.pureComputed(function () {
            return self.STAR().name;
        });

        /************
         * VNAV Tab *
         ************/
        self.vnavEnabled = flight.vnavEnabled;
        self.cruiseAlt = flight.cruiseAlt;
        self.spdControl = flight.spdControl;
        self.phase = flight.phase;
        self.phaseLocked = flight.phaseLocked;

        var phaseToText = ['climb', 'cruise', 'descent'];
        self.currentPhaseText = ko.pureComputed(function () {
            return phaseToText[flight.phase()];
        });

        self.nextPhase = function () {
            var phase = flight.phase();

            flight.phase(phase === phaseToText.length - 1 ? 0 : phase + 1);
        };

        /************
         * PROG Tab *<commit_msg>Fixed potential bugs where runway, SID, or STAR is undefined<commit_after>"use strict";

define(['knockout', 'flight', 'get', 'log', 'waypoints', 'nav/progress'], function (ko, flight, get, log, waypoints, progress) {

    /**
     * ViewModel function for knockout bindings
     */
    function ViewModel () {
        var self = this;

        /*************************
         * General Modal Actions *
         *************************/
        var _opened = ko.observable(false);
        self.opened = ko.pureComputed({
            read: function () {
                return _opened();
            },
            write: function (boolean, viewmodel) { // jshint unused:false
                _opened(boolean);
            }
        });

        self.modalWarning = ko.observable();
        log.warn = ko.pureComputed({ // Prints modal warning, disappears after 5 seconds
    		read: function () {
    			return self.modalWarning();
    		},
    		write: function (warningText) {
    			self.modalWarning(warningText);
    			setTimeout(function () { self.modalWarning(undefined); }, 5000);
    		}
    	});

        /***********
         * RTE Tab *
         ***********/
        self.departureAirport = flight.departure.airport;
        self.arrivalAirport = flight.arrival.airport;
        self.flightNumber = flight.number;
        self.route = waypoints.route;
        self.nextWaypoint = waypoints.nextWaypoint;
        self.saveWaypoints = waypoints.saveData;
        self.retrieveWaypoints = waypoints.loadFromSave;
        self.addWaypoint = waypoints.addWaypoint;
        self.activateWaypoint = waypoints.activateWaypoint;
        self.shiftWaypoint = waypoints.shiftWaypoint;
        self.removeWaypoint = waypoints.removeWaypoint;

        /***************
         * DEP/ARR Tab *
         ***************/
        self.fieldElev = flight.fieldElev;
        self.todDist = flight.todDist;
        self.todCalc = flight.todCalc;

        // List of departure runways based on departure airport
        self.departureRwyList = ko.pureComputed(function () {
            return get.runway(self.departureAirport());
        });

        // Selected departure runway and name
        self.departureRunway = flight.departure.runway;
        self.departureRwyName = ko.pureComputed(function () {
            if (self.departureRunway()) return self.departureRunway().runway;
            else return undefined;
        });

        // List of SIDs based on departure airport and runway
        self.SIDList = ko.pureComputed(function () {
            return get.SID(self.departureAirport(), self.departureRwyName());
        });

        // Selected SID name
        self.SID = flight.departure.SID;
        self.SIDName = ko.pureComputed(function () {
            if (self.SID()) return self.SID().name;
            else return undefined;
        });

        // List of arrival runways based on arrival airport
        self.arrivalRwyList = ko.pureComputed(function () {
            return get.runway(self.arrivalAirport());
        });

        // Selected arrival runway and name
        self.arrivalRunway = flight.arrival.runway;
        self.arrivalRunwayName = ko.pureComputed(function () {
            if (self.arrivalRunway()) return self.arrivalRunway().runway;
            else return undefined;
        });

        // List of STARs based on arrival airport and runway
        // FIXME: STARs do not necessarily need a runway at first
        self.STARs = ko.pureComputed(function () {
            return get.STAR(self.arrivalAirport(), self.arrivalRunwayName());
        });

        // Selected STAR name
        self.STAR = flight.arrival.STAR;
        self.STARName = ko.pureComputed(function () {
            if (self.STAR()) return self.STAR().name;
            else return undefined;
        });

        /************
         * VNAV Tab *
         ************/
        self.vnavEnabled = flight.vnavEnabled;
        self.cruiseAlt = flight.cruiseAlt;
        self.spdControl = flight.spdControl;
        self.phase = flight.phase;
        self.phaseLocked = flight.phaseLocked;

        var phaseToText = ['climb', 'cruise', 'descent'];
        self.currentPhaseText = ko.pureComputed(function () {
            return phaseToText[flight.phase()];
        });

        self.nextPhase = function () {
            var phase = flight.phase();

            flight.phase(phase === phaseToText.length - 1 ? 0 : phase + 1);
        };

        /************
         * PROG Tab *
{'fraction_non_alphanumeric': 0.13906000456308465, 'fraction_numerical': 0.0018252338580880675, 'mean_word_length': 2.057900244157656, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4588985', 'n_tokens_mistral': 2612, 'n_tokens_neox': 2415, 'n_words': 501}