mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
Support for choosing a destination category when splitting topics.
This commit is contained in:
parent
be0d5bd1f0
commit
6063b52d6a
13 changed files with 93 additions and 55 deletions
|
@ -25,6 +25,10 @@ Discourse.MergeTopicController = Discourse.ObjectController.extend(Discourse.Sel
|
|||
return I18n.t('topic.merge_topic.title');
|
||||
}.property('saving'),
|
||||
|
||||
onShow: function() {
|
||||
this.set('controllers.modal.modalClass', 'split-modal');
|
||||
},
|
||||
|
||||
movePostsToExistingTopic: function() {
|
||||
this.set('saving', true);
|
||||
|
||||
|
|
|
@ -25,31 +25,43 @@ Discourse.SplitTopicController = Discourse.ObjectController.extend(Discourse.Sel
|
|||
}.property('saving'),
|
||||
|
||||
onShow: function() {
|
||||
this.set('saving', false);
|
||||
this.setProperties({
|
||||
'controllers.modal.modalClass': 'split-modal',
|
||||
saving: false,
|
||||
categoryId: null,
|
||||
topicName: ''
|
||||
});
|
||||
},
|
||||
|
||||
movePostsToNewTopic: function() {
|
||||
this.set('saving', true);
|
||||
actions: {
|
||||
movePostsToNewTopic: function() {
|
||||
this.set('saving', true);
|
||||
|
||||
var postIds = this.get('selectedPosts').map(function(p) { return p.get('id'); }),
|
||||
replyPostIds = this.get('selectedReplies').map(function(p) { return p.get('id'); }),
|
||||
self = this;
|
||||
var postIds = this.get('selectedPosts').map(function(p) { return p.get('id'); }),
|
||||
replyPostIds = this.get('selectedReplies').map(function(p) { return p.get('id'); }),
|
||||
self = this,
|
||||
categoryId = this.get('categoryId'),
|
||||
saveOpts = {
|
||||
title: this.get('topicName'),
|
||||
post_ids: postIds,
|
||||
reply_post_ids: replyPostIds
|
||||
};
|
||||
|
||||
Discourse.Topic.movePosts(this.get('id'), {
|
||||
title: this.get('topicName'),
|
||||
post_ids: postIds,
|
||||
reply_post_ids: replyPostIds
|
||||
}).then(function(result) {
|
||||
// Posts moved
|
||||
self.send('closeModal');
|
||||
self.get('topicController').send('toggleMultiSelect');
|
||||
Em.run.next(function() { Discourse.URL.routeTo(result.url); });
|
||||
}, function() {
|
||||
// Error moving posts
|
||||
self.flash(I18n.t('topic.split_topic.error'));
|
||||
self.set('saving', false);
|
||||
});
|
||||
return false;
|
||||
if (!Ember.isNone(categoryId)) { saveOpts.category_id = categoryId; }
|
||||
|
||||
Discourse.Topic.movePosts(this.get('id'), saveOpts).then(function(result) {
|
||||
// Posts moved
|
||||
self.send('closeModal');
|
||||
self.get('topicController').send('toggleMultiSelect');
|
||||
Em.run.next(function() { Discourse.URL.routeTo(result.url); });
|
||||
}, function() {
|
||||
// Error moving posts
|
||||
self.flash(I18n.t('topic.split_topic.error'));
|
||||
self.set('saving', false);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
|
|
@ -7,7 +7,9 @@
|
|||
|
||||
<p>{{{i18n topic.merge_topic.instructions count="selectedPostsCount"}}}</p>
|
||||
|
||||
{{chooseTopic selectedTopicId=selectedTopicId}}
|
||||
<form>
|
||||
{{chooseTopic selectedTopicId=selectedTopicId}}
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
|
|
|
@ -9,7 +9,10 @@
|
|||
|
||||
<form>
|
||||
<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>
|
||||
|
||||
</div>
|
||||
|
|
|
@ -175,6 +175,10 @@
|
|||
.chzn-search input {
|
||||
width: 378px;
|
||||
}
|
||||
|
||||
.chzn-search-icon {
|
||||
margin-top: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
&.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 {
|
||||
max-height: 450px;
|
||||
|
@ -282,6 +264,37 @@
|
|||
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 {
|
||||
overflow: visible;
|
||||
.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);
|
||||
z-index: 1010;
|
||||
}
|
||||
|
||||
/* @end */
|
||||
|
||||
/* @group Single Chosen */
|
||||
|
|
|
@ -227,6 +227,8 @@ class TopicsController < ApplicationController
|
|||
|
||||
def move_posts
|
||||
params.require(:post_ids)
|
||||
params.require(:topic_id)
|
||||
params.permit(:category_id)
|
||||
|
||||
topic = Topic.where(id: params[:topic_id]).first
|
||||
guardian.ensure_can_move_posts!(topic)
|
||||
|
@ -325,6 +327,7 @@ class TopicsController < ApplicationController
|
|||
args = {}
|
||||
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?
|
||||
|
||||
topic.move_posts(current_user, post_ids_including_replies, args)
|
||||
end
|
||||
|
|
|
@ -19,14 +19,14 @@ class PostMover
|
|||
end
|
||||
end
|
||||
|
||||
def to_new_topic(title)
|
||||
def to_new_topic(title, category_id=nil)
|
||||
@move_type = PostMover.move_types[:new_topic]
|
||||
|
||||
Topic.transaction do
|
||||
move_posts_to Topic.create!(
|
||||
user: user,
|
||||
title: title,
|
||||
category: original_topic.category
|
||||
category_id: category_id
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -486,7 +486,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]
|
||||
post_mover.to_new_topic(opts[:title], opts[:category_id])
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -763,7 +763,7 @@ en:
|
|||
split_topic:
|
||||
title: "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."
|
||||
instructions:
|
||||
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:
|
||||
title: "Move Selected Posts"
|
||||
topic_name: "New Topic Name:"
|
||||
topic_name: "New Topic Name"
|
||||
error: "Sorry, there was an error moving those posts."
|
||||
instructions:
|
||||
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) }
|
||||
|
||||
before do
|
||||
Topic.any_instance.expects(:move_posts).with(user, [p2.id], title: 'blah').returns(topic)
|
||||
xhr :post, :move_posts, topic_id: topic.id, title: 'blah', post_ids: [p2.id]
|
||||
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], category_id: 123
|
||||
end
|
||||
|
||||
it "returns success" do
|
||||
|
|
|
@ -6,7 +6,7 @@ describe PostMover do
|
|||
let(:user) { Fabricate(:user) }
|
||||
let(:another_user) { Fabricate(:evil_trout) }
|
||||
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!(: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)}
|
||||
|
@ -58,7 +58,7 @@ describe PostMover do
|
|||
end
|
||||
|
||||
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
|
||||
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_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
|
||||
moved_to.should == destination_topic
|
||||
|
|
Loading…
Reference in a new issue