reenable select boxes for filter by facets

This commit is contained in:
Lars Henrik Mai 2015-06-22 21:33:40 +02:00 committed by Andreas Haller
parent 2caec3d721
commit 2b7ab65432
5 changed files with 21 additions and 9 deletions

View file

@ -4,6 +4,8 @@ class SearchController < ApplicationController
@originator = params[:originator] @originator = params[:originator]
options = params.slice(:paper_type, :originator) options = params.slice(:paper_type, :originator)
@show_filters = true
@response = Paper.search(params[:q], options) @response = Paper.search(params[:q], options)
@papers = @response.page(params[:page]).results @papers = @response.page(params[:page]).results
@paper_type_facets = extract_facets('paper_types') @paper_type_facets = extract_facets('paper_types')

View file

@ -10,4 +10,17 @@ module SearchHelper
end end
end 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 end

View file

@ -64,8 +64,8 @@ class Paper < ActiveRecord::Base
# filters # filters
filter do filter do
bool do bool do
must { term paper_type: options[:paper_type] } if options[:paper_type] must { term paper_type: options[:paper_type] } if options[:paper_type].present?
must { term originator: options[:originator] } if options[:originator] must { term originator: options[:originator] } if options[:originator].present?
# catchall when no filters set # catchall when no filters set
must { match_all } if options.keys.none? {|k| [:paper_type, :originator].include?(k) } must { match_all } if options.keys.none? {|k| [:paper_type, :originator].include?(k) }
end end

View file

@ -1,13 +1,10 @@
= form_tag(search_path, method: :get) = form_tag(search_path, method: :get)
= text_field_tag(:q, params[:q], placeholder: 'Suche…', autofocus: true) = text_field_tag(:q, params[:q], placeholder: 'Suche…', autofocus: true)
- if false #@show_filters - if @show_filters
fieldset fieldset
legend Ergebnisse filtern legend Ergebnisse filtern
.row .row
.small-4.columns .small-4.columns
= label "paper_type", "Typ" = filter_select("paper_type", "Typ", @paper_type_facets, @paper_type)
= select_tag "paper_type", options_for_select(@paper_types_found, @paper_type), include_blank: true, :onchange => "this.form.submit();"
.small-4.columns.end .small-4.columns.end
= label "originator", "Einreicher" = filter_select("originator", "Einreicher", @originator_facets, @originator)
= select_tag "originator", options_for_select(@originators_found, @originator), include_blank: true, :onchange => "this.form.submit();"

View file

@ -2,7 +2,7 @@ div
= render 'search/form' = render 'search/form'
- if params[:q].present? - if false # params[:q].present?
.row .row
.small-4.columns .small-4.columns
= facet_list(@paper_type_facets) = facet_list(@paper_type_facets)