Class: Blacklight::SearchContext::ServerItemPaginationComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/blacklight/search_context/server_item_pagination_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(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_infoString

Displays “showing X of Y items” message.

Returns:

  • (String)


22
23
24
25
26
# File 'app/components/blacklight/search_context/server_item_pagination_component.rb', line 22

def 
  t('blacklight.search.entry_pagination_info.other', current: number_with_delimiter(count),
                                                     total: number_with_delimiter(total),
                                                     count: total).html_safe
end


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


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

Returns:

  • (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]) && (@search_session['document_id'] == @current_document_id)
end