Class: Arclight::DocumentCollectionHierarchyComponent

Inherits:
SearchResultComponent
  • Object
show all
Defined in:
app/components/arclight/document_collection_hierarchy_component.rb

Overview

Display a single document in the collection hierarchy

Instance Attribute Summary collapse

Attributes inherited from SearchResultComponent

#document

Instance Method Summary collapse

Methods inherited from SearchResultComponent

#compact?, #icon

Constructor Details

#initialize(document: nil, nest_path: nil, blacklight_config: nil, **kwargs) ⇒ DocumentCollectionHierarchyComponent

Returns a new instance of DocumentCollectionHierarchyComponent.

Parameters:

  • document (Blacklight::DocumentPresenter) (defaults to: nil)
  • nest_path (String) (defaults to: nil)

    determines which element to highlight



8
9
10
11
12
# File 'app/components/arclight/document_collection_hierarchy_component.rb', line 8

def initialize(document: nil, nest_path: nil, blacklight_config: nil, **kwargs)
  super(document: document, **kwargs)
  @nest_path = nest_path
  @blacklight_config = blacklight_config
end

Instance Attribute Details

#blacklight_configObject (readonly)

Returns the value of attribute blacklight_config.



14
15
16
# File 'app/components/arclight/document_collection_hierarchy_component.rb', line 14

def blacklight_config
  @blacklight_config
end

Instance Method Details

#classesObject



16
17
18
# File 'app/components/arclight/document_collection_hierarchy_component.rb', line 16

def classes
  super - ['row']
end

#show_expanded?Boolean

we want to eager-load this document’s children if we’re in the target document’s component hierarchy

Returns:

  • (Boolean)


22
23
24
# File 'app/components/arclight/document_collection_hierarchy_component.rb', line 22

def show_expanded?
  within_original_tree?
end

#target_indexString

Solr nest paths are constructed using the path name and an index, e.g. ‘/components#5/components#3`.

Returns:

  • (String)

    the targeted index for this level of the hierarchy



30
31
32
33
34
35
36
37
38
# File 'app/components/arclight/document_collection_hierarchy_component.rb', line 30

def target_index
  return -1 unless within_original_tree?

  remaining_path = nest_path.sub("#{@document.nest_path}/", '')
  current_component, _rest = remaining_path.split('/', 2)
  _name, index = current_component.split('#', 2)

  index&.to_i
end