<commit_before>import { extend, override } from 'flarum/extension-utils';
import Model from 'flarum/model';
import Discussion from 'flarum/models/discussion';
import IndexPage from 'flarum/components/index-page';
import DiscussionPage from 'flarum/components/discussion-page';
import DiscussionList from 'flarum/components/discussion-list';
import DiscussionHero from 'flarum/components/discussion-hero';
import Separator from 'flarum/components/separator';
import ActionButton from 'flarum/components/action-button';
import NavItem from 'flarum/components/nav-item';
import ComposerDiscussion from 'flarum/components/composer-discussion';
import SettingsPage from 'flarum/components/settings-page';
import ActivityPost from 'flarum/components/activity-post';
import icon from 'flarum/helpers/icon';
import app from 'flarum/app';

import Category from 'categories/models/category';
import CategoriesPage from 'categories/components/categories-page';
import CategoryHero from 'categories/components/category-hero';
import CategoryNavItem from 'categories/components/category-nav-item';
import MoveDiscussionModal from 'categories/components/move-discussion-modal';
import NotificationDiscussionMoved from 'categories/components/notification-discussion-moved';
import PostDiscussionMoved from 'categories/components/post-discussion-moved';
import categoryLabel from 'categories/helpers/category-label';
import categoryIcon from 'categories/helpers/category-icon';

