<commit_before>/**
 *
 */
App.ProductsRoute = Ember.Route.extend(
{
  subAction: 'index',

  beforeModel: function(transition)
  {
    console.log('ProductsRoute::beforeModel');
    console.log(transition.params.category);
    console.log('---------------------------');
    if (transition.params.category)
    {
      this.controllerFor('products').set('category', transition.params.category);
      catMap = this.controllerFor('products').get('categoryMap');
      cat = catMap.findBy('urlName', transition.params.category);
      if (typeof cat === 'undefined' && transition.targetName != 'products.search')
      {
        console.log('set previousTransition');
        this.controllerFor('application').set('previousTransition', transition);
        this.transitionTo('index');
      }
      this.controllerFor('products').set('currentCategory', cat);
    }
  },
  model: function(params, transition)
  {
    var self = this;
    var data = null;
    var cat = false;
    var catMap = false;
    this.product_id = false;

    console.log('ProductsRoute::model');
    console.log(transition.params);
    console.log('------------------------------------------------------------');
    //~ else
    //~ {
      //~ this.controllerFor('products').set('category', 'all');
    //~ }

    switch (transition.targetName)
    {
      case 'products.index':
        this.subAction = 'index';
        if (this.controllerFor('products').get('currentCategory'))
        {
          catId = this.controllerFor('products').get('currentCategory').id;
          data = this.store.find('product', { catid: catId, page: this.controllerFor('products').get('page') });
        }
        break;
      case 'products.search':
        this.subAction = 'search';

        var searchParams =
        {
          page: this.controllerFor('products').get('page'),
          perPage: this.controllerFor('products').get('perPage'),
          keywords: this.controllerFor('products').get('keywords')
        }
        console.log(searchParams);

        data = this.store.findQuery('product', searchParams);

        if (! data)
        {
          transition.abort();
          this.transitionTo('index');
        }
        break;
      case 'products.show':
        this.subAction = 'show';

        if (this.controllerFor('products').get('currentCategory'))
        {
          if (transition['providedModelsArray'].length)
          {
            if (typeof transition['providedModels']['products.show']['_data'] != 'undefined')
            {
              this.product_id = transition['providedModels']['products.show']['_data']['id'];
            }
            else
            {
              this.product_id = transition['providedModels']['products.show']['product_id'];
            }
          }

          if (! this.product_id && typeof transition['params']['product_id'] != 'undefined')
          {
            // the last resort
            this.product_id = transition['params']['product_id'];
          }

          if (this.product_id)
          {
            data = this.store.find('product', this.product_id);
          }
        }
        break;
    }
    return data;
  },<commit_msg>cleanup<commit_after>/**
 *
 */
App.ProductsRoute = Ember.Route.extend(
{
  subAction: 'index',

  beforeModel: function(transition)
  {
    console.log('ProductsRoute::beforeModel');
    if (transition.params.category)
    {
      this.controllerFor('products').set('category', transition.params.category);
      catMap = this.controllerFor('products').get('categoryMap');
      cat = catMap.findBy('urlName', transition.params.category);
      if (transition.params.category != 'all' && typeof cat === 'undefined' && transition.targetName != 'products.search')
      {
        this.controllerFor('application').set('previousTransition', transition);
        this.transitionTo('index');
      }
      this.controllerFor('products').set('currentCategory', cat);
    }
  },
  model: function(params, transition)
  {
    var self = this;
    var data = null;
    var cat = false;
    var catMap = false;
    this.product_id = false;

    console.log('ProductsRoute::model');
    //~ console.log(transition.targetName);
    //~ console.log(transition.params);
    //~ console.log('------------------------------------------------------------');

    switch (transition.targetName)
    {
      case 'products.index':
        this.subAction = 'index';
        if (this.controllerFor('products').get('currentCategory'))
        {
          catId = this.controllerFor('products').get('currentCategory').id;
          data = this.store.find('product', { catid: catId, page: this.controllerFor('products').get('page') });
        }
        break;
      case 'products.search':
        this.subAction = 'search';

        var searchParams =
        {
          page: this.controllerFor('products').get('page'),
          perPage: this.controllerFor('products').get('perPage'),
          keywords: this.controllerFor('products').get('keywords')
        }

        data = this.store.findQuery('product', searchParams);

        if (! data)
        {
          transition.abort();
          this.transitionTo('index');
        }
        break;
      case 'products.show':
        this.subAction = 'show';

        if (transition['providedModelsArray'].length)
        {
          if (typeof transition['providedModels']['products.show']['_data'] != 'undefined')
          {
            this.product_id = transition['providedModels']['products.show']['_data']['id'];
          }
          else
          {
            this.product_id = transition['providedModels']['products.show']['product_id'];
          }
        }

        if (! this.product_id && typeof transition['params']['product_id'] != 'undefined')
        {
          // the last resort
          this.product_id = transition['params']['product_id'];
        }

        if (this.product_id)
        {
          data = this.store.find('product', this.product_id);
        }
        else
        {
          console.log('something is bad with transition:');
          console.log(transition);
        }
        break;
    }
    return data;
  },
{'fraction_non_alphanumeric': 0.1772808296872468, 'fraction_numerical': 0.0, 'mean_word_length': 2.1570332480818415, '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': '4909405', 'n_tokens_mistral': 1646, 'n_tokens_neox': 1613, 'n_words': 256}