<commit_before>import Ember from 'ember';

/**
 * Taxons show page
 * This page shows products related to the current taxon
 */
export default Ember.Route.extend({
  // Define the query params
  queryParams: {
    page: {
      refreshModel: true
    }
  },

  //
  model: function(params) {
    // Query and rule for this route
    let query, rule;

    // Check if the query exists
    if( !this.get('currentQuery') ) {
      // Define a query
      query = new YeboSDK.Products();

      // Define the rule
      rule = new YeboSDK.Products.Rules.taxonomy([]);

      // Add the rule to the query
      query.and(rule);

      // Define the number of results per page
      query.perPage(15);

      // Set query and rule to the route
      this.set('currentQuery', query);
      this.set('currentRule', rule);
    } else {
      // Get the current query and rule
      query = this.get('currentQuery');
      rule = this.get('currentRule');
    }

    // Set a new value to the rule
    rule.values = params.taxon.split('/');

    // Set the page
    query.page(params.page);

		// Todo: Reuse taxonomy find all
    return Ember.RSVP.hash({
      taxonomies: this.yebo.store.findAll('taxonomy'),
      taxon: this.yebo.store.find('taxon', params.taxon),
      search: this.yebo.products.search(query)
    });
  },

  // Change the current controller
  setupController: function(controller, model) {
    // This is indispensable, if out, the model won't be passed to the view
    controller.set('model', model);

    // the component that requires current taxon and taxonomies is in application
    let appController = this.controllerFor('application');

    // Define some values
    let taxon = model.taxon;
    let taxonomies = model.taxonomies;

    // Set the values to the application controller
    appController.set('currentTaxonomy', taxon.get('taxonomy'));
    appController.set('taxonomies', taxonomies);
  },

  // When reset the controller
  resetController(controller, isExiting, transition) {
    // Check if the user is leaving the page
    if (isExiting) {
      // Reset the page
      controller.set('page', 1);
    }
  },

  //
  actions: {
    changePage: function(pageNumber) {
      // Change the page number
      this.transitionTo({ queryParams: { page: pageNumber } })
    }
  }<commit_msg>Sort logic in the taxons#show<commit_after>import Ember from 'ember';

/**
 * Taxons show page
 * This page shows products related to the current taxon
 */
export default Ember.Route.extend({
  // Define the query params
  queryParams: {
    page: {
      refreshModel: true
    },
    sort: {
      refreshModel: true
    }
  },

  // Current ordenation
  currentSortParam: 'price-desc',

  //
  model: function(params) {
    // Query and rule for this route
    let query, rule;

    // Check if the query exists
    if( !this.get('currentQuery') ) {
      // Define a query
      query = new YeboSDK.Products();

      // Define the rule
      rule = new YeboSDK.Products.Rules.taxonomy([]);

      // Add the rule to the query
      query.and(rule);

      // Define the number of results per page
      query.perPage(15);

      // Set query and rule to the route
      this.set('currentQuery', query);
      this.set('currentRule', rule);
    } else {
      // Get the current query and rule
      query = this.get('currentQuery');
      rule = this.get('currentRule');
    }

    // Set a new value to the rule
    rule.values = params.taxon.split('/');

    // Check if the sort param exists
    if( params.sort !== undefined )
      this.set('currentSortParam', params.sort);

    // Sort options
    let sortOptions = this.get('currentSortParam').split('-');

    // Set the page
    query.sortBy(sortOptions[0], sortOptions[1]);

    // Set the page
    query.page(params.page);

		// Todo: Reuse taxonomy find all
    return Ember.RSVP.hash({
      taxonomies: this.yebo.store.findAll('taxonomy'),
      taxon: this.yebo.store.find('taxon', params.taxon),
      sortParam: this.get('currentSortParam'),
      search: this.yebo.products.search(query)
    });
  },

  // Change the current controller
  setupController: function(controller, model) {
    // This is indispensable, if out, the model won't be passed to the view
    controller.set('model', model);

    // the component that requires current taxon and taxonomies is in application
    let appController = this.controllerFor('application');

    // Define some values
    let taxon = model.taxon;
    let taxonomies = model.taxonomies;

    // Set the values to the application controller
    appController.set('currentTaxonomy', taxon.get('taxonomy'));
    appController.set('taxonomies', taxonomies);
  },

  // When reset the controller
  resetController(controller, isExiting, transition) {
    // Check if the user is leaving the page
    if (isExiting) {
      // Reset the page
      controller.set('page', 1);

      // Reset the sort
      controller.set('sort', undefined);
    }
  },

  //
  actions: {
    changePage: function(pageNumber) {
      // Change the page number
      this.transitionTo({ queryParams: { page: pageNumber } })
    }
  }
{'fraction_non_alphanumeric': 0.12021751796465333, 'fraction_numerical': 0.001553699747523791, 'mean_word_length': 2.544390915347557, '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': '2645613', 'n_tokens_mistral': 1548, 'n_tokens_neox': 1490, 'n_words': 459}