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
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) {
@ -12,42 +15,44 @@ export default Ember.Component.extend({
// Don't show "uncategorized" if allow_uncategorized_topics setting is false.
return false;
}
return !c.get("parentCategory");
}),
parentCategoriesSorted: function() {
let cats = this.get("parentCategories");
@computed("parentCategories")
parentCategoriesSorted(parentCategories) {
if (this.siteSettings.fixed_category_positions) {
return cats;
return parentCategories;
}
return cats.sortBy("totalTopicCount").reverse();
}.property("parentCategories"),
return parentCategories.sortBy("totalTopicCount").reverse();
},
hidden: function() {
return this.site.mobileView && !this.get("category");
}.property("category"),
@computed("category")
hidden(category) {
return this.site.mobileView && !category;
},
firstCategory: function() {
return this.get("parentCategory") || this.get("category");
}.property("parentCategory", "category"),
firstCategory: Ember.computed.or("{parentCategory,category}"),
secondCategory: function() {
if (this.get("parentCategory")) return this.get("category");
@computed("category", "parentCategory")
secondCategory(category, parentCategory) {
if (parentCategory) return category;
return null;
}.property("category", "parentCategory"),
},
childCategories: function() {
if (this.get("hideSubcategories")) {
@computed("firstCategory", "hideSubcategories")
childCategories(firstCategory, hideSubcategories) {
if (hideSubcategories) {
return [];
}
var firstCategory = this.get("firstCategory");
if (!firstCategory) {
return [];
}
return this.get("categories").filter(function(c) {
return c.get("parentCategory") === firstCategory;
});
}.property("firstCategory", "hideSubcategories")
return this.get("categories").filter(
c => c.get("parentCategory") === firstCategory
);
}
});

View File

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