DEV: Remove path building indirection
Tags are now handled just like other context information.
This commit is contained in:
parent
126b9bd16d
commit
7b63c92f47
|
@ -7,40 +7,8 @@ import {
|
||||||
} from "discourse-common/utils/decorators";
|
} from "discourse-common/utils/decorators";
|
||||||
import BulkTopicSelection from "discourse/mixins/bulk-topic-selection";
|
import BulkTopicSelection from "discourse/mixins/bulk-topic-selection";
|
||||||
import {
|
import {
|
||||||
default as NavItem,
|
default as NavItem
|
||||||
customNavItemHref
|
|
||||||
} from "discourse/models/nav-item";
|
} from "discourse/models/nav-item";
|
||||||
import Category from "discourse/models/category";
|
|
||||||
import Site from "discourse/models/site";
|
|
||||||
|
|
||||||
if (customNavItemHref) {
|
|
||||||
customNavItemHref(function(navItem) {
|
|
||||||
if (navItem.get("tagId")) {
|
|
||||||
const name = navItem.get("name");
|
|
||||||
|
|
||||||
if (!Site.currentProp("filters").includes(name)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
let path = "/tags/";
|
|
||||||
const category = navItem.get("category");
|
|
||||||
|
|
||||||
if (category) {
|
|
||||||
path += "c/";
|
|
||||||
path += Category.slugFor(category);
|
|
||||||
if (navItem.get("noSubcategories")) {
|
|
||||||
path += "/none";
|
|
||||||
}
|
|
||||||
path += "/";
|
|
||||||
}
|
|
||||||
|
|
||||||
path += `${navItem.get("tagId")}/l/`;
|
|
||||||
return `${path}${name.replace(" ", "-")}`;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Controller.extend(BulkTopicSelection, {
|
export default Controller.extend(BulkTopicSelection, {
|
||||||
application: inject(),
|
application: inject(),
|
||||||
|
|
|
@ -33,8 +33,8 @@ const NavItem = EmberObject.extend({
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
@discourseComputed("filterMode")
|
@discourseComputed("name", "category", "noSubcategories", "tagId")
|
||||||
href(filterMode) {
|
href(filterMode, category, noSubcategories, tagId) {
|
||||||
let customHref = null;
|
let customHref = null;
|
||||||
|
|
||||||
NavItem.customNavItemHrefs.forEach(function(cb) {
|
NavItem.customNavItemHrefs.forEach(function(cb) {
|
||||||
|
@ -48,7 +48,8 @@ const NavItem = EmberObject.extend({
|
||||||
return customHref;
|
return customHref;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Discourse.getURL("/") + filterMode;
|
const context = { category, noSubcategories, tagId };
|
||||||
|
return NavItem.pathFor(filterMode, context);
|
||||||
},
|
},
|
||||||
|
|
||||||
@discourseComputed("name", "category", "noSubcategories")
|
@discourseComputed("name", "category", "noSubcategories")
|
||||||
|
@ -99,6 +100,46 @@ NavItem.reopenClass({
|
||||||
customNavItemHrefs: [],
|
customNavItemHrefs: [],
|
||||||
extraNavItemDescriptors: [],
|
extraNavItemDescriptors: [],
|
||||||
|
|
||||||
|
pathFor(filterType, context) {
|
||||||
|
let path = Discourse.getURL("");
|
||||||
|
let includesCategoryContext = false;
|
||||||
|
let includesTagContext = false;
|
||||||
|
|
||||||
|
if (filterType === "categories") {
|
||||||
|
path += "/categories";
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (context.tagId && Site.currentProp("filters").includes(filterType)) {
|
||||||
|
includesTagContext = true;
|
||||||
|
path += "/tags";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (context.category) {
|
||||||
|
includesCategoryContext = true;
|
||||||
|
path += `/c/${Category.slugFor(context.category)}`;
|
||||||
|
|
||||||
|
if (context.noSubcategories) {
|
||||||
|
path += "/none";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (includesTagContext) {
|
||||||
|
path += `/${context.tagId}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (includesTagContext || includesCategoryContext) {
|
||||||
|
path += "/l";
|
||||||
|
}
|
||||||
|
|
||||||
|
path += `/${filterType}`;
|
||||||
|
|
||||||
|
// In the case of top, the nav item doesn't include a period because the
|
||||||
|
// period has its own selector just below
|
||||||
|
|
||||||
|
return path;
|
||||||
|
},
|
||||||
|
|
||||||
// Create a nav item given a filterType. It returns null if there is not
|
// Create a nav item given a filterType. It returns null if there is not
|
||||||
// valid nav item. The name is a historical artifact.
|
// valid nav item. The name is a historical artifact.
|
||||||
fromText(filterType, opts) {
|
fromText(filterType, opts) {
|
||||||
|
|
Loading…
Reference in New Issue