FEATURE: Bulk `reset read` status.

This commit is contained in:
Robin Ward 2014-02-21 13:03:50 -05:00
parent 7a07f14dfc
commit a07e9f7e71
9 changed files with 41 additions and 19 deletions

View File

@ -7,7 +7,7 @@
@module Discourse
**/
Discourse.BulkNotificationLevelController = Em.Controller.extend({
needs: ['topicBulkActions', 'discoveryTopics'],
needs: ['topicBulkActions'],
notificationLevelId: null,
@ -27,17 +27,9 @@ Discourse.BulkNotificationLevelController = Em.Controller.extend({
actions: {
changeNotificationLevel: function() {
var self = this;
this.get('controllers.topicBulkActions').perform({
this.get('controllers.topicBulkActions').performAndRefresh({
type: 'change_notification_level',
notification_level_id: this.get('notificationLevelId')
}).then(function(topics) {
if (topics) {
// Tell current route to reload
self.get('controllers.discoveryTopics').send('refresh');
self.send('closeModal');
}
});
}
}

View File

@ -8,6 +8,8 @@
@module Discourse
**/
Discourse.TopicBulkActionsController = Ember.ArrayController.extend(Discourse.ModalFunctionality, {
needs: ['discoveryTopics'],
onShow: function() {
this.set('controllers.modal.modalClass', 'topic-bulk-actions-modal small');
},
@ -40,6 +42,14 @@ Discourse.TopicBulkActionsController = Ember.ArrayController.extend(Discourse.Mo
});
},
performAndRefresh: function(operation) {
var self = this;
return this.perform(operation).then(function() {
self.get('controllers.discoveryTopics').send('refresh');
self.send('closeModal');
});
},
actions: {
showChangeCategory: function() {
this.send('changeBulkTemplate', 'modal/bulk_change_category');
@ -66,6 +76,10 @@ Discourse.TopicBulkActionsController = Ember.ArrayController.extend(Discourse.Mo
});
self.send('closeModal');
});
},
resetRead: function() {
this.performAndRefresh({ type: 'reset_read' });
}
}
});

View File

@ -1,3 +1,4 @@
<button class='btn' {{action showChangeCategory}}>{{i18n topics.bulk.change_category}}</button>
<button class='btn' {{action closeTopics}}>{{i18n topics.bulk.close_topics}}</button>
<button class='btn' {{action showNotificationLevel}}>{{i18n topics.bulk.notification_level}}</button>
<button class='btn' {{action resetRead}}>{{i18n topics.bulk.reset_read}}</button>

View File

@ -88,7 +88,7 @@ class TopicsController < ApplicationController
end
def destroy_timings
PostTiming.destroy_for(current_user.id, params[:topic_id].to_i)
PostTiming.destroy_for(current_user.id, [params[:topic_id].to_i])
render nothing: true
end

View File

@ -52,10 +52,10 @@ class PostTiming < ActiveRecord::Base
end
def self.destroy_for(user_id, topic_id)
def self.destroy_for(user_id, topic_ids)
PostTiming.transaction do
PostTiming.delete_all(['user_id = ? and topic_id = ?', user_id, topic_id])
TopicUser.delete_all(['user_id = ? and topic_id = ?', user_id, topic_id])
PostTiming.delete_all(['user_id = ? and topic_id in (?)', user_id, topic_ids])
TopicUser.delete_all(['user_id = ? and topic_id in (?)', user_id, topic_ids])
end
end

View File

@ -628,6 +628,7 @@ en:
topics:
bulk:
reset_read: "Reset Read"
dismiss_read: "Dismiss Read"
toggle: "toggle bulk selection of topics"
actions: "Bulk Actions"

View File

@ -8,7 +8,7 @@ class TopicsBulkAction
end
def self.operations
%w(change_category close change_notification_level)
%w(change_category close change_notification_level reset_read)
end
def perform!
@ -19,6 +19,10 @@ class TopicsBulkAction
private
def reset_read
PostTiming.destroy_for(@user.id, @topic_ids)
end
def change_category
topics.each do |t|
if guardian.can_edit?(t)

View File

@ -27,7 +27,7 @@ describe TopicsBulkAction do
end
context "when the user can't edit the topic" do
it "doesn't change the category" do
it "doesn't change the category" do
Guardian.any_instance.expects(:can_edit?).returns(false)
tba = TopicsBulkAction.new(topic.user, [topic.id], type: 'change_category', category_name: category.name)
topic_ids = tba.perform!
@ -38,10 +38,20 @@ describe TopicsBulkAction do
end
end
describe "reset_read" do
let(:topic) { Fabricate(:topic) }
it "delegates to PostTiming.destroy_for" do
tba = TopicsBulkAction.new(topic.user, [topic.id], type: 'reset_read')
PostTiming.expects(:destroy_for).with(topic.user_id, [topic.id])
topic_ids = tba.perform!
end
end
describe "change_notification_level" do
let(:topic) { Fabricate(:topic) }
context "when the user can edit the topic" do
context "when the user can see the topic" do
it "updates the notification level" do
tba = TopicsBulkAction.new(topic.user, [topic.id], type: 'change_notification_level', notification_level_id: 2)
topic_ids = tba.perform!
@ -50,7 +60,7 @@ describe TopicsBulkAction do
end
end
context "when the user can't edit the topic" do
context "when the user can't see the topic" do
it "doesn't change the level" do
Guardian.any_instance.expects(:can_see?).returns(false)
tba = TopicsBulkAction.new(topic.user, [topic.id], type: 'change_notification_level', notification_level_id: 2)

View File

@ -345,7 +345,7 @@ describe TopicsController do
end
it 'deletes the forum topic user record' do
PostTiming.expects(:destroy_for).with(@user.id, @topic.id)
PostTiming.expects(:destroy_for).with(@user.id, [@topic.id])
xhr :delete, :destroy_timings, topic_id: @topic.id
end