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]
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')

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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)