diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 6e5b1df3d..c4134468a 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -33,6 +33,7 @@ var initialize_modules = function() { App.Stats.initialize(); App.LocaleSwitcher.initialize(); App.DebatesOrderSelector.initialize(); + App.DebatesTagFilter.initialize(); }; $(function(){ diff --git a/app/assets/javascripts/debates_tag_filter.js.coffee b/app/assets/javascripts/debates_tag_filter.js.coffee new file mode 100644 index 000000000..08b8c7712 --- /dev/null +++ b/app/assets/javascripts/debates_tag_filter.js.coffee @@ -0,0 +1,17 @@ +App.DebatesTagFilter = + + href_with_params: (query_params) -> + loc = window.location + + loc.protocol + "//" + loc.hostname + + (if loc.port then ':' + loc.port else '') + + loc.pathname + + loc.hash + + '?' + $.param(query_params) + + initialize: -> + $('.js-tag-filter').on 'change', -> + query_params = window.getQueryParameters() + query_params['tag'] = $(this).val() + window.location.assign(App.DebatesTagFilter.href_with_params(query_params)) + diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb index 60819fcf6..084bfc1f0 100644 --- a/app/controllers/debates_controller.rb +++ b/app/controllers/debates_controller.rb @@ -1,5 +1,5 @@ class DebatesController < ApplicationController - before_action :parse_order, only: :index + before_action :parse_order, :parse_tag_filter, only: :index before_action :authenticate_user!, except: [:index, :show] load_and_authorize_resource @@ -77,4 +77,9 @@ class DebatesController < ApplicationController @order = @valid_orders.include?(params[:order]) ? params[:order] : 'created_at' end + def parse_tag_filter + valid_tags = ActsAsTaggableOn::Tag.all.map(&:name) + @tag_filter = params[:tag] if valid_tags.include?(params[:tag]) + end + end diff --git a/app/views/debates/_order_selector.erb b/app/views/debates/_order_selector.erb deleted file mode 100644 index de18cfc45..000000000 --- a/app/views/debates/_order_selector.erb +++ /dev/null @@ -1,5 +0,0 @@ -
diff --git a/app/views/debates/index.html.erb b/app/views/debates/index.html.erb index 13600160c..8ab8366fc 100644 --- a/app/views/debates/index.html.erb +++ b/app/views/debates/index.html.erb @@ -1,25 +1,37 @@