Skip to content

Commit

Permalink
Merge pull request #158 from n8rzz/feature/ATC-151
Browse files Browse the repository at this point in the history
feature/ATC-151
  • Loading branch information
n8rzz authored Nov 27, 2016
2 parents ac2a214 + d800d15 commit bbca36f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 34 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

### Bugfixes
- Moves `_comment` blocks in airport json file to be within object the are describing [#145](https://github.com/n8rzz/atc/issues/145)

- Streamlines flight number generation and adds new method to add new callsigns to the existing list [#151](https://github.com/n8rzz/atc/issues/151)



Expand Down
45 changes: 20 additions & 25 deletions src/assets/scripts/aircraft/AircraftController.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,45 +33,39 @@ export default class AircraftController {

/**
* @for AircraftController
* @method aircraft_generate_callsign
* @param airlineName
* @method aircraft_auto_toggle
*/
aircraft_generate_callsign(airlineName) {
// TODO: this should live in the AirlineModel
const airline = window.airlineController.airline_get(airlineName);

if (!airline) {
console.warn(`Airline not found: ${airlineName}`);

return `airline-${airlineName}-not-found`;
}

return airline.generateFlightNumber();
aircraft_auto_toggle() {
prop.aircraft.auto.enabled = !this.aircraft.auto.enabled;
}

/**
* @for AircraftController
* @method aircraft_auto_toggle
* @method isCallsignInList
* @param callsign {string}
* return {boolean}
*/
aircraft_auto_toggle() {
prop.aircraft.auto.enabled = !this.aircraft.auto.enabled;
isCallsignInList(callsign) {
return this.aircraft.callsigns.indexOf(callsign) !== -1;
}

/**
* Add a new callsign to `aircraft.callsigns`
*
* @for AircraftController
* @method aircraft_callsign_new
* @param airline {string}
* @method addCallsignToList
* @param callsign {string}
*/
aircraft_callsign_new(airline) {
// TODO: the logic needs work here. if `callsign` is always initialized as null, one would imagine that
// this function would always result in the creation of a callsign?
let callsign = this.aircraft_generate_callsign(airline);
addCallsignToList(callsign) {
if (this.isCallsignInList(callsign)) {
// if you've made it here something has gone very wrong. generation of a callsign/flightNumber should
// also include verification that the callsign/flightNumber is unique
console.warn(`${callsign} already exists within the callsigns list!`);

if (this.aircraft.callsigns.indexOf(callsign) === -1) {
this.aircraft.callsigns.push(callsign);
return;
}

return callsign;
this.aircraft.callsigns.push(callsign);
}

/**
Expand Down Expand Up @@ -359,6 +353,7 @@ export default class AircraftController {
return this.aircraft.models[icao];
}

// TODO: what is an `eid` and why would it beed to be updated?
/**
* Adjust all aircraft's eid values
*
Expand Down
18 changes: 10 additions & 8 deletions src/assets/scripts/airline/AirlineModel.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import _get from 'lodash/get';
import _has from 'lodash/has';
import _forEach from 'lodash/forEach';
import _map from 'lodash/map';
import { choose, choose_weight } from '../utilities/generalUtilities';

/**
Expand Down Expand Up @@ -82,7 +81,7 @@ export default class AirlineModel {
_forEach(this.fleets, (fleet) => {
_forEach(fleet, (aircraftInFleet) => {
const NAME_INDEX = 0;
aircraftInFleet[NAME_INDEX] = aircraftInFleet[NAME_INDEX].toLowerCase()
aircraftInFleet[NAME_INDEX] = aircraftInFleet[NAME_INDEX].toLowerCase();
});
});
}
Expand Down Expand Up @@ -148,7 +147,7 @@ export default class AirlineModel {
*/
chooseAircraft(fleet) {
if (!fleet) {
fleet = 'default'
fleet = 'default';
}

// TODO: why is this a try/catch?
Expand Down Expand Up @@ -227,6 +226,11 @@ export default class AirlineModel {
}
}

// if this flightNumber already exists, repeat the process of generating a new flightNumber
if (window.aircraftController.isCallsignInList(flightNumber)) {
return this.generateFlightNumber();
}

return flightNumber;
}

Expand Down Expand Up @@ -273,9 +277,9 @@ export default class AirlineModel {
*/
_generateAircraft(options) {
if (!options.callsign) {
// TODO: Why is the `AircraftController` repsonsible for generating a callsign, but this is responsible for
// generating the flight number? callsign generation logi should live in this class.
options.callsign = window.aircraftController.aircraft_callsign_new(options.airline);
options.callsign = this.generateFlightNumber();

window.aircraftController.addCallsignToList(options.callsign);
}

if (!options.icao) {
Expand All @@ -285,7 +289,5 @@ export default class AirlineModel {
const model = window.aircraftController.aircraft_model_get(options.icao.toLowerCase());

return model.generateAircraft(options);
// FIXME: this block is unreachable, is it needed?
// var icao = options.icao.toLowerCase();
}
}

0 comments on commit bbca36f

Please sign in to comment.