<commit_before>import Ember from 'ember';

export default Ember.Component.extend({
  fixCalc: Ember.inject.service(),
  flightPhase: Ember.inject.service(),
  pinnedFlights: Ember.inject.service(),

  classNames: ['olFullscreen'],

  didInsertElement() {
    let fixCalc = this.get('fixCalc');

    let sidebar = this.$('#sidebar').sidebar();

    this.$('#barogram_panel').resize(() => {
      let height = this.$('#barogram_panel').height() + 10;
      sidebar.css('bottom', height);
      this.$('.ol-scale-line').css('bottom', height);
      this.$('.ol-attribution').css('bottom', height);
    });

    if (window.location.hash &&
      sidebar.find(`li > a[href="#${window.location.hash.substring(1)}"]`).length != 0) {
      sidebar.open(window.location.hash.substring(1));
    }

    let paddingFn = window.paddingFn = () => [20, 20, this.$('#barogram_panel').height() + 20, sidebar.width() + 20];

    let [primaryId, ...otherIds] = this.get('ids');

    let map = window.flightMap.get('map');

    fixCalc.addFlightFromJSON(`/flights/${primaryId}/json`, false);
    otherIds.forEach(otherId => {
      fixCalc.addFlightFromJSON(`/flights/${otherId}/json`);
    });

    let extent = fixCalc.get('flights').getBounds();
    map.getView().fit(extent, map.getSize(), { padding: paddingFn() });

    this.get('pinnedFlights.pinned').filter(function(id) {
      return id !== primaryId;
    }).forEach(function(id) {
      fixCalc.addFlightFromJSON(`/flights/${id}/json`);
    });
  },

  timeInterval: Ember.computed('mapExtent', 'cesiumEnabled', function() {
    if (this.get('cesiumEnabled')) return null;

    let extent = this.get('mapExtent');
    if (!extent) return null;

    let interval = this.get('fixCalc.flights').getMinMaxTimeInExtent(extent);

    return (interval.max == -Infinity) ? null : [interval.min, interval.max];
  }),

  actions: {
    removeFlight(id) {
      let flights = this.get('fixCalc.flights');
      flights.removeObjects(flights.filterBy('id', id));
      this.get('pinnedFlights').unpin(id);
    },

    selectWingman(id) {
      let fixCalc = this.get('fixCalc');
      let pinnedFlights = this.get('pinnedFlights');

      let flights = fixCalc.get('flights');
      let matches = flights.filterBy('id', id);
      if (matches.length !== 0) {
        flights.removeObjects(matches);
        pinnedFlights.unpin(id);
      } else {
        fixCalc.addFlightFromJSON(`/flights/${id}/json`);
        pinnedFlights.pin(id);
      }
    },
  },
});
<commit_msg>components/flight-page: Simplify code<commit_after>import Ember from 'ember';

export default Ember.Component.extend({
  fixCalc: Ember.inject.service(),
  flightPhase: Ember.inject.service(),
  pinnedFlights: Ember.inject.service(),

  classNames: ['olFullscreen'],

  didInsertElement() {
    let fixCalc = this.get('fixCalc');

    let sidebar = this.$('#sidebar').sidebar();

    this.$('#barogram_panel').resize(() => {
      let height = this.$('#barogram_panel').height() + 10;
      sidebar.css('bottom', height);
      this.$('.ol-scale-line').css('bottom', height);
      this.$('.ol-attribution').css('bottom', height);
    });

    if (window.location.hash &&
      sidebar.find(`li > a[href="#${window.location.hash.substring(1)}"]`).length != 0) {
      sidebar.open(window.location.hash.substring(1));
    }

    let paddingFn = window.paddingFn = () => [20, 20, this.$('#barogram_panel').height() + 20, sidebar.width() + 20];

    let [primaryId, ...otherIds] = this.get('ids');

    let map = window.flightMap.get('map');

    fixCalc.addFlightFromJSON(`/flights/${primaryId}/json`, false);
    otherIds.forEach(id => fixCalc.addFlightFromJSON(`/flights/${id}/json`));

    let extent = fixCalc.get('flights').getBounds();
    map.getView().fit(extent, map.getSize(), { padding: paddingFn() });

    this.get('pinnedFlights.pinned')
      .filter(id => id !== primaryId)
      .forEach(id => fixCalc.addFlightFromJSON(`/flights/${id}/json`));
  },

  timeInterval: Ember.computed('mapExtent', 'cesiumEnabled', function() {
    if (this.get('cesiumEnabled')) return null;

    let extent = this.get('mapExtent');
    if (!extent) return null;

    let interval = this.get('fixCalc.flights').getMinMaxTimeInExtent(extent);

    return (interval.max == -Infinity) ? null : [interval.min, interval.max];
  }),

  actions: {
    removeFlight(id) {
      let flights = this.get('fixCalc.flights');
      flights.removeObjects(flights.filterBy('id', id));
      this.get('pinnedFlights').unpin(id);
    },

    selectWingman(id) {
      let fixCalc = this.get('fixCalc');
      let pinnedFlights = this.get('pinnedFlights');

      let flights = fixCalc.get('flights');
      let matches = flights.filterBy('id', id);
      if (matches.length !== 0) {
        flights.removeObjects(matches);
        pinnedFlights.unpin(id);
      } else {
        fixCalc.addFlightFromJSON(`/flights/${id}/json`);
        pinnedFlights.pin(id);
      }
    },
  },
});

{'fraction_non_alphanumeric': 0.19137792103142626, 'fraction_numerical': 0.0056406124093473006, 'mean_word_length': 3.4409660107334528, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '1990790', 'n_tokens_mistral': 1690, 'n_tokens_neox': 1629, 'n_words': 254}