REFACTOR: bread-crumbs (#7064)

This commit is contained in:
Joffrey JAFFEUX 2019-02-25 14:51:14 +01:00 committed by GitHub
parent 6930706830
commit c0dd171cf1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 23 deletions

View File

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

View File

@ -13,9 +13,12 @@
{{/if}} {{/if}}
{{#if siteSettings.tagging_enabled}} {{#if siteSettings.tagging_enabled}}
{{tag-drop firstCategory=firstCategory secondCategory=secondCategory tagId=tagId}} {{tag-drop
firstCategory=firstCategory
secondCategory=secondCategory
tagId=tagId}}
{{/if}} {{/if}}
{{plugin-outlet name="bread-crumbs-right" connectorTagName="li"}} {{plugin-outlet name="bread-crumbs-right" connectorTagName="li"}}
<div class='clear'></div> <div class="clear"></div>