From 439f393d89a20ab94d6a2ced12fa2a3ddea43a84 Mon Sep 17 00:00:00 2001 From: cpradio Date: Wed, 22 Oct 2014 18:31:19 -0400 Subject: [PATCH] Show dismiss posts/topics buttons on category filtered lists --- .../discourse/controllers/discovery/topics.js.es6 | 13 +++++++++---- app/assets/javascripts/discourse/models/topic.js | 6 ++++-- app/controllers/topics_controller.rb | 6 +++++- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 b/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 index a25502d663d..a58dccc90a5 100644 --- a/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 +++ b/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 @@ -85,7 +85,8 @@ var controllerOpts = { if (selected.length > 0) { promise = Discourse.Topic.bulkOperation(selected, operation); } else { - promise = Discourse.Topic.bulkOperationByFilter(this.get('filter'), operation); + var category = this.get('category'); + promise = Discourse.Topic.bulkOperationByFilter('unread', operation, category ? category.id : null); } promise.then(function(result) { if (result && result.topic_ids) { @@ -105,8 +106,12 @@ var controllerOpts = { return Discourse.TopicTrackingState.current(); }.property(), + isFilterPage: function(filter, filterType) { + return filter.match(new RegExp(filterType + '$', 'gi')) ? true : false; + }, + showDismissRead: function() { - return this.get('filter') === 'unread' && this.get('topics.length') > 0; + return this.isFilterPage(this.get('filter'), 'unread') && this.get('topics.length') > 0; }.property('filter', 'topics.length'), showResetNew: function() { @@ -114,8 +119,8 @@ var controllerOpts = { }.property('filter', 'topics.length'), showDismissAtTop: function() { - return (this.get('filter') === 'new' || - this.get('filter') === 'unread') && + return (this.isFilterPage(this.get('filter'), 'new') || + this.isFilterPage(this.get('filter'), 'unread')) && this.get('topics.length') >= 30; }.property('filter', 'topics.length'), diff --git a/app/assets/javascripts/discourse/models/topic.js b/app/assets/javascripts/discourse/models/topic.js index 40c0d9eb877..e0ddb17553d 100644 --- a/app/assets/javascripts/discourse/models/topic.js +++ b/app/assets/javascripts/discourse/models/topic.js @@ -452,10 +452,12 @@ Discourse.Topic.reopenClass({ }); }, - bulkOperationByFilter: function(filter, operation) { + bulkOperationByFilter: function(filter, operation, categoryId) { + var data = { filter: filter, operation: operation }; + if (categoryId) data['categoryId'] = categoryId; return Discourse.ajax("/topics/bulk", { type: 'PUT', - data: { filter: filter, operation: operation } + data: data }); }, diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index f8cdbac396a..6cf0501c5f0 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -359,7 +359,11 @@ class TopicsController < ApplicationController 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) + if params[:categoryId] + topic_ids = TopicQuery.unread_filter(tq.joined_topic_user).listable_topics.where('category_id = ?', params[:categoryId]).pluck(:id) + else + topic_ids = TopicQuery.unread_filter(tq.joined_topic_user).listable_topics.pluck(:id) + end else raise ActionController::ParameterMissing.new(:topic_ids) end