mirror of
https://github.com/discourse/discourse.git
synced 2025-02-16 08:15:00 +00:00
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) {
|
if (opts.topicCategoryId) {
|
||||||
this.set("model.categoryId", 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 (
|
if (
|
||||||
|
@ -16,7 +16,6 @@ export default Ember.Mixin.create({
|
|||||||
topicTitle,
|
topicTitle,
|
||||||
topicBody,
|
topicBody,
|
||||||
topicCategoryId,
|
topicCategoryId,
|
||||||
topicCategory,
|
|
||||||
topicTags
|
topicTags
|
||||||
) {
|
) {
|
||||||
this.controllerFor("composer").open({
|
this.controllerFor("composer").open({
|
||||||
@ -24,7 +23,6 @@ export default Ember.Mixin.create({
|
|||||||
topicTitle,
|
topicTitle,
|
||||||
topicBody,
|
topicBody,
|
||||||
topicCategoryId,
|
topicCategoryId,
|
||||||
topicCategory,
|
|
||||||
topicTags,
|
topicTags,
|
||||||
draftKey: controller.get("model.draft_key"),
|
draftKey: controller.get("model.draft_key"),
|
||||||
draftSequence: controller.get("model.draft_sequence")
|
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.openComposerWithTopicParams(
|
||||||
this.controllerFor("discovery/topics"),
|
this.controllerFor("discovery/topics"),
|
||||||
title,
|
title,
|
||||||
body,
|
body,
|
||||||
category_id,
|
category_id,
|
||||||
category,
|
|
||||||
tags
|
tags
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -1,23 +1,81 @@
|
|||||||
|
import Category from "discourse/models/category";
|
||||||
|
|
||||||
export default Discourse.Route.extend({
|
export default Discourse.Route.extend({
|
||||||
beforeModel: function(transition) {
|
beforeModel: function(transition) {
|
||||||
const self = this;
|
const self = this;
|
||||||
if (Discourse.User.current()) {
|
if (Discourse.User.current()) {
|
||||||
// User is logged in
|
let category, category_id;
|
||||||
self.replaceWith("discovery.latest").then(function(e) {
|
|
||||||
if (self.controllerFor("navigation/default").get("canCreateTopic")) {
|
if (transition.queryParams.category_id) {
|
||||||
// User can create topic
|
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() {
|
Ember.run.next(function() {
|
||||||
e.send(
|
e.send(
|
||||||
"createNewTopicViaParams",
|
"createNewTopicViaParams",
|
||||||
transition.queryParams.title,
|
transition.queryParams.title,
|
||||||
transition.queryParams.body,
|
transition.queryParams.body,
|
||||||
transition.queryParams.category_id,
|
category_id,
|
||||||
transition.queryParams.category,
|
|
||||||
transition.queryParams.tags
|
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 {
|
} else {
|
||||||
// User is not logged in
|
// User is not logged in
|
||||||
$.cookie("destination_url", window.location.href);
|
$.cookie("destination_url", window.location.href);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user