mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 03:36:18 +08:00
Support for choosing a destination category when splitting topics.
This commit is contained in:
@ -25,6 +25,10 @@ Discourse.MergeTopicController = Discourse.ObjectController.extend(Discourse.Sel
|
|||||||
return I18n.t('topic.merge_topic.title');
|
return I18n.t('topic.merge_topic.title');
|
||||||
}.property('saving'),
|
}.property('saving'),
|
||||||
|
|
||||||
|
onShow: function() {
|
||||||
|
this.set('controllers.modal.modalClass', 'split-modal');
|
||||||
|
},
|
||||||
|
|
||||||
movePostsToExistingTopic: function() {
|
movePostsToExistingTopic: function() {
|
||||||
this.set('saving', true);
|
this.set('saving', true);
|
||||||
|
|
||||||
|
@ -25,21 +25,31 @@ Discourse.SplitTopicController = Discourse.ObjectController.extend(Discourse.Sel
|
|||||||
}.property('saving'),
|
}.property('saving'),
|
||||||
|
|
||||||
onShow: function() {
|
onShow: function() {
|
||||||
this.set('saving', false);
|
this.setProperties({
|
||||||
|
'controllers.modal.modalClass': 'split-modal',
|
||||||
|
saving: false,
|
||||||
|
categoryId: null,
|
||||||
|
topicName: ''
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
actions: {
|
||||||
movePostsToNewTopic: function() {
|
movePostsToNewTopic: function() {
|
||||||
this.set('saving', true);
|
this.set('saving', true);
|
||||||
|
|
||||||
var postIds = this.get('selectedPosts').map(function(p) { return p.get('id'); }),
|
var postIds = this.get('selectedPosts').map(function(p) { return p.get('id'); }),
|
||||||
replyPostIds = this.get('selectedReplies').map(function(p) { return p.get('id'); }),
|
replyPostIds = this.get('selectedReplies').map(function(p) { return p.get('id'); }),
|
||||||
self = this;
|
self = this,
|
||||||
|
categoryId = this.get('categoryId'),
|
||||||
Discourse.Topic.movePosts(this.get('id'), {
|
saveOpts = {
|
||||||
title: this.get('topicName'),
|
title: this.get('topicName'),
|
||||||
post_ids: postIds,
|
post_ids: postIds,
|
||||||
reply_post_ids: replyPostIds
|
reply_post_ids: replyPostIds
|
||||||
}).then(function(result) {
|
};
|
||||||
|
|
||||||
|
if (!Ember.isNone(categoryId)) { saveOpts.category_id = categoryId; }
|
||||||
|
|
||||||
|
Discourse.Topic.movePosts(this.get('id'), saveOpts).then(function(result) {
|
||||||
// Posts moved
|
// Posts moved
|
||||||
self.send('closeModal');
|
self.send('closeModal');
|
||||||
self.get('topicController').send('toggleMultiSelect');
|
self.get('topicController').send('toggleMultiSelect');
|
||||||
@ -51,5 +61,7 @@ Discourse.SplitTopicController = Discourse.ObjectController.extend(Discourse.Sel
|
|||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -7,7 +7,9 @@
|
|||||||
|
|
||||||
<p>{{{i18n topic.merge_topic.instructions count="selectedPostsCount"}}}</p>
|
<p>{{{i18n topic.merge_topic.instructions count="selectedPostsCount"}}}</p>
|
||||||
|
|
||||||
|
<form>
|
||||||
{{chooseTopic selectedTopicId=selectedTopicId}}
|
{{chooseTopic selectedTopicId=selectedTopicId}}
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
|
@ -9,7 +9,10 @@
|
|||||||
|
|
||||||
<form>
|
<form>
|
||||||
<label>{{i18n topic.split_topic.topic_name}}</label>
|
<label>{{i18n topic.split_topic.topic_name}}</label>
|
||||||
{{textField value=topicName placeholderKey="composer.title_placeholder"}}
|
{{textField value=topicName placeholderKey="composer.title_placeholder" elementId='split-topic-name'}}
|
||||||
|
|
||||||
|
<label>{{i18n categories.category}}</label>
|
||||||
|
{{categoryChooser value=categoryId}}
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -175,6 +175,10 @@
|
|||||||
.chzn-search input {
|
.chzn-search input {
|
||||||
width: 378px;
|
width: 378px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.chzn-search-icon {
|
||||||
|
margin-top: 8px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&.hidden {
|
&.hidden {
|
||||||
@ -208,28 +212,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#move-selected {
|
|
||||||
p {
|
|
||||||
margin-top: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
input[type=radio] {
|
|
||||||
margin-right: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
button {
|
|
||||||
margin-top: 10px;
|
|
||||||
display: block;
|
|
||||||
width: 300px;
|
|
||||||
}
|
|
||||||
|
|
||||||
form {
|
|
||||||
margin-top: 20px;
|
|
||||||
input[type=text] {
|
|
||||||
width: 500px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.flag-modal {
|
.flag-modal {
|
||||||
max-height: 450px;
|
max-height: 450px;
|
||||||
@ -282,6 +264,37 @@
|
|||||||
position: absolute;
|
position: absolute;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.split-modal {
|
||||||
|
.modal-body {
|
||||||
|
position: relative;
|
||||||
|
height: 350px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#move-selected {
|
||||||
|
p {
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type=radio] {
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
margin-top: 10px;
|
||||||
|
display: block;
|
||||||
|
width: 300px;
|
||||||
|
}
|
||||||
|
|
||||||
|
form {
|
||||||
|
margin-top: 20px;
|
||||||
|
#split-topic-name, #choose-topic-title {
|
||||||
|
width: 520px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.invite-modal {
|
.invite-modal {
|
||||||
overflow: visible;
|
overflow: visible;
|
||||||
.ember-text-field {
|
.ember-text-field {
|
||||||
|
1
app/assets/stylesheets/vendor/chosen.css.erb
vendored
1
app/assets/stylesheets/vendor/chosen.css.erb
vendored
@ -20,6 +20,7 @@
|
|||||||
box-shadow : 0 4px 5px rgba(0,0,0,.15);
|
box-shadow : 0 4px 5px rgba(0,0,0,.15);
|
||||||
z-index: 1010;
|
z-index: 1010;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* @end */
|
/* @end */
|
||||||
|
|
||||||
/* @group Single Chosen */
|
/* @group Single Chosen */
|
||||||
|
@ -227,6 +227,8 @@ class TopicsController < ApplicationController
|
|||||||
|
|
||||||
def move_posts
|
def move_posts
|
||||||
params.require(:post_ids)
|
params.require(:post_ids)
|
||||||
|
params.require(:topic_id)
|
||||||
|
params.permit(:category_id)
|
||||||
|
|
||||||
topic = Topic.where(id: params[:topic_id]).first
|
topic = Topic.where(id: params[:topic_id]).first
|
||||||
guardian.ensure_can_move_posts!(topic)
|
guardian.ensure_can_move_posts!(topic)
|
||||||
@ -325,6 +327,7 @@ class TopicsController < ApplicationController
|
|||||||
args = {}
|
args = {}
|
||||||
args[:title] = params[:title] if params[:title].present?
|
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[: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?
|
||||||
|
|
||||||
topic.move_posts(current_user, post_ids_including_replies, args)
|
topic.move_posts(current_user, post_ids_including_replies, args)
|
||||||
end
|
end
|
||||||
|
@ -19,14 +19,14 @@ class PostMover
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_new_topic(title)
|
def to_new_topic(title, category_id=nil)
|
||||||
@move_type = PostMover.move_types[:new_topic]
|
@move_type = PostMover.move_types[:new_topic]
|
||||||
|
|
||||||
Topic.transaction do
|
Topic.transaction do
|
||||||
move_posts_to Topic.create!(
|
move_posts_to Topic.create!(
|
||||||
user: user,
|
user: user,
|
||||||
title: title,
|
title: title,
|
||||||
category: original_topic.category
|
category_id: category_id
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -486,7 +486,7 @@ class Topic < ActiveRecord::Base
|
|||||||
if opts[:destination_topic_id]
|
if opts[:destination_topic_id]
|
||||||
post_mover.to_topic opts[:destination_topic_id]
|
post_mover.to_topic opts[:destination_topic_id]
|
||||||
elsif opts[:title]
|
elsif opts[:title]
|
||||||
post_mover.to_new_topic opts[:title]
|
post_mover.to_new_topic(opts[:title], opts[:category_id])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -763,7 +763,7 @@ en:
|
|||||||
split_topic:
|
split_topic:
|
||||||
title: "Move to New Topic"
|
title: "Move to New Topic"
|
||||||
action: "move to new topic"
|
action: "move to new topic"
|
||||||
topic_name: "New Topic Name:"
|
topic_name: "New Topic Name"
|
||||||
error: "There was an error moving posts to the new topic."
|
error: "There was an error moving posts to the new topic."
|
||||||
instructions:
|
instructions:
|
||||||
one: "You are about to create a new topic and populate it with the post you've selected."
|
one: "You are about to create a new topic and populate it with the post you've selected."
|
||||||
|
@ -469,7 +469,7 @@ id:
|
|||||||
|
|
||||||
move_selected:
|
move_selected:
|
||||||
title: "Move Selected Posts"
|
title: "Move Selected Posts"
|
||||||
topic_name: "New Topic Name:"
|
topic_name: "New Topic Name"
|
||||||
error: "Sorry, there was an error moving those posts."
|
error: "Sorry, there was an error moving those posts."
|
||||||
instructions:
|
instructions:
|
||||||
one: "You are about to create a new topic and populate it with the post you've selected."
|
one: "You are about to create a new topic and populate it with the post you've selected."
|
||||||
|
@ -62,8 +62,8 @@ describe TopicsController do
|
|||||||
let(:p2) { Fabricate(:post, user: user) }
|
let(:p2) { Fabricate(:post, user: user) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
Topic.any_instance.expects(:move_posts).with(user, [p2.id], title: 'blah').returns(topic)
|
Topic.any_instance.expects(:move_posts).with(user, [p2.id], title: 'blah', category_id: 123).returns(topic)
|
||||||
xhr :post, :move_posts, topic_id: topic.id, title: 'blah', post_ids: [p2.id]
|
xhr :post, :move_posts, topic_id: topic.id, title: 'blah', post_ids: [p2.id], category_id: 123
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns success" do
|
it "returns success" do
|
||||||
|
@ -6,7 +6,7 @@ describe PostMover do
|
|||||||
let(:user) { Fabricate(:user) }
|
let(:user) { Fabricate(:user) }
|
||||||
let(:another_user) { Fabricate(:evil_trout) }
|
let(:another_user) { Fabricate(:evil_trout) }
|
||||||
let(:category) { Fabricate(:category, user: user) }
|
let(:category) { Fabricate(:category, user: user) }
|
||||||
let!(:topic) { Fabricate(:topic, user: user, category: category) }
|
let!(:topic) { Fabricate(:topic, user: user) }
|
||||||
let!(:p1) { Fabricate(:post, topic: topic, user: user) }
|
let!(:p1) { Fabricate(:post, topic: topic, user: user) }
|
||||||
let!(:p2) { Fabricate(:post, topic: topic, user: another_user, raw: "Has a link to [evil trout](http://eviltrout.com) which is a cool site.")}
|
let!(:p2) { Fabricate(:post, topic: topic, user: another_user, raw: "Has a link to [evil trout](http://eviltrout.com) which is a cool site.")}
|
||||||
let!(:p3) { Fabricate(:post, topic: topic, user: user)}
|
let!(:p3) { Fabricate(:post, topic: topic, user: user)}
|
||||||
@ -58,7 +58,7 @@ describe PostMover do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context "to a new topic" do
|
context "to a new topic" do
|
||||||
let!(:new_topic) { topic.move_posts(user, [p2.id, p4.id], title: "new testing topic name") }
|
let!(:new_topic) { topic.move_posts(user, [p2.id, p4.id], title: "new testing topic name", category_id: category.id) }
|
||||||
|
|
||||||
it "works correctly" do
|
it "works correctly" do
|
||||||
TopicUser.where(user_id: user.id, topic_id: topic.id).first.last_read_post_number.should == p3.post_number
|
TopicUser.where(user_id: user.id, topic_id: topic.id).first.last_read_post_number.should == p3.post_number
|
||||||
@ -102,7 +102,7 @@ describe PostMover do
|
|||||||
|
|
||||||
let!(:destination_topic) { Fabricate(:topic, user: user ) }
|
let!(:destination_topic) { Fabricate(:topic, user: user ) }
|
||||||
let!(:destination_op) { Fabricate(:post, topic: destination_topic, user: user) }
|
let!(:destination_op) { Fabricate(:post, topic: destination_topic, user: user) }
|
||||||
let!(:moved_to) { topic.move_posts(user, [p2.id, p4.id], destination_topic_id: destination_topic.id )}
|
let!(:moved_to) { topic.move_posts(user, [p2.id, p4.id], destination_topic_id: destination_topic.id)}
|
||||||
|
|
||||||
it "works correctly" do
|
it "works correctly" do
|
||||||
moved_to.should == destination_topic
|
moved_to.should == destination_topic
|
||||||
|
Reference in New Issue
Block a user