FEATURE: support category slug when creating new topic via URL
This commit is contained in:
parent
d35bce96ab
commit
c84415b1f2
|
@ -11,24 +11,17 @@ export default Discourse.Route.extend({
|
||||||
category = Category.findById(category_id);
|
category = Category.findById(category_id);
|
||||||
} else if (transition.queryParams.category) {
|
} else if (transition.queryParams.category) {
|
||||||
const splitCategory = transition.queryParams.category.split("/");
|
const splitCategory = transition.queryParams.category.split("/");
|
||||||
|
category = this._getCategory(
|
||||||
if (!splitCategory[1]) {
|
splitCategory[0],
|
||||||
category = this.site
|
splitCategory[1],
|
||||||
.get("categories")
|
"nameLower"
|
||||||
.findBy("nameLower", splitCategory[0].toLowerCase());
|
);
|
||||||
} else {
|
if (!category) {
|
||||||
const categories = this.site.get("categories");
|
category = this._getCategory(
|
||||||
const mainCategory = categories.findBy(
|
splitCategory[0],
|
||||||
"nameLower",
|
splitCategory[1],
|
||||||
splitCategory[0].toLowerCase()
|
"slug"
|
||||||
);
|
);
|
||||||
category = categories.find(function(item) {
|
|
||||||
return (
|
|
||||||
item &&
|
|
||||||
item.get("nameLower") === splitCategory[1].toLowerCase() &&
|
|
||||||
item.get("parent_category_id") === mainCategory.id
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (category) {
|
if (category) {
|
||||||
|
@ -86,5 +79,27 @@ export default Discourse.Route.extend({
|
||||||
self.replaceWith("login");
|
self.replaceWith("login");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
_getCategory(mainCategory, subCategory, type) {
|
||||||
|
let category;
|
||||||
|
if (!subCategory) {
|
||||||
|
category = this.site
|
||||||
|
.get("categories")
|
||||||
|
.findBy(type, mainCategory.toLowerCase());
|
||||||
|
} else {
|
||||||
|
const categories = this.site.get("categories");
|
||||||
|
const main = categories.findBy(type, mainCategory.toLowerCase());
|
||||||
|
if (main) {
|
||||||
|
category = categories.find(function(item) {
|
||||||
|
return (
|
||||||
|
item &&
|
||||||
|
item.get(type) === subCategory.toLowerCase() &&
|
||||||
|
item.get("parent_category_id") === main.id
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return category;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue