Class: Arclight::SearchBarComponent

Inherits:
Blacklight::SearchBarComponent
  • Object
show all
Defined in:
app/components/arclight/search_bar_component.rb

Overview

Override Blacklight’s SearchBarComponent to add a dropdown for choosing the context of the search (within “this collection” or “all collections”). If a collection has not been chosen, it displays a dropdown with only “all collections” as the only selectable option.

Instance Method Summary collapse

Constructor Details

#initialize(**kwargs) ⇒ SearchBarComponent

Returns a new instance of SearchBarComponent.



9
10
11
12
13
# File 'app/components/arclight/search_bar_component.rb', line 9

def initialize(**kwargs)
  super

  @kwargs = kwargs
end

Instance Method Details

#collection_nameObject



27
28
29
30
# File 'app/components/arclight/search_bar_component.rb', line 27

def collection_name
  @collection_name ||= Array(@params.dig(:f, :collection)).reject(&:empty?).first ||
                       helpers.current_context_document&.collection_name
end

#within_collection_optionsObject



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

def within_collection_options
  value = collection_name || 'none-selected'
  options_for_select(
    [
      [t('arclight.within_collection_dropdown.all_collections'), ''],
      [t('arclight.within_collection_dropdown.this_collection'), value]
    ],
    selected: collection_name,
    disabled: 'none-selected'
  )
end