Class: Blacklight::FacetFieldListComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/blacklight/facet_field_list_component.rb

Constant Summary

Constants inherited from Component

Component::EXCLUDE_VARIABLES

Instance Method Summary collapse

Methods inherited from Component

compiler, config, #inspect

Constructor Details

#initialize(facet_field:, layout: nil) ⇒ FacetFieldListComponent

Returns a new instance of FacetFieldListComponent.



5
6
7
8
# File 'app/components/blacklight/facet_field_list_component.rb', line 5

def initialize(facet_field:, layout: nil)
  @facet_field = facet_field
  @layout = layout == false ? FacetFieldNoLayoutComponent : Blacklight::FacetFieldComponent
end

Instance Method Details

#facet_configObject



50
51
52
# File 'app/components/blacklight/facet_field_list_component.rb', line 50

def facet_config
  @facet_field.facet_field
end

#facet_item_component_class(deprecated_facet_config = nil) ⇒ Object



46
47
48
# File 'app/components/blacklight/facet_field_list_component.rb', line 46

def facet_item_component_class(deprecated_facet_config = nil)
  (deprecated_facet_config || facet_config).item_component
end

#facet_item_presenter(facet_item, deprecated_facet_config = nil, facet_field = nil) ⇒ Object



42
43
44
# File 'app/components/blacklight/facet_field_list_component.rb', line 42

def facet_item_presenter(facet_item, deprecated_facet_config = nil, facet_field = nil)
  (deprecated_facet_config || facet_config).item_presenter.new(facet_item, deprecated_facet_config || facet_config, helpers, facet_field || @facet_field.key)
end

#facet_item_presentersObject



32
33
34
35
36
# File 'app/components/blacklight/facet_field_list_component.rb', line 32

def facet_item_presenters
  @facet_field.paginator.items.map do |item|
    facet_item_presenter(item)
  end
end

#facet_items(wrapping_element: :li, **item_args) ⇒ Object



28
29
30
# File 'app/components/blacklight/facet_field_list_component.rb', line 28

def facet_items(wrapping_element: :li, **item_args)
  facet_item_component_class.with_collection(facet_item_presenters, wrapping_element: wrapping_element, **item_args)
end

#render?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'app/components/blacklight/facet_field_list_component.rb', line 38

def render?
  @facet_field.paginator&.items&.any?
end

#render_facet_limit_list(paginator, facet_field, wrapping_element = :li) ⇒ Object

Deprecated.

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



15
16
17
18
19
20
21
22
23
24
25
# File 'app/components/blacklight/facet_field_list_component.rb', line 15

def render_facet_limit_list(paginator, facet_field, wrapping_element = :li)
  return render(facet_items(wrapping_element: wrapping_element)) if paginator == @facet_field.paginator && facet_field == @facet_field.key

  facet_config ||= helpers.facet_configuration_for_field(facet_field)

  collection = paginator.items.map do |item|
    facet_item_presenter(item, facet_config, facet_field)
  end

  render(facet_item_component_class(facet_config).with_collection(collection, wrapping_element: wrapping_element))
end