FEATURE: land on specified category page when creating topic via URL
This commit is contained in:
parent
7cf6c2825e
commit
7d9c97d661
|
@ -814,32 +814,6 @@ export default Ember.Controller.extend({
|
|||
|
||||
if (opts.topicCategoryId) {
|
||||
this.set("model.categoryId", opts.topicCategoryId);
|
||||
} else if (opts.topicCategory) {
|
||||
const splitCategory = opts.topicCategory.split("/");
|
||||
let category;
|
||||
|
||||
if (!splitCategory[1]) {
|
||||
category = this.site
|
||||
.get("categories")
|
||||
.findBy("nameLower", splitCategory[0].toLowerCase());
|
||||
} else {
|
||||
const categories = this.site.get("categories");
|
||||
const mainCategory = categories.findBy(
|
||||
"nameLower",
|
||||
splitCategory[0].toLowerCase()
|
||||
);
|
||||
category = categories.find(function(item) {
|
||||
return (
|
||||
item &&
|
||||
item.get("nameLower") === splitCategory[1].toLowerCase() &&
|
||||
item.get("parent_category_id") === mainCategory.id
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
if (category) {
|
||||
this.set("model.categoryId", category.get("id"));
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
|
|
|
@ -16,7 +16,6 @@ export default Ember.Mixin.create({
|
|||
topicTitle,
|
||||
topicBody,
|
||||
topicCategoryId,
|
||||
topicCategory,
|
||||
topicTags
|
||||
) {
|
||||
this.controllerFor("composer").open({
|
||||
|
@ -24,7 +23,6 @@ export default Ember.Mixin.create({
|
|||
topicTitle,
|
||||
topicBody,
|
||||
topicCategoryId,
|
||||
topicCategory,
|
||||
topicTags,
|
||||
draftKey: controller.get("model.draft_key"),
|
||||
draftSequence: controller.get("model.draft_sequence")
|
||||
|
|
|
@ -183,13 +183,12 @@ const ApplicationRoute = Discourse.Route.extend(OpenComposer, {
|
|||
});
|
||||
},
|
||||
|
||||
createNewTopicViaParams(title, body, category_id, category, tags) {
|
||||
createNewTopicViaParams(title, body, category_id, tags) {
|
||||
this.openComposerWithTopicParams(
|
||||
this.controllerFor("discovery/topics"),
|
||||
title,
|
||||
body,
|
||||
category_id,
|
||||
category,
|
||||
tags
|
||||
);
|
||||
},
|
||||
|
|
|
@ -1,23 +1,81 @@
|
|||
import Category from "discourse/models/category";
|
||||
|
||||
export default Discourse.Route.extend({
|
||||
beforeModel: function(transition) {
|
||||
const self = this;
|
||||
if (Discourse.User.current()) {
|
||||
// User is logged in
|
||||
self.replaceWith("discovery.latest").then(function(e) {
|
||||
if (self.controllerFor("navigation/default").get("canCreateTopic")) {
|
||||
// User can create topic
|
||||
Ember.run.next(function() {
|
||||
e.send(
|
||||
"createNewTopicViaParams",
|
||||
transition.queryParams.title,
|
||||
transition.queryParams.body,
|
||||
transition.queryParams.category_id,
|
||||
transition.queryParams.category,
|
||||
transition.queryParams.tags
|
||||
let category, category_id;
|
||||
|
||||
if (transition.queryParams.category_id) {
|
||||
category_id = transition.queryParams.category_id;
|
||||
category = Category.findById(category_id);
|
||||
} else if (transition.queryParams.category) {
|
||||
const splitCategory = transition.queryParams.category.split("/");
|
||||
|
||||
if (!splitCategory[1]) {
|
||||
category = this.site
|
||||
.get("categories")
|
||||
.findBy("nameLower", splitCategory[0].toLowerCase());
|
||||
} else {
|
||||
const categories = this.site.get("categories");
|
||||
const mainCategory = categories.findBy(
|
||||
"nameLower",
|
||||
splitCategory[0].toLowerCase()
|
||||
);
|
||||
category = categories.find(function(item) {
|
||||
return (
|
||||
item &&
|
||||
item.get("nameLower") === splitCategory[1].toLowerCase() &&
|
||||
item.get("parent_category_id") === mainCategory.id
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
if (category) {
|
||||
category_id = category.get("id");
|
||||
}
|
||||
}
|
||||
|
||||
if (Boolean(category)) {
|
||||
let route = "discovery.parentCategory";
|
||||
let params = { category, slug: category.get("slug") };
|
||||
if (category.get("parentCategory")) {
|
||||
route = "discovery.category";
|
||||
params = {
|
||||
category,
|
||||
parentSlug: category.get("parentCategory.slug"),
|
||||
slug: category.get("slug")
|
||||
};
|
||||
}
|
||||
|
||||
self.replaceWith(route, params).then(function(e) {
|
||||
if (self.controllerFor("navigation/category").get("canCreateTopic")) {
|
||||
Ember.run.next(function() {
|
||||
e.send(
|
||||
"createNewTopicViaParams",
|
||||
transition.queryParams.title,
|
||||
transition.queryParams.body,
|
||||
category_id,
|
||||
transition.queryParams.tags
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
self.replaceWith("discovery.latest").then(function(e) {
|
||||
if (self.controllerFor("navigation/default").get("canCreateTopic")) {
|
||||
Ember.run.next(function() {
|
||||
e.send(
|
||||
"createNewTopicViaParams",
|
||||
transition.queryParams.title,
|
||||
transition.queryParams.body,
|
||||
null,
|
||||
transition.queryParams.tags
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// User is not logged in
|
||||
$.cookie("destination_url", window.location.href);
|
||||
|
|
Loading…
Reference in New Issue