Class: Blacklight::Hierarchy::FacetFieldComponent

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field_name:, tree:, key:) ⇒ FacetFieldComponent

Returns a new instance of FacetFieldComponent.



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

def initialize(field_name:, tree:, key:)
  @field_name = field_name
  @tree = tree
  @key = key
  @id = SecureRandom.uuid
end

Instance Attribute Details

#field_nameObject (readonly)

Returns the value of attribute field_name.



13
14
15
# File 'app/components/blacklight/hierarchy/facet_field_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/facet_field_component.rb', line 13

def id
  @id
end

#keyObject (readonly)

Returns the value of attribute key.



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

def key
  @key
end

#treeObject (readonly)

Returns the value of attribute tree.



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

def tree
  @tree
end

Instance Method Details

#controller_nameObject



23
24
25
# File 'app/components/blacklight/hierarchy/facet_field_component.rb', line 23

def controller_name
  subset.empty? ? '' : 'b-h-collapsible'
end

#itemObject



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

def item
  tree[:_]
end

#li_classObject



19
20
21
# File 'app/components/blacklight/hierarchy/facet_field_component.rb', line 19

def li_class
  subset.empty? ? 'h-leaf' : 'h-node'
end

#qfacet_selected?Boolean

Returns:

  • (Boolean)


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

def qfacet_selected?
  config = helpers.facet_configuration_for_field(field_name)
  helpers.search_state.filter(config).include?(item.qvalue)
end

#subsetObject



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

def subset
  @subset ||= tree.reject { |k, _v| !k.is_a?(String) }
end