Class: Blacklight::FacetItemPresenter
- Inherits:
-
Object
- Object
- Blacklight::FacetItemPresenter
- Defined in:
- app/presenters/blacklight/facet_item_presenter.rb
Direct Known Subclasses
FacetCheckboxItemPresenter, FacetGroupedItemPresenter, FacetItemPivotPresenter, InclusiveFacetItemPresenter
Instance Attribute Summary collapse
-
#facet_config ⇒ Object
readonly
Returns the value of attribute facet_config.
-
#facet_field ⇒ Object
readonly
Returns the value of attribute facet_field.
-
#facet_item ⇒ Object
readonly
Returns the value of attribute facet_item.
-
#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
- #add_href(path_options = {}) ⇒ Object
-
#constraint_label ⇒ String
Get the displayable version of the facet’s value for use in e.g.
- #field_label ⇒ Object
- #hits ⇒ Object
- #href(path_options = {}) ⇒ Object
-
#initialize(facet_item, facet_config, view_context, facet_field, search_state = view_context.search_state) ⇒ FacetItemPresenter
constructor
A new instance of FacetItemPresenter.
- #items ⇒ Object
-
#label ⇒ String
Get the displayable version of a facet’s value.
- #remove_href(path = search_state) ⇒ Object
-
#selected? ⇒ Boolean
Check if the query parameters have the given facet field with the given value.
- #value ⇒ Object
Constructor Details
#initialize(facet_item, facet_config, view_context, facet_field, search_state = view_context.search_state) ⇒ FacetItemPresenter
Returns a new instance of FacetItemPresenter.
9 10 11 12 13 14 15 |
# File 'app/presenters/blacklight/facet_item_presenter.rb', line 9 def initialize(facet_item, facet_config, view_context, facet_field, search_state = view_context.search_state) @facet_item = facet_item @facet_config = facet_config @view_context = view_context @facet_field = facet_field @search_state = search_state end |
Instance Attribute Details
#facet_config ⇒ Object (readonly)
Returns the value of attribute facet_config.
5 6 7 |
# File 'app/presenters/blacklight/facet_item_presenter.rb', line 5 def facet_config @facet_config end |
#facet_field ⇒ Object (readonly)
Returns the value of attribute facet_field.
5 6 7 |
# File 'app/presenters/blacklight/facet_item_presenter.rb', line 5 def facet_field @facet_field end |
#facet_item ⇒ Object (readonly)
Returns the value of attribute facet_item.
5 6 7 |
# File 'app/presenters/blacklight/facet_item_presenter.rb', line 5 def facet_item @facet_item end |
#search_state ⇒ Object (readonly)
Returns the value of attribute search_state.
5 6 7 |
# File 'app/presenters/blacklight/facet_item_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_item_presenter.rb', line 5 def view_context @view_context end |
Instance Method Details
#add_href(path_options = {}) ⇒ Object
95 96 97 98 99 100 101 |
# File 'app/presenters/blacklight/facet_item_presenter.rb', line 95 def add_href( = {}) if facet_config.url_method view_context.public_send(facet_config.url_method, facet_config.key, facet_item) else view_context.search_action_path(search_state.add_facet_params_and_redirect(facet_config.key, facet_item).merge()) end end |
#constraint_label ⇒ String
Get the displayable version of the facet’s value for use in e.g. the constraints widget
69 70 71 |
# File 'app/presenters/blacklight/facet_item_presenter.rb', line 69 def constraint_label label end |
#field_label ⇒ Object
36 37 38 |
# File 'app/presenters/blacklight/facet_item_presenter.rb', line 36 def field_label facet_field_presenter.label end |
#hits ⇒ Object
17 18 19 20 21 |
# File 'app/presenters/blacklight/facet_item_presenter.rb', line 17 def hits return unless @facet_item.respond_to? :hits @facet_item.hits end |
#href(path_options = {}) ⇒ Object
81 82 83 84 85 86 87 |
# File 'app/presenters/blacklight/facet_item_presenter.rb', line 81 def href( = {}) if selected? remove_href else add_href() end end |
#items ⇒ Object
23 24 25 26 27 |
# File 'app/presenters/blacklight/facet_item_presenter.rb', line 23 def items return unless @facet_item.respond_to? :items @facet_item.items end |
#label ⇒ String
Get the displayable version of a facet’s value
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/presenters/blacklight/facet_item_presenter.rb', line 44 def label label_value = if facet_item.respond_to? :label facet_item.label else value end if facet_config.helper_method view_context.public_send(facet_config.helper_method, label_value) elsif facet_config.query && facet_config.query[label_value] facet_config.query[label_value][:label] elsif value == Blacklight::SearchState::FilterField::MISSING I18n.t("blacklight.search.facets.missing") elsif facet_config.date = facet_config.date == true ? {} : facet_config.date I18n.l(Time.zone.parse(label_value), **) else label_value.to_s end end |
#remove_href(path = search_state) ⇒ Object
90 91 92 |
# File 'app/presenters/blacklight/facet_item_presenter.rb', line 90 def remove_href(path = search_state) view_context.search_action_path(path.filter(facet_config.key).remove(facet_item)) end |
#selected? ⇒ Boolean
Check if the query parameters have the given facet field with the given value.
32 33 34 |
# File 'app/presenters/blacklight/facet_item_presenter.rb', line 32 def selected? search_state.filter(facet_config).include?(value) end |
#value ⇒ Object
73 74 75 76 77 78 79 |
# File 'app/presenters/blacklight/facet_item_presenter.rb', line 73 def value if facet_item.respond_to? :value facet_item.value else facet_item end end |