about summary refs log tree commit diff
path: root/app/controllers
diff options
context:
space:
mode:
authormayaeh <mayaeh@marimo-net.org>2019-09-16 21:27:29 +0900
committerEugen Rochko <eugen@zeonfederated.com>2019-09-16 14:27:29 +0200
commitef0d22f232723be035e95bde13310d02bf1c127b (patch)
tree114a12ef4c032dda781ba112b44a0c8ab6de8afc /app/controllers
parentb7420b8643b4028796d1bbd9443241f997957eb4 (diff)
Add search and sort functions to hashtag admin UI (#11829)
* Add search and sort functions to hashtag admin UI

* Move scope processing from tags_controller to tag_filter

* Fix based on method naming conventions

* Fixed not to get 500 errors for invalid requests
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/admin/tags_controller.rb15
1 files changed, 3 insertions, 12 deletions
diff --git a/app/controllers/admin/tags_controller.rb b/app/controllers/admin/tags_controller.rb
index 376ebe44d..65341bbfb 100644
--- a/app/controllers/admin/tags_controller.rb
+++ b/app/controllers/admin/tags_controller.rb
@@ -2,7 +2,6 @@
 
 module Admin
   class TagsController < BaseController
-    before_action :set_tags, only: :index
     before_action :set_tag, except: [:index, :batch, :approve_all, :reject_all]
     before_action :set_usage_by_domain, except: [:index, :batch, :approve_all, :reject_all]
     before_action :set_counters, except: [:index, :batch, :approve_all, :reject_all]
@@ -10,6 +9,7 @@ module Admin
     def index
       authorize :tag, :index?
 
+      @tags = filtered_tags.page(params[:page])
       @form = Form::TagBatch.new
     end
 
@@ -48,10 +48,6 @@ module Admin
 
     private
 
-    def set_tags
-      @tags = filtered_tags.page(params[:page])
-    end
-
     def set_tag
       @tag = Tag.find(params[:id])
     end
@@ -73,16 +69,11 @@ module Admin
     end
 
     def filtered_tags
-      scope = Tag
-      scope = scope.discoverable if filter_params[:context] == 'directory'
-      scope = scope.unreviewed if filter_params[:review] == 'unreviewed'
-      scope = scope.reviewed.order(reviewed_at: :desc) if filter_params[:review] == 'reviewed'
-      scope = scope.pending_review.order(requested_review_at: :desc) if filter_params[:review] == 'pending_review'
-      scope.order(max_score: :desc)
+      TagFilter.new(filter_params).results
     end
 
     def filter_params
-      params.slice(:context, :review, :page).permit(:context, :review, :page)
+      params.slice(:directory, :reviewed, :unreviewed, :pending_review, :page, :popular, :active, :name).permit(:directory, :reviewed, :unreviewed, :pending_review, :page, :popular, :active, :name)
     end
 
     def tag_params