Class: Blacklight::Search::PerPageComponent
- Inherits:
-
Component
- Object
- ViewComponent::Base
- Component
- Blacklight::Search::PerPageComponent
- Defined in:
- app/components/blacklight/search/per_page_component.rb
Constant Summary
Constants inherited from Component
Instance Method Summary collapse
- #current_per_page ⇒ Integer
- #dropdown ⇒ Object
-
#dropdown_class ⇒ Object
You may override this method in a subclass if you want to use a different dropdown component.
-
#initialize(blacklight_config:, response:, search_state:) ⇒ PerPageComponent
constructor
A new instance of PerPageComponent.
-
#per_page_options_for_select ⇒ Object
The available options for results per page, in the style of #options_for_select.
- #render? ⇒ Boolean
Methods inherited from Component
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_page ⇒ 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 |
#dropdown ⇒ Object
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: , id: 'per_page-dropdown', search_state: @search_state, selected: current_per_page, interpolation: :count )) end |
#dropdown_class ⇒ Object
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_select ⇒ Object
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 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
12 13 14 |
# File 'app/components/blacklight/search/per_page_component.rb', line 12 def render? helpers.show_sort_and_per_page? end |