A platform for community discussion. Free, open, simple.
DEV: Make bread-crumb component work with sub-sub-categories
Daniel Waterworthaf5bcb25d52b
diff --git a/app/assets/javascripts/discourse/components/bread-crumbs.js.es6 b/app/assets/javascripts/discourse/components/bread-crumbs.js.es6index c1e013cac97..9556aceff4a 100644--- a/app/assets/javascripts/discourse/components/bread-crumbs.js.es6+++ b/app/assets/javascripts/discourse/components/bread-crumbs.js.es6@@ -1,15 +1,64 @@import { alias, filter, or } from "@ember/object/computed";import Component from "@ember/component";import { default as discourseComputed } from "discourse-common/utils/decorators";+import deprecated from "discourse-common/lib/deprecated";// A breadcrumb including category drop downsexport default Component.extend({classNameBindings: ["hidden:hidden", ":category-breadcrumb"],tagName: "ol",- parentCategory: alias("category.parentCategory"),+ @discourseComputed("categories")+ filteredCategories(categories) {+ return categories.filter(+ category =>+ this.siteSettings.allow_uncategorized_topics ||+ category.id !== this.site.uncategorized_category_id+ );+ },++ @discourseComputed(+ "category.ancestors",+ "filteredCategories",+ "noSubcategories"+ )+ categoryBreadcrumbs(categoryAncestors, filteredCategories, noSubcategories) {+ categoryAncestors = categoryAncestors || [];+ const parentCategories = [undefined, ...categoryAncestors];+ const categories = [...categoryAncestors, undefined];+ const zipped = parentCategories.map((x, i) => [x, categories[i]]);++ return zipped.map(record => {+ const [parentCategory, category] = record;++ const options = filteredCategories.filter(+ c =>+ c.get("parentCategory.id") === (parentCategory && parentCategory.id)+ );++ return {+ category,+ parentCategory,+ options,+ isSubcategory: !!parentCategory,+ noSubcategories: !category && noSubcategories,+ hasOptions: options.length !== 0+ };+ });+ },++ @discourseComputed("category")+ parentCategory(category) {+ deprecated(+ "The parentCategory property of the bread-crumbs component is deprecated"+ );+ return category && category.parentCategory;+ },parentCategories: filter("categories", function(c) {+ deprecated(+ "The parentCategories property of the bread-crumbs component is deprecated"+ );if (c.id === this.site.get("uncategorized_category_id") &&!this.siteSettings.allow_uncategorized_topics@@ -23,6 +72,9 @@ export default Component.extend({@discourseComputed("parentCategories")parentCategoriesSorted(parentCategories) {+ deprecated(+ "The parentCategoriesSorted property of the bread-crumbs component is deprecated"+ );if (this.siteSettings.fixed_category_positions) {return parentCategories;}@@ -35,16 +87,27 @@ export default Component.extend({return this.site.mobileView && !category;},- firstCategory: or("{parentCategory,category}"),+ @discourseComputed("category", "parentCategory")+ firstCategory(category, parentCategory) {+ deprecated(+ "The firstCategory property of the bread-crumbs component is deprecated"+ );+ return parentCategory || category;+ },@discourseComputed("category", "parentCategory")secondCategory(category, parentCategory) {- if (parentCategory) return category;- return null;+ deprecated(+ "The secondCategory property of the bread-crumbs component is deprecated"+ );+ return parentCategory && category;},@discourseComputed("firstCategory", "hideSubcategories")childCategories(firstCategory, hideSubcategories) {+ deprecated(+ "The childCategories property of the bread-crumbs component is deprecated"+ );if (hideSubcategories) {return [];}diff --git a/app/assets/javascripts/discourse/models/category.js.es6 b/app/assets/javascripts/discourse/models/category.js.es6index 57d8f2dcc6a..82084aada3c 100644--- a/app/assets/javascripts/discourse/models/category.js.es6+++ b/app/assets/javascripts/discourse/models/category.js.es6@@ -55,6 +55,11 @@ const Category = RestModel.extend({return { type: "category", id, category: this };},+ @discourseComputed("parentCategory.ancestors")+ ancestors(parentAncestors) {+ return [...(parentAncestors || []), this];+ },+@discourseComputed("notification_level")isMuted(notificationLevel) {return notificationLevel === NotificationLevels.MUTED;diff --git a/app/assets/javascripts/discourse/templates/components/bread-crumbs.hbs b/app/assets/javascripts/discourse/templates/components/bread-crumbs.hbsindex e15d265a6b3..c7bfe57aaf4 100644--- a/app/assets/javascripts/discourse/templates/components/bread-crumbs.hbs+++ b/app/assets/javascripts/discourse/templates/components/bread-crumbs.hbs@@ -1,16 +1,13 @@-{{category-drop- category=firstCategory- categories=parentCategoriesSorted- countSubcategories=true}}--{{#if childCategories}}- {{category-drop- category=secondCategory- parentCategory=firstCategory- categories=childCategories- subCategory=true- noSubcategories=noSubcategories}}-{{/if}}+{{#each categoryBreadcrumbs as |breadcrumb|}}+ {{#if breadcrumb.hasOptions}}+ {{category-drop+ category=breadcrumb.category+ parentCategory=breadcrumb.parentCategory+ categories=breadcrumb.options+ subCategory=breadcrumb.isSubcategory+ noSubcategories=breadcrumb.noSubcategories}}+ {{/if}}+{{/each}}{{#if siteSettings.tagging_enabled}}{{tag-drop