Skip to content

A platform for community discussion. Free, open, simple.

FIX: count subcategories in breadcrumbs

Sam818bc1010736
diff --git a/app/assets/javascripts/discourse/components/bread-crumbs.js.es6 b/app/assets/javascripts/discourse/components/bread-crumbs.js.es6
index c8881680108..74012f4817a 100644
--- a/app/assets/javascripts/discourse/components/bread-crumbs.js.es6
+++ b/app/assets/javascripts/discourse/components/bread-crumbs.js.es6
@@ -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"),
diff --git a/app/assets/javascripts/discourse/models/category.js.es6 b/app/assets/javascripts/discourse/models/category.js.es6
index 0afa3fd9bc3..20f070b1e79 100644
--- a/app/assets/javascripts/discourse/models/category.js.es6
+++ b/app/assets/javascripts/discourse/models/category.js.es6
@@ -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";
diff --git a/app/assets/javascripts/discourse/templates/components/bread-crumbs.hbs b/app/assets/javascripts/discourse/templates/components/bread-crumbs.hbs
index e46d6c32e15..bf8fdeefbf8 100644
--- a/app/assets/javascripts/discourse/templates/components/bread-crumbs.hbs
+++ b/app/assets/javascripts/discourse/templates/components/bread-crumbs.hbs
@@ -1,6 +1,9 @@
-{{category-drop
+{{
+ category-drop
category=firstCategory
- categories=parentCategories}}
+ categories=parentCategoriesSorted
+ countSubcategories=true
+}}
{{#if childCategories}}
{{category-drop
diff --git a/app/assets/javascripts/discourse/widgets/hamburger-categories.js.es6 b/app/assets/javascripts/discourse/widgets/hamburger-categories.js.es6
index 8036f1a4e2e..56ffa45a999 100644
--- a/app/assets/javascripts/discourse/widgets/hamburger-categories.js.es6
+++ b/app/assets/javascripts/discourse/widgets/hamburger-categories.js.es6
@@ -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)));
diff --git a/app/assets/javascripts/select-kit/components/category-drop.js.es6 b/app/assets/javascripts/select-kit/components/category-drop.js.es6
index ab63744f44d..f2090eb80ca 100644
--- a/app/assets/javascripts/select-kit/components/category-drop.js.es6
+++ b/app/assets/javascripts/select-kit/components/category-drop.js.es6
@@ -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)
diff --git a/app/assets/javascripts/select-kit/components/category-row.js.es6 b/app/assets/javascripts/select-kit/components/category-row.js.es6
index 7cb5b87d077..e9150dda8ce 100644
--- a/app/assets/javascripts/select-kit/components/category-row.js.es6
+++ b/app/assets/javascripts/select-kit/components/category-row.js.es6
@@ -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")