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(&block) ⇒ Object
Appease rubocop rules by implementing #each_value.
-
#facet_limit ⇒ Object
Look up facet limit for given facet_field.
- #in_modal? ⇒ Boolean
-
#initialize(facet_field, display_facet, view_context, search_state = view_context.search_state) ⇒ FacetFieldPresenter
constructor
A new instance of FacetFieldPresenter.
- #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.
10 11 12 13 14 15 |
# File 'app/presenters/blacklight/facet_field_presenter.rb', line 10 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
21 22 23 |
# File 'app/presenters/blacklight/facet_field_presenter.rb', line 21 def active? search_state.filter(facet_field).any? end |
#collapsed? ⇒ Boolean
17 18 19 |
# File 'app/presenters/blacklight/facet_field_presenter.rb', line 17 def collapsed? !active? && facet_field.collapse end |
#each_value(&block) ⇒ Object
Appease rubocop rules by implementing #each_value
44 45 46 |
# File 'app/presenters/blacklight/facet_field_presenter.rb', line 44 def each_value(&block) values.each(&block) 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.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/presenters/blacklight/facet_field_presenter.rb', line 68 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_modal? ⇒ Boolean
25 26 27 |
# File 'app/presenters/blacklight/facet_field_presenter.rb', line 25 def in_modal? search_state.params[:action] == "facet" end |
#label ⇒ Object
35 36 37 |
# File 'app/presenters/blacklight/facet_field_presenter.rb', line 35 def label view_context.facet_field_label(key) end |
#modal_path ⇒ Object
29 30 31 32 33 |
# File 'app/presenters/blacklight/facet_field_presenter.rb', line 29 def modal_path return unless paginator view_context.search_facet_path(id: key) unless paginator&.last_page? end |
#paginator ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/presenters/blacklight/facet_field_presenter.rb', line 48 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
39 40 41 |
# File 'app/presenters/blacklight/facet_field_presenter.rb', line 39 def values search_state&.filter(facet_field)&.values || [] end |