This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/components/bread-crumbs.js.es6
2019-02-25 14:51:14 +01:00

59 lines
1.5 KiB
JavaScript

import { default as computed } from "ember-addons/ember-computed-decorators";
// A breadcrumb including category drop downs
export default Ember.Component.extend({
classNameBindings: ["hidden:hidden", ":category-breadcrumb"],
tagName: "ol",
parentCategory: Ember.computed.alias("category.parentCategory"),
parentCategories: Ember.computed.filter("categories", function(c) {
if (
c.id === this.site.get("uncategorized_category_id") &&
!this.siteSettings.allow_uncategorized_topics
) {
// Don't show "uncategorized" if allow_uncategorized_topics setting is false.
return false;
}
return !c.get("parentCategory");
}),
@computed("parentCategories")
parentCategoriesSorted(parentCategories) {
if (this.siteSettings.fixed_category_positions) {
return parentCategories;
}
return parentCategories.sortBy("totalTopicCount").reverse();
},
@computed("category")
hidden(category) {
return this.site.mobileView && !category;
},
firstCategory: Ember.computed.or("{parentCategory,category}"),
@computed("category", "parentCategory")
secondCategory(category, parentCategory) {
if (parentCategory) return category;
return null;
},
@computed("firstCategory", "hideSubcategories")
childCategories(firstCategory, hideSubcategories) {
if (hideSubcategories) {
return [];
}
if (!firstCategory) {
return [];
}
return this.get("categories").filter(
c => c.get("parentCategory") === firstCategory
);
}
});