DEV: Prevent setting filterMode where it can be already be computed

The plan is to switch over all cases where filterMode is set, but, to
prevent breaking plugins and themes, the category and noSubcategories
need to be inferred from any given filterMode before that can happen.
This commit is contained in:
Daniel Waterworth 2019-11-21 13:35:51 +00:00
parent 3344312fb5
commit ffba242de1
4 changed files with 10 additions and 19 deletions

View File

@ -66,14 +66,12 @@ export default (filterArg, params) => {
_setupNavigation(category) { _setupNavigation(category) {
const noSubcategories = params && !!params.no_subcategories, const noSubcategories = params && !!params.no_subcategories,
filterMode = `c/${Category.slugFor(category)}${ filterType = this.filter(category).split("/")[0];
noSubcategories ? "/none" : ""
}/l/${this.filter(category)}`;
this.controllerFor("navigation/category").setProperties({ this.controllerFor("navigation/category").setProperties({
category, category,
filterMode: filterMode, filterType,
noSubcategories: params && params.no_subcategories noSubcategories
}); });
}, },

View File

@ -80,7 +80,10 @@ export default function(filter, extras) {
queryParams, queryParams,
beforeModel() { beforeModel() {
this.controllerFor("navigation/default").set("filterMode", filter); this.controllerFor("navigation/default").set(
"filterType",
filter.split("/")[0]
);
}, },
model(data, transition) { model(data, transition) {

View File

@ -24,8 +24,6 @@ export default DiscourseRoute.extend(FilterModeMixin, {
const tag = this.store.createRecord("tag", { const tag = this.store.createRecord("tag", {
id: Handlebars.Utils.escapeExpression(params.tag_id) id: Handlebars.Utils.escapeExpression(params.tag_id)
}); });
let f = "";
if (params.additional_tags) { if (params.additional_tags) {
this.set( this.set(
"additionalTags", "additionalTags",
@ -39,15 +37,7 @@ export default DiscourseRoute.extend(FilterModeMixin, {
this.set("additionalTags", null); this.set("additionalTags", null);
} }
if (params.category) { this.set("filterType", this.navMode.split("/")[0]);
f = "c/";
if (params.parent_category) {
f += `${params.parent_category}/`;
}
f += `${params.category}/l/`;
}
f += this.navMode;
this.set("filterMode", f);
if (params.category) { if (params.category) {
this.set("categorySlug", params.category); this.set("categorySlug", params.category);
@ -161,7 +151,7 @@ export default DiscourseRoute.extend(FilterModeMixin, {
tag: model, tag: model,
additionalTags: this.additionalTags, additionalTags: this.additionalTags,
category: this.category, category: this.category,
filterMode: this.filterMode, filterType: this.filterType,
navMode: this.navMode, navMode: this.navMode,
tagNotification: this.tagNotification, tagNotification: this.tagNotification,
noSubcategories: this.noSubcategories noSubcategories: this.noSubcategories

View File

@ -1,6 +1,6 @@
{{#d-section bodyClass="navigation-categories" class="navigation-container"}} {{#d-section bodyClass="navigation-categories" class="navigation-container"}}
{{d-navigation {{d-navigation
filterMode="categories" filterType="categories"
showCategoryAdmin=showCategoryAdmin showCategoryAdmin=showCategoryAdmin
createCategory=(route-action "createCategory") createCategory=(route-action "createCategory")
reorderCategories=(route-action "reorderCategories") reorderCategories=(route-action "reorderCategories")