<commit_before>import Ember from 'ember';

export default Ember.Controller.extend({
  ajax: Ember.inject.service(),
  // Session is now automatically injected everywhere
  // session: Ember.inject.service('session'),

  cpvModalIsOpen: false,
  optionsModalIsOpen: false,

  selectedCodes: Ember.A([]),

  rangeIsDisabled: Ember.computed('query.countries', function(){
    return !this.get('query.countries').length;
  }),

  countries: [],
  yearsStart: [],

  yearsRange: Ember.computed('years', function () {
      let yearMin = _.minBy(this.get('years'), 'id').id;
      let yearMax = _.maxBy(this.get('years'), 'id').id;

      this.set('yearsStart', [yearMin,yearMax]);

      return {'min': yearMin, 'max' : yearMax};
  }),

  height: window.innerHeight - 200,

  network: {},

  query: {
    'nodes': 'count',
    'edges': 'count',
    'rawCountries': [],
    'countries': [],
    'years': [2004, 2010],
    'cpvs': []
  },

  jsTree: {
    core: {
      'themes': {
        'url': '/assets/photonui/style.css',
        'name': 'photonui',
      }
    },
    plugins: 'checkbox, search, contextmenu',
    searchOptions: { 'show_only_matches' : true },
    checkbox : {
      "three_state" : true
    }
  },
  searchTerm: '',

  prepareQuery() {
    let self = this;
    self.get('selectedCodes').forEach((v) => {
      self.get('query.cpvs').push(v.id);
    });
  },

  actions: {

    onSelectEvent(value) {
      this.set('query.countries', []);
      value.forEach((v) => {
        this.get('query.countries').push(v.id);
      });

      // this.set('query.country_ids', value);
      // this.prepareQuery();

      let options = this.get('query.countries').length && `{
        "query": {
            "countries": ["${this.get('query.countries').join('", "')}"]
        }
      }`;
      this.get('ajax')
          .post('/contracts/years', { data: options, headers: { 'Content-Type': 'application/json' } })
          .then((data) => {
            this.set('years', data.search.results);
          });
    },

    slidingAction(value) {
      // Ember.debug( "New slider value: %@".fmt( value ) );
      // this.controller.set('years', value[0]);
      this.set('query.years', []);
      this.get('query.years').push(value[0]);
      this.get('query.years').push(value[1]);
      Ember.run.scheduleOnce('afterRender', function() {
        Ember.$('span.left-year').text(value[0]);
        Ember.$('span.right-year').text(value[1]);
      });
      this.set('query.years', _.range(this.get('query.years')[0], ++this.get('query.years')[1]));




    },

    toggleCpvModal() {
      Ember.$('.cpv-modal-open').css('pointer-events', 'none');
      let self = this;
      let options = `{
        "query": {
            "countries": ["${self.get('query.countries').join('", "')}"],
            "years": [${self.get('query.years').join(', ')}]
        }
      }`;

      this.get('ajax')
        .post('/contracts/cpvs', { data: options, headers: { 'Content-Type': 'application/json' } })
        .then((data) => {
          self.set('cpvs', data.search.results);
          this.toggleProperty('cpvModalIsOpen');
          Ember.$('.cpv-modal-open').css('pointer-events', 'inherit');
        });

      console.log(this.get('selectedCodes'));
    },

    toggleOptionsModal() {
      this.toggleProperty('optionsModalIsOpen');
    },

    submitQuery() {
      let self = this;

      // // self.send('loading');

      self.notifications.info('This is probably going to take a while...', {
        autoClear: false
      });

      self.set('isLoading', true);
      self.prepareQuery();

      this.get('store').createRecord('network', {
        options: {<commit_msg>repairs bug on query.years that are sent to api<commit_after>import Ember from 'ember';

export default Ember.Controller.extend({
  ajax: Ember.inject.service(),
  // Session is now automatically injected everywhere
  // session: Ember.inject.service('session'),

  cpvModalIsOpen: false,
  optionsModalIsOpen: false,

  selectedCodes: Ember.A([]),

  rangeIsDisabled: Ember.computed('query.countries', function(){
    return !this.get('query.countries').length;
  }),

  query: {
    'nodes': 'count',
    'edges': 'count',
    'rawCountries': [],
    'countries': [],
    'years': [2004, 2010],
    'cpvs': []
  },

  countries: [],

  yearsStart: [],

  yearsRange: Ember.computed('years', function () {
      let yearMin = _.minBy(this.get('years'), 'id').id;
      let yearMax = _.maxBy(this.get('years'), 'id').id;
      let yearsRange = {'min': yearMin, 'max' : yearMax};

      console.log(`yearMin = ${yearMin} | yearMax = ${yearMax} | yearsRange = ${yearsRange}`);

      this.set('yearsStart', [yearMin,yearMax]);
      this.set('query.years', [yearMin,yearMax]);

      return yearsRange;
  }),

  height: window.innerHeight - 200,

  network: {},

  jsTree: {
    core: {
      'themes': {
        'url': '/assets/photonui/style.css',
        'name': 'photonui',
      }
    },
    plugins: 'checkbox, search, contextmenu',
    searchOptions: { 'show_only_matches' : true },
    checkbox : {
      "three_state" : true
    }
  },
  searchTerm: '',

  prepareQuery() {
    let self = this;
    self.get('selectedCodes').forEach((v) => {
      self.get('query.cpvs').push(v.id);
    });
  },

  actions: {

    onSelectEvent(value) {
      this.set('query.countries', []);
      value.forEach((v) => {
        this.get('query.countries').push(v.id);
      });

      // this.set('query.country_ids', value);
      // this.prepareQuery();

      let options = this.get('query.countries').length && `{
        "query": {
            "countries": ["${this.get('query.countries').join('", "')}"]
        }
      }`;
      this.get('ajax')
          .post('/contracts/years', { data: options, headers: { 'Content-Type': 'application/json' } })
          .then((data) => {
            this.set('years', data.search.results);
          });
    },

    slidingAction(value) {
      // Ember.debug( "New slider value: %@".fmt( value ) );
      // this.controller.set('years', value[0]);
      this.set('query.years', []);
      this.get('query.years').push(value[0]);
      this.get('query.years').push(value[1]);
      Ember.run.scheduleOnce('afterRender', function() {
        Ember.$('span.left-year').text(value[0]);
        Ember.$('span.right-year').text(value[1]);
      });
      this.set('query.years', _.range(this.get('query.years')[0], ++this.get('query.years')[1]));
    },

    toggleCpvModal() {
      Ember.$('.cpv-modal-open').css('pointer-events', 'none');
      let self = this;
      let options = `{
        "query": {
            "countries": ["${self.get('query.countries').join('", "')}"],
            "years": [${self.get('query.years').join(', ')}]
        }
      }`;

      //console.log('options', options);
      this.get('ajax')
        .post('/contracts/cpvs', { data: options, headers: { 'Content-Type': 'application/json' } })
        .then((data) => {
          self.set('cpvs', data.search.results);
          this.toggleProperty('cpvModalIsOpen');
          Ember.$('.cpv-modal-open').css('pointer-events', 'inherit');
        });

      console.log(this.get('selectedCodes'));
    },

    toggleOptionsModal() {
      this.toggleProperty('optionsModalIsOpen');
    },

    submitQuery() {
      let self = this;

      // // self.send('loading');

      self.notifications.info('This is probably going to take a while...', {
        autoClear: false
      });

      self.set('isLoading', true);
      self.prepareQuery();

      this.get('store').createRecord('network', {
        options: {
{'fraction_non_alphanumeric': 0.20720010511102352, 'fraction_numerical': 0.004729996058336618, 'mean_word_length': 2.5520298646756885, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 11, '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': '5884983', 'n_tokens_mistral': 2548, 'n_tokens_neox': 2429, 'n_words': 379}