<commit_before>import Ember from 'ember';
import $ from 'jquery';

export default Ember.Controller.extend({
  autoComlete: Ember.inject.service('geolocation-srv'),
  trasportapi: Ember.inject.service('trasport-api'),
  indexedDbPromised: Ember.inject.service('indexed-db'),
  routeDateUnformated: null,
  routeTimeUnformated: null,
  loaderOn: false,

  actions: {
    fetchData(){
      let routeData = this.get('autoComlete').fetchRouteData();
      if(!routeData.from || !routeData.to){
        return;
      }

      // Initialize loader
      this.set('loaderOn', true);

      // Clear search results
      this.set('model', null);

      // Slide form up
      $('.search-train-form').addClass('form-up');

      // If time and date selected add them to the search query object
      if(this.get('routeDateUnformated')){
        routeData.routeDate = this.get('routeDateUnformated');
      }
      if(this.get('routeTimeUnformated')){
        routeData.routeTime = this.get('routeTimeUnformated');
      }

    },

    locationFrom(e){
      // The service require element id and string to name an object
      this.get('autoComlete').initAutocomplete(e.id, 'from');
    },

    locationTo(e){
      this.get('autoComlete').initAutocomplete(e.id, 'to');
    },

    dateSelected(element){
      let vm = this;// requires for ember to work inside pikadate object
      $(element).pickadate({
        onSet: function(date){
          vm.set('routeDateUnformated', new Date(date.select));
        }
      });
    },

    timeSelected(element){
      let vm = this;
      $(element).pickatime({
        onSet: function(time){
          vm.set('routeTimeUnformated', time.select);
        }
      });
    },
  },//actions

  trasportapiInit(data){

  return  this.get('trasportapi').requestDataFromTrasportApi(data)
    .then((response)=>{

      if(response.identification) {
        Materialize.toast('Journey not Found!', 3000);
        return;
      }
      response.from = data.from.name;
      response.to = data.to.name;
      response.fromTo =`${data.from.name}->${data.to.name}`.replace(/ /gi, "_");
      this.get('indexedDbPromised').saveToDb({
        $dbName: 'transportme-recent',
        $dbStore: 'recent',
        $value: response
      }).then(()=>{
        console.log('added to db');
      });
      return response;
    })
    .then((resp)=>{
      this.set('loaderOn', false);
      this.set('model', resp);
    })
    .catch((err)=>{
      console.log('Trasportapi request failed: ' + err);
      this.set('loaderOn', false);
    });
  },


});
<commit_msg>refactor: Set a short delay for loader and trasport api<commit_after>import Ember from 'ember';
import $ from 'jquery';

export default Ember.Controller.extend({
  autoComlete: Ember.inject.service('geolocation-srv'),
  trasportapi: Ember.inject.service('trasport-api'),
  indexedDbPromised: Ember.inject.service('indexed-db'),
  routeDateUnformated: null,
  routeTimeUnformated: null,
  loaderOn: false,

  actions: {
    fetchData(){
      let routeData = this.get('autoComlete').fetchRouteData();
      if(!routeData.from || !routeData.to){
        return;
      }

      // If time and date selected add them to the search query object
      if(this.get('routeDateUnformated')){
        routeData.routeDate = this.get('routeDateUnformated');
      }
      if(this.get('routeTimeUnformated')){
        routeData.routeTime = this.get('routeTimeUnformated');
      }

      // Clear search results
      this.set('model', null);

      // Slide form up
      $('.search-train-form').addClass('form-up');

      // Delay loader while form is being animated
      Ember.run.later(()=>{
        // Initialize loader
        this.set('loaderOn', true);
        this.trasportapiInit(routeData)
        // keeps scrollbar on while fetching data
        .then(()=> $('body').css('min-height', '100vh') );

      }, 300);

    },

    locationFrom(e){
      // The service require element id and string to name an object
      this.get('autoComlete').initAutocomplete(e.id, 'from');
    },

    locationTo(e){
      this.get('autoComlete').initAutocomplete(e.id, 'to');
    },

    dateSelected(element){
      let vm = this;// requires for ember to work inside pikadate object
      $(element).pickadate({
        onSet: function(date){
          vm.set('routeDateUnformated', new Date(date.select));
        }
      });
    },

    timeSelected(element){
      let vm = this;
      $(element).pickatime({
        onSet: function(time){
          vm.set('routeTimeUnformated', time.select);
        }
      });
    },
  },//actions

  trasportapiInit(data){

  return  this.get('trasportapi').requestDataFromTrasportApi(data)
    .then((response)=>{

      if(response.identification) {
        Materialize.toast('Journey not Found!', 3000);
        return;
      }
      response.from = data.from.name;
      response.to = data.to.name;
      response.fromTo =`${data.from.name}->${data.to.name}`.replace(/ /gi, "_");
      this.get('indexedDbPromised').saveToDb({
        $dbName: 'transportme-recent',
        $dbStore: 'recent',
        $value: response
      }).then(()=>{
        console.log('added to db');
      });
      return response;
    })
    .then((resp)=>{
      this.set('loaderOn', false);
      this.set('model', resp);
    })
    .catch((err)=>{
      console.log('Trasportapi request failed: ' + err);
      this.set('loaderOn', false);
    });
  },


});

{'fraction_non_alphanumeric': 0.15878254492115879, 'fraction_numerical': 0.002566923359002567, 'mean_word_length': 2.593544137022398, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '1168530', 'n_tokens_mistral': 1744, 'n_tokens_neox': 1684, 'n_words': 324}