FEATURE: Bulk `reset read` status.
This commit is contained in:
parent
7a07f14dfc
commit
a07e9f7e71
|
@ -7,7 +7,7 @@
|
||||||
@module Discourse
|
@module Discourse
|
||||||
**/
|
**/
|
||||||
Discourse.BulkNotificationLevelController = Em.Controller.extend({
|
Discourse.BulkNotificationLevelController = Em.Controller.extend({
|
||||||
needs: ['topicBulkActions', 'discoveryTopics'],
|
needs: ['topicBulkActions'],
|
||||||
|
|
||||||
notificationLevelId: null,
|
notificationLevelId: null,
|
||||||
|
|
||||||
|
@ -27,17 +27,9 @@ Discourse.BulkNotificationLevelController = Em.Controller.extend({
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
changeNotificationLevel: function() {
|
changeNotificationLevel: function() {
|
||||||
var self = this;
|
this.get('controllers.topicBulkActions').performAndRefresh({
|
||||||
|
|
||||||
this.get('controllers.topicBulkActions').perform({
|
|
||||||
type: 'change_notification_level',
|
type: 'change_notification_level',
|
||||||
notification_level_id: this.get('notificationLevelId')
|
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');
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
@module Discourse
|
@module Discourse
|
||||||
**/
|
**/
|
||||||
Discourse.TopicBulkActionsController = Ember.ArrayController.extend(Discourse.ModalFunctionality, {
|
Discourse.TopicBulkActionsController = Ember.ArrayController.extend(Discourse.ModalFunctionality, {
|
||||||
|
needs: ['discoveryTopics'],
|
||||||
|
|
||||||
onShow: function() {
|
onShow: function() {
|
||||||
this.set('controllers.modal.modalClass', 'topic-bulk-actions-modal small');
|
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: {
|
actions: {
|
||||||
showChangeCategory: function() {
|
showChangeCategory: function() {
|
||||||
this.send('changeBulkTemplate', 'modal/bulk_change_category');
|
this.send('changeBulkTemplate', 'modal/bulk_change_category');
|
||||||
|
@ -66,6 +76,10 @@ Discourse.TopicBulkActionsController = Ember.ArrayController.extend(Discourse.Mo
|
||||||
});
|
});
|
||||||
self.send('closeModal');
|
self.send('closeModal');
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
resetRead: function() {
|
||||||
|
this.performAndRefresh({ type: 'reset_read' });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
<button class='btn' {{action showChangeCategory}}>{{i18n topics.bulk.change_category}}</button>
|
<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 closeTopics}}>{{i18n topics.bulk.close_topics}}</button>
|
||||||
<button class='btn' {{action showNotificationLevel}}>{{i18n topics.bulk.notification_level}}</button>
|
<button class='btn' {{action showNotificationLevel}}>{{i18n topics.bulk.notification_level}}</button>
|
||||||
|
<button class='btn' {{action resetRead}}>{{i18n topics.bulk.reset_read}}</button>
|
||||||
|
|
|
@ -88,7 +88,7 @@ class TopicsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy_timings
|
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
|
render nothing: true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -52,10 +52,10 @@ class PostTiming < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def self.destroy_for(user_id, topic_id)
|
def self.destroy_for(user_id, topic_ids)
|
||||||
PostTiming.transaction do
|
PostTiming.transaction do
|
||||||
PostTiming.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 = ?', user_id, topic_id])
|
TopicUser.delete_all(['user_id = ? and topic_id in (?)', user_id, topic_ids])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -628,6 +628,7 @@ en:
|
||||||
|
|
||||||
topics:
|
topics:
|
||||||
bulk:
|
bulk:
|
||||||
|
reset_read: "Reset Read"
|
||||||
dismiss_read: "Dismiss Read"
|
dismiss_read: "Dismiss Read"
|
||||||
toggle: "toggle bulk selection of topics"
|
toggle: "toggle bulk selection of topics"
|
||||||
actions: "Bulk Actions"
|
actions: "Bulk Actions"
|
||||||
|
|
|
@ -8,7 +8,7 @@ class TopicsBulkAction
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.operations
|
def self.operations
|
||||||
%w(change_category close change_notification_level)
|
%w(change_category close change_notification_level reset_read)
|
||||||
end
|
end
|
||||||
|
|
||||||
def perform!
|
def perform!
|
||||||
|
@ -19,6 +19,10 @@ class TopicsBulkAction
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def reset_read
|
||||||
|
PostTiming.destroy_for(@user.id, @topic_ids)
|
||||||
|
end
|
||||||
|
|
||||||
def change_category
|
def change_category
|
||||||
topics.each do |t|
|
topics.each do |t|
|
||||||
if guardian.can_edit?(t)
|
if guardian.can_edit?(t)
|
||||||
|
|
|
@ -27,7 +27,7 @@ describe TopicsBulkAction do
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when the user can't edit the topic" do
|
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)
|
Guardian.any_instance.expects(:can_edit?).returns(false)
|
||||||
tba = TopicsBulkAction.new(topic.user, [topic.id], type: 'change_category', category_name: category.name)
|
tba = TopicsBulkAction.new(topic.user, [topic.id], type: 'change_category', category_name: category.name)
|
||||||
topic_ids = tba.perform!
|
topic_ids = tba.perform!
|
||||||
|
@ -38,10 +38,20 @@ describe TopicsBulkAction do
|
||||||
end
|
end
|
||||||
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
|
describe "change_notification_level" do
|
||||||
let(:topic) { Fabricate(:topic) }
|
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
|
it "updates the notification level" do
|
||||||
tba = TopicsBulkAction.new(topic.user, [topic.id], type: 'change_notification_level', notification_level_id: 2)
|
tba = TopicsBulkAction.new(topic.user, [topic.id], type: 'change_notification_level', notification_level_id: 2)
|
||||||
topic_ids = tba.perform!
|
topic_ids = tba.perform!
|
||||||
|
@ -50,7 +60,7 @@ describe TopicsBulkAction do
|
||||||
end
|
end
|
||||||
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
|
it "doesn't change the level" do
|
||||||
Guardian.any_instance.expects(:can_see?).returns(false)
|
Guardian.any_instance.expects(:can_see?).returns(false)
|
||||||
tba = TopicsBulkAction.new(topic.user, [topic.id], type: 'change_notification_level', notification_level_id: 2)
|
tba = TopicsBulkAction.new(topic.user, [topic.id], type: 'change_notification_level', notification_level_id: 2)
|
||||||
|
|
|
@ -345,7 +345,7 @@ describe TopicsController do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'deletes the forum topic user record' do
|
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
|
xhr :delete, :destroy_timings, topic_id: @topic.id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue