mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-05-01 08:25:18 -04:00
FEATURE: If you don't select any topics to "Dissmiss Read" it does all
by filter.
This commit is contained in:
parent
a07e9f7e71
commit
1aa27ade17
5 changed files with 32 additions and 5 deletions
app
assets/javascripts/discourse
controllers
lib
spec/controllers
|
@ -28,6 +28,12 @@ Discourse.DiscoveryTopicsController = Discourse.DiscoveryController.extend({
|
||||||
this.send('loading');
|
this.send('loading');
|
||||||
Discourse.TopicList.find(filter).then(function(list) {
|
Discourse.TopicList.find(filter).then(function(list) {
|
||||||
self.setProperties({ model: list, selected: [] });
|
self.setProperties({ model: list, selected: [] });
|
||||||
|
|
||||||
|
var tracking = Discourse.TopicTrackingState.current();
|
||||||
|
if (tracking) {
|
||||||
|
tracking.sync(list, filter);
|
||||||
|
}
|
||||||
|
|
||||||
self.send('loadingComplete');
|
self.send('loadingComplete');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -43,12 +49,13 @@ Discourse.DiscoveryTopicsController = Discourse.DiscoveryController.extend({
|
||||||
operation = { type: 'change_notification_level',
|
operation = { type: 'change_notification_level',
|
||||||
notification_level: Discourse.Topic.NotificationLevel.REGULAR };
|
notification_level: Discourse.Topic.NotificationLevel.REGULAR };
|
||||||
|
|
||||||
|
var promise;
|
||||||
if (selected.length > 0) {
|
if (selected.length > 0) {
|
||||||
Discourse.Topic.bulkOperation(selected, operation).then(function() {
|
promise = Discourse.Topic.bulkOperation(selected, operation);
|
||||||
self.send('refresh');
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
|
promise = Discourse.Topic.bulkOperationByFilter(this.get('filter'), operation);
|
||||||
}
|
}
|
||||||
|
promise.then(function() { self.send('refresh'); });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -420,6 +420,13 @@ Discourse.Topic.reopenClass({
|
||||||
operation: operation
|
operation: operation
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
bulkOperationByFilter: function(filter, operation) {
|
||||||
|
return Discourse.ajax("/topics/bulk", {
|
||||||
|
type: 'PUT',
|
||||||
|
data: { filter: filter, operation: operation }
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -265,7 +265,15 @@ class TopicsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def bulk
|
def bulk
|
||||||
topic_ids = params.require(:topic_ids).map {|t| t.to_i}
|
if params[:topic_ids].present?
|
||||||
|
topic_ids = params[:topic_ids].map {|t| t.to_i}
|
||||||
|
elsif params[:filter] == 'unread'
|
||||||
|
tq = TopicQuery.new(current_user)
|
||||||
|
topic_ids = TopicQuery.unread_filter(tq.joined_topic_user).listable_topics.pluck(:id)
|
||||||
|
else
|
||||||
|
raise ActionController::ParameterMissing.new(:topic_ids)
|
||||||
|
end
|
||||||
|
|
||||||
operation = params.require(:operation).symbolize_keys
|
operation = params.require(:operation).symbolize_keys
|
||||||
raise ActionController::ParameterMissing.new(:operation_type) if operation[:type].blank?
|
raise ActionController::ParameterMissing.new(:operation_type) if operation[:type].blank?
|
||||||
operator = TopicsBulkAction.new(current_user, topic_ids, operation)
|
operator = TopicsBulkAction.new(current_user, topic_ids, operation)
|
||||||
|
|
|
@ -38,6 +38,10 @@ class TopicQuery
|
||||||
@user = user
|
@user = user
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def joined_topic_user(list=nil)
|
||||||
|
(list || Topic).joins("LEFT OUTER JOIN topic_users AS tu ON (topics.id = tu.topic_id AND tu.user_id = #{@user.id.to_i})")
|
||||||
|
end
|
||||||
|
|
||||||
# Return a list of suggested topics for a topic
|
# Return a list of suggested topics for a topic
|
||||||
def list_suggested_for(topic)
|
def list_suggested_for(topic)
|
||||||
builder = SuggestedTopicsBuilder.new(topic)
|
builder = SuggestedTopicsBuilder.new(topic)
|
||||||
|
@ -209,6 +213,7 @@ class TopicQuery
|
||||||
result.order("topics.#{sort_column} #{sort_dir}")
|
result.order("topics.#{sort_column} #{sort_dir}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# Create results based on a bunch of default options
|
# Create results based on a bunch of default options
|
||||||
def default_results(options={})
|
def default_results(options={})
|
||||||
options.reverse_merge!(@options)
|
options.reverse_merge!(@options)
|
||||||
|
|
|
@ -791,7 +791,7 @@ describe TopicsController do
|
||||||
let(:operation) { {type: 'change_category', category_id: '1'} }
|
let(:operation) { {type: 'change_category', category_id: '1'} }
|
||||||
let(:topic_ids) { [1,2,3] }
|
let(:topic_ids) { [1,2,3] }
|
||||||
|
|
||||||
it "requires a list of topic_ids" do
|
it "requires a list of topic_ids or filter" do
|
||||||
lambda { xhr :put, :bulk, operation: operation }.should raise_error(ActionController::ParameterMissing)
|
lambda { xhr :put, :bulk, operation: operation }.should raise_error(ActionController::ParameterMissing)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue