Class: Blacklight::Hierarchy::QfacetValueComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/blacklight/hierarchy/qfacet_value_component.rb

Direct Known Subclasses

SelectedQfacetValueComponent

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field_name:, item:, id: nil, suppress_link: false) ⇒ QfacetValueComponent

Returns a new instance of QfacetValueComponent.



6
7
8
9
10
11
# File 'app/components/blacklight/hierarchy/qfacet_value_component.rb', line 6

def initialize(field_name:, item:, id: nil, suppress_link: false)
  @field_name = field_name
  @item = item
  @id = id
  @suppress_link = suppress_link
end

Instance Attribute Details

#field_nameObject (readonly)

Returns the value of attribute field_name.



13
14
15
# File 'app/components/blacklight/hierarchy/qfacet_value_component.rb', line 13

def field_name
  @field_name
end

#idObject (readonly)

Returns the value of attribute id.



13
14
15
# File 'app/components/blacklight/hierarchy/qfacet_value_component.rb', line 13

def id
  @id
end

#itemObject (readonly)

Returns the value of attribute item.



13
14
15
# File 'app/components/blacklight/hierarchy/qfacet_value_component.rb', line 13

def item
  @item
end

Returns the value of attribute suppress_link.



13
14
15
# File 'app/components/blacklight/hierarchy/qfacet_value_component.rb', line 13

def suppress_link
  @suppress_link
end

Instance Method Details

#facet_configObject



29
30
31
# File 'app/components/blacklight/hierarchy/qfacet_value_component.rb', line 29

def facet_config
  helpers.facet_configuration_for_field(field_name)
end

#facet_item_presenter_classObject



41
42
43
# File 'app/components/blacklight/hierarchy/qfacet_value_component.rb', line 41

def facet_item_presenter_class
  hierarchy_config.dig(field_name_prefix)[2] || Blacklight::FacetItemPresenter
end

#field_name_prefixObject



37
38
39
# File 'app/components/blacklight/hierarchy/qfacet_value_component.rb', line 37

def field_name_prefix
  @field_name_prefix ||= field_name.gsub("_#{field_name.split(/_/).last}", '')
end

#hierarchy_configObject



33
34
35
# File 'app/components/blacklight/hierarchy/qfacet_value_component.rb', line 33

def hierarchy_config
  helpers.blacklight_config.facet_display[:hierarchy]
end

#label_valueObject



15
16
17
18
# File 'app/components/blacklight/hierarchy/qfacet_value_component.rb', line 15

def label_value
  return item.value if facet_item_presenter_class == Blacklight::FacetItemPresenter
  facet_item_presenter_class.new(item.qvalue, facet_config, helpers, field_name).label
end

#path_for_facetObject



20
21
22
# File 'app/components/blacklight/hierarchy/qfacet_value_component.rb', line 20

def path_for_facet
  facet_item_presenter_class.new(item.qvalue, facet_config, helpers, field_name).href
end

#render_facet_countObject



24
25
26
27
# File 'app/components/blacklight/hierarchy/qfacet_value_component.rb', line 24

def render_facet_count
  classes = "facet-count"
  ("span", t('blacklight.search.facets.count', number: number_with_delimiter(item.hits)), class: classes)
end