app.initializers.add('categories', function() {
  // Register routes.
  app.routes['categories'] = ['/categories', CategoriesPage.component()];
  app.routes['category'] = ['/c/:categories', IndexPage.component()];

  // @todo support combination with filters
  // app.routes['category.filter'] = ['/c/:slug/:filter', IndexPage.component({category: true})];

  // Register models.
  app.store.models['categories'] = Category;
  Discussion.prototype.category = Model.one('category');

  // Register components.
  app.postComponentRegistry['discussionMoved'] = PostDiscussionMoved;
  app.notificationComponentRegistry['discussionMoved'] = NotificationDiscussionMoved;

  // ---------------------------------------------------------------------------
  // INDEX PAGE
  // ---------------------------------------------------------------------------

  // Add a category label to each discussion in the discussion list.
  extend(DiscussionList.prototype, 'infoItems', function(items, discussion) {
    var category = discussion.category();
    if (category && category.slug() !== this.props.params.categories) {
      items.add('category', categoryLabel(category), {first: true});
    }
  });

  // Add a link to the categories page, as well as a list of all the categories,
  // to the index page's sidebar.
  extend(IndexPage.prototype, 'navItems', function(items) {
    items.add('categories', NavItem.component({
      icon: 'reorder',
      label: 'Categories',
      href: app.route('categories'),
      config: m.route
    }), {last: true});

    items.add('separator', Separator.component(), {last: true});

    items.add('uncategorized', CategoryNavItem.component({params: this.stickyParams()}), {last: true});

    app.store.all('categories').forEach(category => {
      items.add('category'+category.id(), CategoryNavItem.component({category, params: this.stickyParams()}), {last: true});
    });
  });

  IndexPage.prototype.currentCategory = function() {
    var slug = this.params().categories;
    if (slug) {
      return app.store.getBy('categories', 'slug', slug);
    }
  };

  // If currently viewing a category, insert a category hero at the top of the
  // view.
  extend(IndexPage.prototype, 'view', function(view) {
    var category = this.currentCategory();
    if (category) {
      view.children[0] = CategoryHero.component({category});
    }
  });

  // If currently viewing a category, restyle the 'new discussion' button to use
  // the category's color.
  extend(IndexPage.prototype, 'sidebarItems', function(items) {
    var category = this.currentCategory();
    if (category) {
      items.newDiscussion.content.props.style = 'background-color: '+category.color();
    }
  });

  // Add a parameter for the IndexPage to pass on to the DiscussionList that
  // will let us filter discussions by category.
  extend(IndexPage.prototype, 'params', function(params) {
    params.categories = m.route.param('categories');
  });

  // Translate that parameter into a gambit appended to the search query.
  extend(DiscussionList.prototype, 'params', function(params) {
    if (params.categories) {
      params.q = (params.q || '')+' category:'+params.categories;
      delete params.categories;
    }
  });

  // ---------------------------------------------------------------------------
  // DISCUSSION PAGE
  // ---------------------------------------------------------------------------

  // Include a discussion's category when fetching it.
  extend(DiscussionPage.prototype, 'params', function(params) {
    params.include.push('category');
  });

  // Restyle a discussion's hero to use its category color.
  extend(DiscussionHero.prototype, 'view', function(view) {
    var category = this.props.discussion.category();
    if (category) {
      view.attrs.style = 'background-color: '+category.color();
    }
  });

  // Add the name of a discussion's category to the discussion hero, displayed
  // before the title. Put the title on its own line.
  extend(DiscussionHero.prototype, 'items', function(items) {
    var category = this.props.discussion.category();<commit_msg>Include category in the discussion list request<commit_after>import { extend, override } from 'flarum/extension-utils';
import Model from 'flarum/model';
import Discussion from 'flarum/models/discussion';
import IndexPage from 'flarum/components/index-page';
import DiscussionPage from 'flarum/components/discussion-page';
import DiscussionList from 'flarum/components/discussion-list';
import DiscussionHero from 'flarum/components/discussion-hero';
import Separator from 'flarum/components/separator';
import ActionButton from 'flarum/components/action-button';
import NavItem from 'flarum/components/nav-item';
import ComposerDiscussion from 'flarum/components/composer-discussion';
import SettingsPage from 'flarum/components/settings-page';
import ActivityPost from 'flarum/components/activity-post';
import icon from 'flarum/helpers/icon';
import app from 'flarum/app';

import Category from 'categories/models/category';
import CategoriesPage from 'categories/components/categories-page';
import CategoryHero from 'categories/components/category-hero';
import CategoryNavItem from 'categories/components/category-nav-item';
import MoveDiscussionModal from 'categories/components/move-discussion-modal';
import NotificationDiscussionMoved from 'categories/components/notification-discussion-moved';
import PostDiscussionMoved from 'categories/components/post-discussion-moved';
import categoryLabel from 'categories/helpers/category-label';
import categoryIcon from 'categories/helpers/category-icon';

app.initializers.add('categories', function() {
  // Register routes.
  app.routes['categories'] = ['/categories', CategoriesPage.component()];
  app.routes['category'] = ['/c/:categories', IndexPage.component()];

  // @todo support combination with filters
  // app.routes['category.filter'] = ['/c/:slug/:filter', IndexPage.component({category: true})];

  // Register models.
  app.store.models['categories'] = Category;
  Discussion.prototype.category = Model.one('category');

  // Register components.
  app.postComponentRegistry['discussionMoved'] = PostDiscussionMoved;
  app.notificationComponentRegistry['discussionMoved'] = NotificationDiscussionMoved;

  // ---------------------------------------------------------------------------
  // INDEX PAGE
  // ---------------------------------------------------------------------------

  // Add a category label to each discussion in the discussion list.
  extend(DiscussionList.prototype, 'infoItems', function(items, discussion) {
    var category = discussion.category();
    if (category && category.slug() !== this.props.params.categories) {
      items.add('category', categoryLabel(category), {first: true});
    }
  });

  // Add a link to the categories page, as well as a list of all the categories,
  // to the index page's sidebar.
  extend(IndexPage.prototype, 'navItems', function(items) {
    items.add('categories', NavItem.component({
      icon: 'reorder',
      label: 'Categories',
      href: app.route('categories'),
      config: m.route
    }), {last: true});

    items.add('separator', Separator.component(), {last: true});

    items.add('uncategorized', CategoryNavItem.component({params: this.stickyParams()}), {last: true});

    app.store.all('categories').forEach(category => {
      items.add('category'+category.id(), CategoryNavItem.component({category, params: this.stickyParams()}), {last: true});
    });
  });

  IndexPage.prototype.currentCategory = function() {
    var slug = this.params().categories;
    if (slug) {
      return app.store.getBy('categories', 'slug', slug);
    }
  };

  // If currently viewing a category, insert a category hero at the top of the
  // view.
  extend(IndexPage.prototype, 'view', function(view) {
    var category = this.currentCategory();
    if (category) {
      view.children[0] = CategoryHero.component({category});
    }
  });

  // If currently viewing a category, restyle the 'new discussion' button to use
  // the category's color.
  extend(IndexPage.prototype, 'sidebarItems', function(items) {
    var category = this.currentCategory();
    if (category) {
      items.newDiscussion.content.props.style = 'background-color: '+category.color();
    }
  });

  // Add a parameter for the IndexPage to pass on to the DiscussionList that
  // will let us filter discussions by category.
  extend(IndexPage.prototype, 'params', function(params) {
    params.categories = m.route.param('categories');
  });

  // Translate that parameter into a gambit appended to the search query.
  extend(DiscussionList.prototype, 'params', function(params) {
    params.include.push('category');
    if (params.categories) {
      params.q = (params.q || '')+' category:'+params.categories;
      delete params.categories;
    }
  });

  // ---------------------------------------------------------------------------
  // DISCUSSION PAGE
  // ---------------------------------------------------------------------------

  // Include a discussion's category when fetching it.
  extend(DiscussionPage.prototype, 'params', function(params) {
    params.include.push('category');
  });

  // Restyle a discussion's hero to use its category color.
  extend(DiscussionHero.prototype, 'view', function(view) {
    var category = this.props.discussion.category();
    if (category) {
      view.attrs.style = 'background-color: '+category.color();
    }
  });

  // Add the name of a discussion's category to the discussion hero, displayed
  // before the title. Put the title on its own line.
  extend(DiscussionHero.prototype, 'items', function(items) {
    var category = this.props.discussion.category();
{'fraction_non_alphanumeric': 0.1797983403230124, 'fraction_numerical': 0.0001784598911394664, 'mean_word_length': 3.3509316770186337, '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': '1724813', 'n_tokens_mistral': 2989, 'n_tokens_neox': 2858, 'n_words': 760}