Class: Blacklight::Search::PerPageComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/blacklight/search/per_page_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(blacklight_config:, response:, search_state:) ⇒ PerPageComponent

Returns a new instance of PerPageComponent.



6
7
8
9
10
# File 'app/components/blacklight/search/per_page_component.rb', line 6

def initialize(blacklight_config:, response:, search_state:)
  @blacklight_config = blacklight_config
  @response = response
  @search_state = search_state
end

Instance Method Details

#current_per_pageInteger

Returns:

  • (Integer)


34
35
36
37
# File 'app/components/blacklight/search/per_page_component.rb', line 34

def current_per_page
  (@response.rows if @response && @response.rows > 0) || # rubocop:disable Style/NumericPredicate
    params.fetch(:per_page, @blacklight_config.default_per_page).to_i
end


21
22
23
24
25
26
27
28
29
30
# File 'app/components/blacklight/search/per_page_component.rb', line 21

def dropdown
  render(dropdown_class.new(
           param: :per_page,
           choices: per_page_options_for_select,
           id: 'per_page-dropdown',
           search_state: @search_state,
           selected: current_per_page,
           interpolation: :count
         ))
end

You may override this method in a subclass if you want to use a different dropdown component



17
18
19
# File 'app/components/blacklight/search/per_page_component.rb', line 17

def dropdown_class
  @blacklight_config.view_config(:show).dropdown_component
end

#per_page_options_for_selectObject

The available options for results per page, in the style of #options_for_select



41
42
43
44
45
46
47
# File 'app/components/blacklight/search/per_page_component.rb', line 41

def per_page_options_for_select
  return [] if @blacklight_config.per_page.blank?

  @blacklight_config.per_page.map do |count|
    [t(:'blacklight.search.per_page.label', count: count).html_safe, count]
  end
end

#render?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'app/components/blacklight/search/per_page_component.rb', line 12

def render?
  helpers.show_sort_and_per_page?
end