FIX: count subcategories in breadcrumbs

This commit is contained in:
Sam 2018-07-17 12:06:48 +10:00
parent 292e8a3756
commit 818bc10107
6 changed files with 37 additions and 12 deletions

View File

@ -15,6 +15,15 @@ export default Ember.Component.extend({
return !c.get("parentCategory");
}),
parentCategoriesSorted: function() {
let cats = this.get("parentCategories");
if (this.siteSettings.fixed_category_positions) {
return cats;
}
return cats.sortBy("totalTopicCount").reverse();
}.property("parentCategories"),
hidden: function() {
return this.site.mobileView && !this.get("category");
}.property("category"),

View File

@ -77,6 +77,17 @@ const Category = RestModel.extend({
return topicCount > (this.get("num_featured_topics") || 2);
},
@computed("topic_count", "subcategories")
totalTopicCount(topicCount, subcats) {
let count = topicCount;
if (subcats) {
subcats.forEach(s => {
count += s.get("topic_count");
});
}
return count;
},
save() {
const id = this.get("id");
const url = id ? `/categories/${id}` : "/categories";

View File

@ -1,6 +1,9 @@
{{category-drop
{{
category-drop
category=firstCategory
categories=parentCategories}}
categories=parentCategoriesSorted
countSubcategories=true
}}
{{#if childCategories}}
{{category-drop

View File

@ -31,15 +31,12 @@ createWidget("hamburger-category", {
}
if (!this.currentUser) {
let count = c.get("topic_count");
let count;
if (c.get("show_subcategory_list")) {
const subcats = c.get("subcategories");
if (subcats) {
subcats.forEach(s => {
count += s.get("topic_count");
});
}
count = c.get("totalTopicCount");
} else {
count = c.get("topic_count");
}
results.push(h("b.topics-count", number(count)));

View File

@ -35,6 +35,7 @@ export default ComboBoxComponent.extend({
this.get("rowComponentOptions").setProperties({
hideParentCategory: this.get("subCategory"),
allowUncategorized: true,
countSubcategories: this.get("countSubcategories"),
displayCategoryDescription: !(
this.currentUser &&
(this.currentUser.get("staff") || this.currentUser.trust_level > 0)

View File

@ -70,9 +70,13 @@ export default SelectKitRowComponent.extend({
return category.get("parent_category_id");
},
@computed("category.topic_count")
topicCount(topicCount) {
return `× ${topicCount}`.htmlSafe();
@computed(
"category.totalTopicCount",
"category.topic_count",
"options.countSubcategories"
)
topicCount(totalCount, topicCount, countSubcats) {
return `× ${countSubcats ? totalCount : topicCount}`.htmlSafe();
},
@computed("displayCategoryDescription", "category.description")