Class: Blacklight::FacetFieldPresenter
- Inherits:
-
Object
- Object
- Blacklight::FacetFieldPresenter
- Defined in:
- app/presenters/blacklight/facet_field_presenter.rb
Constant Summary collapse
- DEFAULT_FACET_LIMIT =
10
Instance Attribute Summary collapse
-
#display_facet ⇒ Object
readonly
Returns the value of attribute display_facet.
-
#facet_field ⇒ Object
readonly
Returns the value of attribute facet_field.
-
#search_state ⇒ Object
readonly
Returns the value of attribute search_state.
-
#view_context ⇒ Object
readonly
Returns the value of attribute view_context.
Instance Method Summary collapse
- #active? ⇒ Boolean
- #collapsed? ⇒ Boolean
-
#each_value ⇒ Object
Appease rubocop rules by implementing #each_value.
-
#facet_limit ⇒ Object
Look up facet limit for given facet_field.
- #in_advanced_search? ⇒ Boolean
- #in_modal? ⇒ Boolean
-
#initialize(facet_field, display_facet, view_context, search_state = view_context.search_state) ⇒ FacetFieldPresenter
constructor
A new instance of FacetFieldPresenter.
- #item_presenter(facet_item) ⇒ Object
- #label ⇒ Object
- #modal_path ⇒ Object
- #paginator ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize(facet_field, display_facet, view_context, search_state = view_context.search_state) ⇒ FacetFieldPresenter
Returns a new instance of FacetFieldPresenter.
14 15 16 17 18 19 |
# File 'app/presenters/blacklight/facet_field_presenter.rb', line 14 def initialize(facet_field, display_facet, view_context, search_state = view_context.search_state) @facet_field = facet_field @display_facet = display_facet @view_context = view_context @search_state = search_state end |
Instance Attribute Details
#display_facet ⇒ Object (readonly)
Returns the value of attribute display_facet.
5 6 7 |
# File 'app/presenters/blacklight/facet_field_presenter.rb', line 5 def display_facet @display_facet end |
#facet_field ⇒ Object (readonly)
Returns the value of attribute facet_field.
5 6 7 |
# File 'app/presenters/blacklight/facet_field_presenter.rb', line 5 def facet_field @facet_field end |
#search_state ⇒ Object (readonly)
Returns the value of attribute search_state.
5 6 7 |
# File 'app/presenters/blacklight/facet_field_presenter.rb', line 5 def search_state @search_state end |
#view_context ⇒ Object (readonly)
Returns the value of attribute view_context.
5 6 7 |
# File 'app/presenters/blacklight/facet_field_presenter.rb', line 5 def view_context @view_context end |
Instance Method Details
#active? ⇒ Boolean
30 31 32 33 34 35 36 |
# File 'app/presenters/blacklight/facet_field_presenter.rb', line 30 def active? if in_advanced_search? search_state.filter(facet_field).values(except: [:filters, :missing]).any? else search_state.filter(facet_field).any? end end |
#collapsed? ⇒ Boolean
26 27 28 |
# File 'app/presenters/blacklight/facet_field_presenter.rb', line 26 def collapsed? !active? && facet_field.collapse end |
#each_value ⇒ Object
Appease rubocop rules by implementing #each_value
62 63 64 |
# File 'app/presenters/blacklight/facet_field_presenter.rb', line 62 def each_value(&) values.each(&) end |
#facet_limit ⇒ Object
Look up facet limit for given facet_field. Will look at config, and if config is ‘true’ will look up from Solr @response if available. If no limit is available, returns nil. Used from #add_facetting_to_solr to supply f.fieldname.facet.limit values in solr request (no @response available), and used in display (with @response available) to create a facet paginator with the right limit.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'app/presenters/blacklight/facet_field_presenter.rb', line 86 def facet_limit return unless facet_field.limit if @display_facet limit = @display_facet.limit if limit.nil? # we didn't get or a set a limit, so infer one. facet_field.limit if facet_field.limit != true elsif limit == -1 # limit -1 is solr-speak for unlimited nil else limit.to_i - 1 # we added 1 to find out if we needed to paginate end else facet_field.limit == true ? DEFAULT_FACET_LIMIT : facet.limit end end |
#in_advanced_search? ⇒ Boolean
38 39 40 |
# File 'app/presenters/blacklight/facet_field_presenter.rb', line 38 def in_advanced_search? search_state.params[:action] == "advanced_search" end |
#in_modal? ⇒ Boolean
42 43 44 45 |
# File 'app/presenters/blacklight/facet_field_presenter.rb', line 42 def in_modal? modal_like_actions = %w[facet facet_suggest] modal_like_actions.include? search_state.params[:action] end |
#item_presenter(facet_item) ⇒ Object
22 23 24 |
# File 'app/presenters/blacklight/facet_field_presenter.rb', line 22 def item_presenter(facet_item) facet_field.item_presenter.new(facet_item, facet_field, view_context, key, search_state) end |
#label ⇒ Object
53 54 55 |
# File 'app/presenters/blacklight/facet_field_presenter.rb', line 53 def label view_context.facet_field_label(key) end |
#modal_path ⇒ Object
47 48 49 50 51 |
# File 'app/presenters/blacklight/facet_field_presenter.rb', line 47 def modal_path return unless paginator view_context.search_facet_path(id: key) unless paginator&.last_page? end |
#paginator ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/presenters/blacklight/facet_field_presenter.rb', line 66 def paginator return unless display_facet @paginator ||= blacklight_config.facet_paginator_class.new( display_facet.items, sort: display_facet.sort, offset: display_facet.offset, prefix: display_facet.prefix, limit: facet_limit ) end |
#values ⇒ Object
57 58 59 |
# File 'app/presenters/blacklight/facet_field_presenter.rb', line 57 def values search_state&.filter(facet_field)&.values || [] end |