From 2b7ab6543228e3aa673bb3819f2aeda835933e87 Mon Sep 17 00:00:00 2001 From: Lars Henrik Mai Date: Mon, 22 Jun 2015 21:33:40 +0200 Subject: [PATCH] reenable select boxes for filter by facets --- app/controllers/search_controller.rb | 2 ++ app/helpers/search_helper.rb | 13 +++++++++++++ app/models/paper.rb | 4 ++-- app/views/search/_form.slim | 9 +++------ app/views/search/index.html.slim | 2 +- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 0316460..743c0f3 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -4,6 +4,8 @@ class SearchController < ApplicationController @originator = params[:originator] options = params.slice(:paper_type, :originator) + @show_filters = true + @response = Paper.search(params[:q], options) @papers = @response.page(params[:page]).results @paper_type_facets = extract_facets('paper_types') diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index 05f865e..9b88590 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -10,4 +10,17 @@ module SearchHelper end end end + + def filter_select(name, desc, facets, selected) + capture do + concat(label name, desc) + concat( + select_tag name, + options_from_collection_for_select(facets, :term, :term, selected), + include_blank: true, + onchange: "this.form.submit();" + ) + end + end + end diff --git a/app/models/paper.rb b/app/models/paper.rb index 3ec8993..7511510 100644 --- a/app/models/paper.rb +++ b/app/models/paper.rb @@ -64,8 +64,8 @@ class Paper < ActiveRecord::Base # filters filter do bool do - must { term paper_type: options[:paper_type] } if options[:paper_type] - must { term originator: options[:originator] } if options[:originator] + must { term paper_type: options[:paper_type] } if options[:paper_type].present? + must { term originator: options[:originator] } if options[:originator].present? # catchall when no filters set must { match_all } if options.keys.none? {|k| [:paper_type, :originator].include?(k) } end diff --git a/app/views/search/_form.slim b/app/views/search/_form.slim index 3d2edd7..4409801 100644 --- a/app/views/search/_form.slim +++ b/app/views/search/_form.slim @@ -1,13 +1,10 @@ = form_tag(search_path, method: :get) = text_field_tag(:q, params[:q], placeholder: 'Sucheā€¦', autofocus: true) - - if false #@show_filters + - if @show_filters fieldset legend Ergebnisse filtern .row .small-4.columns - = label "paper_type", "Typ" - = select_tag "paper_type", options_for_select(@paper_types_found, @paper_type), include_blank: true, :onchange => "this.form.submit();" + = filter_select("paper_type", "Typ", @paper_type_facets, @paper_type) .small-4.columns.end - = label "originator", "Einreicher" - = select_tag "originator", options_for_select(@originators_found, @originator), include_blank: true, :onchange => "this.form.submit();" - + = filter_select("originator", "Einreicher", @originator_facets, @originator) diff --git a/app/views/search/index.html.slim b/app/views/search/index.html.slim index 5a1dc06..e13fb1a 100644 --- a/app/views/search/index.html.slim +++ b/app/views/search/index.html.slim @@ -2,7 +2,7 @@ div = render 'search/form' -- if params[:q].present? +- if false # params[:q].present? .row .small-4.columns = facet_list(@paper_type_facets)