<commit_before>import { queryParams, filterQueryParams } from 'discourse/routes/build-topic-route';

// A helper function to create a category route with parameters
export default function(filter, params) {
  return Discourse.Route.extend({
    queryParams: queryParams,

    model: function(modelParams) {
      return Discourse.Category.findBySlug(modelParams.slug, modelParams.parentSlug);
    },

    afterModel: function(model, transition) {
      if (!model) {
        this.replaceWith('/404');
        return;
      }

      this._setupNavigation(model);
      return Em.RSVP.all([this._createSubcategoryList(model),
                          this._retrieveTopicList(model, transition)]);
    },

    _setupNavigation: function(model) {
      var noSubcategories = params && !!params.no_subcategories,
          filterMode = "c/" + Discourse.Category.slugFor(model) + (noSubcategories ? "/none" : "") + "/l/" + filter;

      this.controllerFor('navigation/category').setProperties({
        category: model,
        filterMode: filterMode,
        noSubcategories: params && params.no_subcategories,
        canEditCategory: model.get('can_edit'),
        canChangeCategoryNotificationLevel: Discourse.User.current()
      });
    },

    _createSubcategoryList: function(model) {
      this._categoryList = null;
      if (Em.isNone(model.get('parentCategory')) && Discourse.SiteSettings.show_subcategory_list) {
        var self = this;
        return Discourse.CategoryList.listForParent(model).then(function(list) {
          self._categoryList = list;
        });
      }

      // If we're not loading a subcategory list just resolve
      return Em.RSVP.resolve();
    },

    _retrieveTopicList: function(model, transition) {
      var listFilter = "c/" + Discourse.Category.slugFor(model) + "/l/" + filter,
          self = this;

      var findOpts = filterQueryParams(transition.queryParams, params),
          extras = { cached: this.isPoppedState(transition) };

      return Discourse.TopicList.list(listFilter, findOpts, extras).then(function(list) {
        // If all the categories are the same, we can hide them
        var hideCategory = !list.get('topics').find(function (t) { return t.get('category') !== model; });
        list.set('hideCategory', hideCategory);
        self.set('topics', list);
      });
    },

    titleToken: function() {
      var filterText = I18n.t('filters.' + filter.replace('/', '.') + '.title', {count: 0}),
          model = this.currentModel;

      return I18n.t('filters.with_category', { filter: filterText, category: model.get('name') });
    },

    setupController: function(controller, model) {
      var topics = this.get('topics'),
          periods = this.controllerFor('discovery').get('periods'),
          periodId = topics.get('for_period') || (filter.indexOf('/') > 0 ? filter.split('/')[1] : '');

      this.controllerFor('navigation/category').set('canCreateTopic', topics.get('can_create_topic'));
      this.controllerFor('discovery/topics').setProperties({
        model: topics,
        category: model,
        period: periods.findBy('id', periodId),
        selected: [],
        noSubcategories: params && !!params.no_subcategories,
        order: model.get('params.order'),
        ascending: model.get('params.ascending'),
      });

      this.controllerFor('search').set('searchContext', model.get('searchContext'));
      this.set('topics', null);

      this.openTopicDraft(topics);
    },

    renderTemplate: function() {
      this.render('navigation/category', { outlet: 'navigation-bar' });

      if (this._categoryList) {
        this.render('discovery/categories', { outlet: 'header-list-container', model: this._categoryList });
      }
      this.render('discovery/topics', { controller: 'discovery/topics', outlet: 'list-container' });
    },

    deactivate: function() {
      this._super();
      this.controllerFor('search').set('searchContext', null);
    },

    actions: {
      setNotification: function(notification_level){
        this.currentModel.setNotification(notification_level);
      }
    }
  });
}<commit_msg>fix params that are send to category route<commit_after>import { queryParams, filterQueryParams } from 'discourse/routes/build-topic-route';

