mirror of
https://github.com/discourse/discourse.git
synced 2025-09-12 21:10:47 +08:00
FEATURE: allow selecting a tag when moving posts to a new topic (#6072)
This commit is contained in:
parent
7cba4cbcc6
commit
18f5f646b1
9 changed files with 33 additions and 8 deletions
|
@ -8,6 +8,8 @@ export default Ember.Controller.extend(ModalFunctionality, {
|
|||
topicName: null,
|
||||
saving: false,
|
||||
categoryId: null,
|
||||
tags: null,
|
||||
canAddTags: Ember.computed.alias("site.can_create_tag"),
|
||||
|
||||
topicController: Ember.inject.controller("topic"),
|
||||
selectedPostsCount: Ember.computed.alias(
|
||||
|
@ -29,7 +31,8 @@ export default Ember.Controller.extend(ModalFunctionality, {
|
|||
"modal.modalClass": "split-modal",
|
||||
saving: false,
|
||||
categoryId: null,
|
||||
topicName: ""
|
||||
topicName: "",
|
||||
tags: null
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -40,7 +43,8 @@ export default Ember.Controller.extend(ModalFunctionality, {
|
|||
const options = {
|
||||
title: this.get("topicName"),
|
||||
post_ids: this.get("topicController.selectedPostIds"),
|
||||
category_id: this.get("categoryId")
|
||||
category_id: this.get("categoryId"),
|
||||
tags: this.get("tags")
|
||||
};
|
||||
|
||||
movePosts(this.get("model.id"), options)
|
||||
|
|
|
@ -7,6 +7,10 @@
|
|||
|
||||
<label>{{i18n 'categories.category'}}</label>
|
||||
{{category-chooser value=categoryId class="small"}}
|
||||
{{#if canAddTags}}
|
||||
<label>{{i18n 'tagging.tags'}}</label>
|
||||
{{tag-chooser tags=tags filterable=true categoryId=categoryId}}
|
||||
{{/if}}
|
||||
</form>
|
||||
{{/d-modal-body}}
|
||||
|
||||
|
|
|
@ -127,6 +127,10 @@
|
|||
width: 300px;
|
||||
}
|
||||
|
||||
.category-chooser {
|
||||
margin-bottom: 9px;
|
||||
}
|
||||
|
||||
form {
|
||||
margin-top: 20px;
|
||||
#split-topic-name,
|
||||
|
|
|
@ -55,6 +55,10 @@
|
|||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.category-chooser {
|
||||
margin-bottom: 9px;
|
||||
}
|
||||
|
||||
button {
|
||||
margin-top: 10px;
|
||||
display: block;
|
||||
|
|
|
@ -550,6 +550,7 @@ class TopicsController < ApplicationController
|
|||
post_ids = params.require(:post_ids)
|
||||
topic_id = params.require(:topic_id)
|
||||
params.permit(:category_id)
|
||||
params.permit(:tags)
|
||||
|
||||
topic = Topic.with_deleted.find_by(id: topic_id)
|
||||
guardian.ensure_can_move_posts!(topic)
|
||||
|
@ -792,6 +793,7 @@ class TopicsController < ApplicationController
|
|||
args[:title] = params[:title] if params[:title].present?
|
||||
args[:destination_topic_id] = params[:destination_topic_id].to_i if params[:destination_topic_id].present?
|
||||
args[:category_id] = params[:category_id].to_i if params[:category_id].present?
|
||||
args[:tags] = params[:tags] if params[:tags].present?
|
||||
|
||||
topic.move_posts(current_user, post_ids_including_replies, args)
|
||||
end
|
||||
|
|
|
@ -19,19 +19,21 @@ class PostMover
|
|||
end
|
||||
end
|
||||
|
||||
def to_new_topic(title, category_id = nil)
|
||||
def to_new_topic(title, category_id = nil, tags = nil)
|
||||
@move_type = PostMover.move_types[:new_topic]
|
||||
|
||||
post = Post.find_by(id: post_ids.first)
|
||||
raise Discourse::InvalidParameters unless post
|
||||
|
||||
Topic.transaction do
|
||||
move_posts_to Topic.create!(
|
||||
new_topic = Topic.create!(
|
||||
user: post.user,
|
||||
title: title,
|
||||
category_id: category_id,
|
||||
created_at: post.created_at
|
||||
)
|
||||
DiscourseTagging.tag_topic_by_names(new_topic, Guardian.new(user), tags)
|
||||
move_posts_to new_topic
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -915,7 +915,7 @@ class Topic < ActiveRecord::Base
|
|||
if opts[:destination_topic_id]
|
||||
post_mover.to_topic opts[:destination_topic_id]
|
||||
elsif opts[:title]
|
||||
post_mover.to_new_topic(opts[:title], opts[:category_id])
|
||||
post_mover.to_new_topic(opts[:title], opts[:category_id], opts[:tags])
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue