Class: Blacklight::SearchContext::ServerItemPaginationComponent
- Inherits:
-
Component
- Object
- ViewComponent::Base
- Component
- Blacklight::SearchContext::ServerItemPaginationComponent
- Defined in:
- app/components/blacklight/search_context/server_item_pagination_component.rb
Instance Method Summary collapse
-
#initialize(search_context:, search_session:, current_document:) ⇒ ServerItemPaginationComponent
constructor
A new instance of ServerItemPaginationComponent.
-
#item_page_entry_info ⇒ String
Displays “showing X of Y items” message.
- #link_to_next_document(next_document = nil, classes: 'next', **link_opts) ⇒ Object
- #link_to_previous_document(previous_document = nil, classes: 'previous', **link_opts) ⇒ Object
- #render? ⇒ Boolean
Methods inherited from Component
reset_compiler!, sidecar_files, upstream_sidecar_files
Constructor Details
#initialize(search_context:, search_session:, current_document:) ⇒ ServerItemPaginationComponent
Returns a new instance of ServerItemPaginationComponent.
8 9 10 11 12 |
# File 'app/components/blacklight/search_context/server_item_pagination_component.rb', line 8 def initialize(search_context:, search_session:, current_document:) @search_context = search_context @search_session = search_session @current_document_id = current_document.id end |
Instance Method Details
#item_page_entry_info ⇒ String
Displays “showing X of Y items” message.
22 23 24 25 26 |
# File 'app/components/blacklight/search_context/server_item_pagination_component.rb', line 22 def item_page_entry_info t('blacklight.search.entry_pagination_info.other', current: number_with_delimiter(count), total: number_with_delimiter(total), count: total).html_safe end |
#link_to_next_document(next_document = nil, classes: 'next', **link_opts) ⇒ Object
36 37 38 39 40 41 42 |
# File 'app/components/blacklight/search_context/server_item_pagination_component.rb', line 36 def link_to_next_document(next_document = nil, classes: 'next', **link_opts) next_document ||= @search_context[:next] link_opts = session_tracking_params(next_document, count + 1, per_page: per_page, search_id: search_id).merge(class: classes, rel: 'next').merge(link_opts) link_to_unless next_document.nil?, raw(t('views.pagination.next')), url_for_document(next_document), link_opts do tag.span raw(t('views.pagination.next')), class: 'next' end end |
#link_to_previous_document(previous_document = nil, classes: 'previous', **link_opts) ⇒ Object
28 29 30 31 32 33 34 |
# File 'app/components/blacklight/search_context/server_item_pagination_component.rb', line 28 def link_to_previous_document(previous_document = nil, classes: 'previous', **link_opts) previous_document ||= @search_context[:prev] link_opts = session_tracking_params(previous_document, count - 1, per_page: per_page, search_id: search_id).merge(class: classes, rel: 'prev').merge(link_opts) link_to_unless previous_document.nil?, raw(t('views.pagination.previous')), url_for_document(previous_document), link_opts do tag.span raw(t('views.pagination.previous')), class: 'previous' end end |
#render? ⇒ Boolean
14 15 16 |
# File 'app/components/blacklight/search_context/server_item_pagination_component.rb', line 14 def render? @search_context.present? && (@search_context[:prev] || @search_context[:next] || total.positive?) && (@search_session['document_id'] == @current_document_id) end |