// A helper function to create a category route with parameters
export default function(filter, params) {
  return Discourse.Route.extend({
    queryParams: queryParams,

    model: function(modelParams) {
      return Discourse.Category.findBySlug(modelParams.slug, modelParams.parentSlug);
    },

    afterModel: function(model, transition) {
      if (!model) {
        this.replaceWith('/404');
        return;
      }

      this._setupNavigation(model);
      return Em.RSVP.all([this._createSubcategoryList(model),
                          this._retrieveTopicList(model, transition)]);
    },

    _setupNavigation: function(model) {
      var noSubcategories = params && !!params.no_subcategories,
          filterMode = "c/" + Discourse.Category.slugFor(model) + (noSubcategories ? "/none" : "") + "/l/" + filter;

      this.controllerFor('navigation/category').setProperties({
        category: model,
        filterMode: filterMode,
        noSubcategories: params && params.no_subcategories,
        canEditCategory: model.get('can_edit'),
        canChangeCategoryNotificationLevel: Discourse.User.current()
      });
    },

    _createSubcategoryList: function(model) {
      this._categoryList = null;
      if (Em.isNone(model.get('parentCategory')) && Discourse.SiteSettings.show_subcategory_list) {
        var self = this;
        return Discourse.CategoryList.listForParent(model).then(function(list) {
          self._categoryList = list;
        });
      }

      // If we're not loading a subcategory list just resolve
      return Em.RSVP.resolve();
    },

    _retrieveTopicList: function(model, transition) {
      var listFilter = "c/" + Discourse.Category.slugFor(model) + "/l/" + filter,
          self = this;

      var findOpts = filterQueryParams(transition.queryParams, params),
          extras = { cached: this.isPoppedState(transition) };

      return Discourse.TopicList.list(listFilter, findOpts, extras).then(function(list) {
        // If all the categories are the same, we can hide them
        var hideCategory = !list.get('topics').find(function (t) { return t.get('category') !== model; });
        list.set('hideCategory', hideCategory);
        self.set('topics', list);
      });
    },

    titleToken: function() {
      var filterText = I18n.t('filters.' + filter.replace('/', '.') + '.title', {count: 0}),
          model = this.currentModel;

      return I18n.t('filters.with_category', { filter: filterText, category: model.get('name') });
    },

    setupController: function(controller, model) {
      var topics = this.get('topics'),
          periods = this.controllerFor('discovery').get('periods'),
          periodId = topics.get('for_period') || (filter.indexOf('/') > 0 ? filter.split('/')[1] : '');

      this.controllerFor('navigation/category').set('canCreateTopic', topics.get('can_create_topic'));
      this.controllerFor('discovery/topics').setProperties({
        model: topics,
        category: model,
        period: periods.findBy('id', periodId),
        selected: [],
        noSubcategories: params && !!params.no_subcategories,
        order: topics.get('params.order'),
        ascending: topics.get('params.ascending'),
      });

      this.controllerFor('search').set('searchContext', model.get('searchContext'));
      this.set('topics', null);

      this.openTopicDraft(topics);
    },

    renderTemplate: function() {
      this.render('navigation/category', { outlet: 'navigation-bar' });

      if (this._categoryList) {
        this.render('discovery/categories', { outlet: 'header-list-container', model: this._categoryList });
      }
      this.render('discovery/topics', { controller: 'discovery/topics', outlet: 'list-container' });
    },

    deactivate: function() {
      this._super();
      this.controllerFor('search').set('searchContext', null);
    },

    actions: {
      setNotification: function(notification_level){
        this.currentModel.setNotification(notification_level);
      }
    }
  });
}
{'fraction_non_alphanumeric': 0.1451476793248945, 'fraction_numerical': 0.0024110910186859553, 'mean_word_length': 3.074656188605108, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4670288', 'n_tokens_mistral': 2348, 'n_tokens_neox': 2290, 'n_words': 433}