Module: Blacklight::FacetsHelperBehavior
- Extended by:
- Deprecation
- Includes:
- Facet
- Included in:
- CatalogHelperBehavior
- Defined in:
- app/helpers/blacklight/facets_helper_behavior.rb
Instance Method Summary collapse
- #facet_display_value(field, item) ⇒ String deprecated Deprecated.
- #facet_field_id(facet_field) ⇒ Object deprecated Deprecated.
-
#facet_field_in_params?(field) ⇒ Boolean
Are any facet restrictions for a field in the query parameters?.
- #facet_field_presenter(facet_config, display_facet) ⇒ Object
- #facet_in_params?(field, item) ⇒ Boolean deprecated Deprecated.
- #facet_params(field) ⇒ Object deprecated Deprecated.
-
#facet_partial_name(display_facet = nil) ⇒ String
The name of the partial to use to render a facet field.
- #has_facet_values?(fields = facet_field_names, response = nil) ⇒ Boolean deprecated Deprecated.
- #path_for_facet(facet_field, item, path_options = {}) ⇒ String deprecated Deprecated.
- #render_facet_count(num, options = {}) ⇒ String deprecated Deprecated.
- #render_facet_item(facet_field, item) ⇒ Object deprecated Deprecated.
-
#render_facet_limit(display_facet, options = {}) ⇒ String
Renders a single section for facet limit with a specified solr field used for faceting.
- #render_facet_limit_list(paginator, facet_field, wrapping_element = :li) ⇒ Object deprecated Deprecated.
- #render_facet_partials(fields = nil, options = {}) ⇒ Object deprecated Deprecated.
-
#render_facet_value(facet_field, item, options = {}) ⇒ String
Standard display of a facet value in a list.
- #render_selected_facet_value(facet_field, item) ⇒ Object deprecated Deprecated.
- #should_collapse_facet?(facet_field) ⇒ Boolean deprecated Deprecated.
- #should_render_facet?(display_facet, facet_config = nil) ⇒ Boolean deprecated Deprecated.
Methods included from Facet
#facet_by_field_name, #facet_paginator, #facets_from_request
Instance Method Details
#facet_display_value(field, item) ⇒ String
Get the displayable version of a facet's value
299 300 301 302 303 |
# File 'app/helpers/blacklight/facets_helper_behavior.rb', line 299 def facet_display_value field, item deprecated_method(:facet_display_value) facet_config = facet_configuration_for_field(field) facet_item_presenter(facet_config, item, field).label end |
#facet_field_id(facet_field) ⇒ Object
306 307 308 |
# File 'app/helpers/blacklight/facets_helper_behavior.rb', line 306 def facet_field_id facet_field "facet-#{facet_field.key.parameterize}" end |
#facet_field_in_params?(field) ⇒ Boolean
Are any facet restrictions for a field in the query parameters?
255 256 257 258 259 260 261 |
# File 'app/helpers/blacklight/facets_helper_behavior.rb', line 255 def facet_field_in_params? field config = facet_configuration_for_field(field) Deprecation.silence(Blacklight::SearchState) do search_state.has_facet? config end end |
#facet_field_presenter(facet_config, display_facet) ⇒ Object
189 190 191 |
# File 'app/helpers/blacklight/facets_helper_behavior.rb', line 189 def facet_field_presenter(facet_config, display_facet) (facet_config.presenter || Blacklight::FacetFieldPresenter).new(facet_config, display_facet, self) end |
#facet_in_params?(field, item) ⇒ Boolean
Check if the query parameters have the given facet field with the given value.
273 274 275 276 277 278 279 |
# File 'app/helpers/blacklight/facets_helper_behavior.rb', line 273 def facet_in_params?(field, item) config = facet_configuration_for_field(field) Deprecation.silence(Blacklight::SearchState) do search_state.has_facet? config, value: facet_value_for_facet_item(item) end end |
#facet_params(field) ⇒ Object
Get the values of the facet set in the blacklight query string
285 286 287 288 289 |
# File 'app/helpers/blacklight/facets_helper_behavior.rb', line 285 def facet_params field config = facet_configuration_for_field(field) search_state.params.dig(:f, config.key) end |
#facet_partial_name(display_facet = nil) ⇒ String
The name of the partial to use to render a facet field. uses the value of the “partial” field if set in the facet configuration otherwise uses “facet_pivot” if this facet is a pivot facet defaults to 'facet_limit'
181 182 183 184 185 186 |
# File 'app/helpers/blacklight/facets_helper_behavior.rb', line 181 def facet_partial_name(display_facet = nil) config = facet_configuration_for_field(display_facet.name) name = config.partial name ||= "facet_pivot" if config.pivot name || "facet_limit" end |
#has_facet_values?(fields = facet_field_names, response = nil) ⇒ Boolean
Check if any of the given fields have values
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/helpers/blacklight/facets_helper_behavior.rb', line 14 def has_facet_values? fields = facet_field_names, response = nil deprecated_method(:has_facet_values?) unless response Deprecation.warn(self, 'Calling has_facet_values? without passing the ' \ 'second argument (response) is deprecated and will be removed in Blacklight ' \ '8.0.0') response = @response end Deprecation.silence(Blacklight::FacetsHelperBehavior) do Deprecation.silence(Blacklight::Facet) do facets_from_request(fields, response).any? { |display_facet| should_render_facet?(display_facet) } end end end |
#path_for_facet(facet_field, item, path_options = {}) ⇒ String
Where should this facet link to?
216 217 218 219 |
# File 'app/helpers/blacklight/facets_helper_behavior.rb', line 216 def path_for_facet(facet_field, item, = {}) facet_config = facet_configuration_for_field(facet_field) facet_item_presenter(facet_config, item, facet_field).href() end |
#render_facet_count(num, options = {}) ⇒ String
Renders a count value for facet limits. Can be over-ridden locally to change style. And can be called by plugins to get consistent display.
244 245 246 247 248 |
# File 'app/helpers/blacklight/facets_helper_behavior.rb', line 244 def render_facet_count(num, = {}) deprecated_method(:render_facet_count) classes = ([:classes] || []) << "facet-count" tag.span(t('blacklight.search.facets.count', number: number_with_delimiter(num)), class: classes) end |
#render_facet_item(facet_field, item) ⇒ Object
Renders a single facet item
131 132 133 134 135 136 137 138 |
# File 'app/helpers/blacklight/facets_helper_behavior.rb', line 131 def render_facet_item(facet_field, item) deprecated_method(:render_facet_item) if facet_in_params?(facet_field, item.value) render_selected_facet_value(facet_field, item) else render_facet_value(facet_field, item) end end |
#render_facet_limit(display_facet, options = {}) ⇒ String
Renders a single section for facet limit with a specified solr field used for faceting. Can be over-ridden for custom display on a per-facet basis.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'app/helpers/blacklight/facets_helper_behavior.rb', line 75 def render_facet_limit(display_facet, = {}) field_config = facet_configuration_for_field(display_facet.name) if field_config.component return unless should_render_field?(field_config, display_facet) component = field_config.component == true ? Blacklight::FacetFieldListComponent : field_config.component return render( component.new( facet_field: facet_field_presenter(field_config, display_facet), layout: (params[:action] == 'facet' ? false : [:layout]) ) ) end Deprecation.warn(Blacklight::FacetsHelperBehavior, 'Calling #render_facet_limit on a non-componentized'\ ' facet is deprecated and will be removed in Blacklight 8') Deprecation.silence(Blacklight::FacetsHelperBehavior) do return unless should_render_facet?(display_facet, field_config) end = .dup Deprecation.silence(Blacklight::FacetsHelperBehavior) do [:partial] ||= facet_partial_name(display_facet) end [:layout] ||= "facet_layout" unless .key?(:layout) [:locals] ||= {} [:locals][:field_name] ||= display_facet.name [:locals][:facet_field] ||= field_config [:locals][:display_facet] ||= display_facet render() end |
#render_facet_limit_list(paginator, facet_field, wrapping_element = :li) ⇒ Object
Renders the list of values removes any elements where render_facet_item returns a nil value. This enables an application to filter undesireable facet items so they don't appear in the UI
117 118 119 120 121 122 123 124 125 |
# File 'app/helpers/blacklight/facets_helper_behavior.rb', line 117 def render_facet_limit_list(paginator, facet_field, wrapping_element = :li) facet_config ||= facet_configuration_for_field(facet_field) collection = paginator.items.map do |item| facet_item_presenter(facet_config, item, facet_field) end render(facet_item_component_class(facet_config).with_collection(collection, wrapping_element: wrapping_element)) end |
#render_facet_partials(fields = nil, options = {}) ⇒ Object
Render a collection of facet fields.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/helpers/blacklight/facets_helper_behavior.rb', line 38 def render_facet_partials fields = nil, = {} deprecated_method(:render_facet_partials) unless fields Deprecation.warn(self.class, 'Calling render_facet_partials without passing the ' \ 'first argument (fields) is deprecated and will be removed in Blacklight ' \ '8.0.0') fields = facet_field_names end response = .delete(:response) unless response Deprecation.warn(self.class, 'Calling render_facet_partials without passing the ' \ 'response keyword is deprecated and will be removed in Blacklight ' \ '8.0.0') response = @response end Deprecation.silence(Blacklight::FacetsHelperBehavior) do Deprecation.silence(Blacklight::Facet) do safe_join(facets_from_request(fields, response).map do |display_facet| render_facet_limit(display_facet, ) end.compact, "\n") end end end |
#render_facet_value(facet_field, item, options = {}) ⇒ String
Standard display of a facet value in a list. Used in both _facets sidebar partial and catalog/facet expanded list. Will output facet value name as a link to add that to your restrictions, with count in parens.
203 204 205 206 207 |
# File 'app/helpers/blacklight/facets_helper_behavior.rb', line 203 def render_facet_value(facet_field, item, = {}) deprecated_method(:render_facet_value) facet_config = facet_configuration_for_field(facet_field) facet_item_component(facet_config, item, facet_field, **).render_facet_value end |
#render_selected_facet_value(facet_field, item) ⇒ Object
Standard display of a SELECTED facet value (e.g. without a link and with a remove button)
229 230 231 232 233 |
# File 'app/helpers/blacklight/facets_helper_behavior.rb', line 229 def render_selected_facet_value(facet_field, item) deprecated_method(:render_selected_facet_value) facet_config = facet_configuration_for_field(facet_field) facet_item_component(facet_config, item, facet_field).render_selected_facet_value end |
#should_collapse_facet?(facet_field) ⇒ Boolean
Determine whether a facet should be rendered as collapsed or not.
- if the facet is 'active', don't collapse
- if the facet is configured to collapse (the default), collapse
- if the facet is configured not to collapse, don't collapse
167 168 169 170 171 |
# File 'app/helpers/blacklight/facets_helper_behavior.rb', line 167 def should_collapse_facet? facet_field Deprecation.silence(Blacklight::FacetsHelperBehavior) do !facet_field_in_params?(facet_field.key) && facet_field.collapse end end |
#should_render_facet?(display_facet, facet_config = nil) ⇒ Boolean
Determine if Blacklight should render the display_facet or not
By default, only render facets with items.
149 150 151 152 153 154 155 |
# File 'app/helpers/blacklight/facets_helper_behavior.rb', line 149 def should_render_facet? display_facet, facet_config = nil return false if display_facet.items.blank? # display when show is nil or true facet_config ||= facet_configuration_for_field(display_facet.name) should_render_field?(facet_config, display_facet) end |