<commit_before>/**
 *
 */
App.ProductsRoute = Ember.Route.extend(
{
  model: function(params, transition)
  {
    var data = null;

    console.log('ProductsRoute::model');
    this.controllerFor('products').set('category', params.category);
    var catMap = this.controllerFor('products').get('categoryMap');

    if (catMap)
    {
      this.controllerFor('products').set('currentCategory', catMap[transition.params.category]);
    }

    switch (transition.targetName)
    {
      case 'products.index':
        var cur = this.controllerFor('products').get('currentCategory');
        if (cur)
        {
          catId = this.controllerFor('products').get('currentCategory').id
          console.log('catid for ' + params.category + ' is ' + catId);
          console.log('page: ' + this.controllerFor('products').get('page'));
          data = this.store.find('product', { catid: catId, page: this.controllerFor('products').get('page') });
        }
        else
        {
          transition.abort();
          this.transitionTo('index');
        }
        break;
      case 'products.show':
        if (transition.params.product_id)
        {
          this.product_id = transition.params.product_id;
        }
        else
        {
          this.product_id = transition['providedModels']['products.show']['id'];
        }
        console.log('load product: ' + this.product_id);
        data = this.store.find('product', parseInt(this.product_id));
        break;
    }

    return data;
  },
  setupController: function(controller, model)
  {
    console.log('ProductsRoute::setupController');
    console.log('model: ');
    console.log(model);
    var catid = this.controllerFor('products').get('categoryMap')[controller.get('category')].get('id');
    console.log('category: ' + controller.get('category') + ', id: ' + catid);

    if (this.product_id)
    {
      console.log('model id exists');
      this.controllerFor('action').send('getit', this.product_id);

      this.controllerFor('products').set('currentProduct', model);
//      this.controllerFor('products').set('currentCategory', this.controllerFor('products').get('categoryMap')[controller.get('category')]);
    }
    else
    {
      console.log('model for products exists');
      this.controllerFor('products').set('currentProduct', null);
      this.controllerFor('products').set('model', model);
    }

    model = [];

    // fetch all programs who have content in this category
    var vars =
    {
      catid: catid,
      application:
      {
        master_uid: App.apiHost,
        master_apikey: App.apiKey
      }
    };

    console.log(vars);

    var programs = this.store.find('program', vars).then(function(data)
    {
      controller.set('programs', data);
      console.log(data);
      //~ jQuery.each(data, function(index, value)
      //~ {
        //~ console.log(value);
      //~ });
    });
  },
  renderTemplate: function()
  {
    console.log('ProductsRoute::renderTemplate');
    if (this.product_id)<commit_msg>moved the program loading elsewhere<commit_after>/**
 *
 */
App.ProductsRoute = Ember.Route.extend(
{
  model: function(params, transition)
  {
    var data = null;

    console.log('ProductsRoute::model');
    this.controllerFor('products').set('category', params.category);
    var catMap = this.controllerFor('products').get('categoryMap');

    if (catMap)
    {
      var cat = catMap.findBy('urlName', transition.params.category);
      this.controllerFor('products').set('currentCategory', cat);
    }

    switch (transition.targetName)
    {
      case 'products.index':
        var cur = this.controllerFor('products').get('currentCategory');
        if (cur)
        {
          catId = this.controllerFor('products').get('currentCategory').id
          console.log('catid for ' + params.category + ' is ' + catId);
          console.log('page: ' + this.controllerFor('products').get('page'));
          data = this.store.find('product', { catid: catId, page: this.controllerFor('products').get('page') });
        }
        else
        {
          transition.abort();
          this.transitionTo('index');
        }
        break;
      case 'products.show':
        if (transition.params.product_id)
        {
          this.product_id = transition.params.product_id;
        }
        else
        {
          this.product_id = transition['providedModels']['products.show']['id'];
        }
        console.log('load product: ' + this.product_id);
        data = this.store.find('product', parseInt(this.product_id));
        break;
    }

    return data;
  },
  setupController: function(controller, model)
  {
    console.log('ProductsRoute::setupController');

    var catid = this.controllerFor('products').get('categoryMap').findBy('urlName', controller.get('category')).get('id');

    if (this.product_id)
    {
      this.controllerFor('action').send('getit', this.product_id);
      this.controllerFor('products').set('currentProduct', model);
    }
    else
    {
      this.controllerFor('products').set('currentProduct', null);
      this.controllerFor('products').set('model', model);
    }

    model = [];

    controller.set('programs', this.controllerFor('products').get('categoryMap').findBy('urlName', controller.get('category'))['programs']);
  },
  renderTemplate: function()
  {
    console.log('ProductsRoute::renderTemplate');
    if (this.product_id)
{'fraction_non_alphanumeric': 0.16432791728212703, 'fraction_numerical': 0.0, 'mean_word_length': 2.828268551236749, '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': '4092404', 'n_tokens_mistral': 1562, 'n_tokens_neox': 1537, 'n_words': 234}