Skip to content

Commit

Permalink
Add custom pagination information for grouped responses fixes #699
Browse files Browse the repository at this point in the history
  • Loading branch information
mejackreed committed Sep 12, 2019
1 parent 66dd349 commit 1ed0033
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
38 changes: 38 additions & 0 deletions app/helpers/blacklight_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module BlacklightHelper
include Blacklight::BlacklightHelperBehavior
include Blacklight::CatalogHelperBehavior

##
# Override the Blacklight Kaminari Override to better support custom group behavior
# @param [RSolr::Resource] collection (or other Kaminari-compatible objects)
# @return [String]
def page_entries_info(collection, options = {})
# Return to Blacklight implementation unless collection grouping is enabled
return super unless collection.respond_to?(:groups) && render_grouped_response?(collection)
return unless show_pagination? collection

entry_name = t('arclight.entry_name.grouped', count: collection.total_count)

end_num = collection.groups.length
end_num = if collection.offset_value + end_num <= collection.total_count
collection.offset_value + end_num
else
collection.total_count
end

case collection.total_count
when 0
t('arclight.search.pagination_info.no_items_found', entry_name: entry_name).html_safe
when 1
t('arclight.search.pagination_info.single_item_found', entry_name: entry_name).html_safe
else
t('arclight.search.pagination_info.pages', entry_name: entry_name,
current_page: collection.current_page,
num_pages: collection.total_pages,
start_num: number_with_delimiter(collection.offset_value + 1),
end_num: number_with_delimiter(end_num),
total_num: number_with_delimiter(collection.total_count),
count: collection.total_pages).html_safe
end
end
end
12 changes: 12 additions & 0 deletions config/locales/arclight.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ en:
date_range_histogram:
hide: Hide date distribution
show: Show date distribution
entry_name:
grouped:
one: collection
other: collections
hierarchy:
scope_and_contents: Scope and Contents
view_all: View
Expand All @@ -16,6 +20,14 @@ en:
home: Home
repositories: Repositories
search_results: Search results
search:
pagination_info:
no_items_found: 'No %{entry_name} found'
single_item_found: '<strong>1</strong> %{entry_name} found'
pages:
one: '<strong>%{start_num}</strong> - <strong>%{end_num}</strong> of <strong>%{total_num} %{entry_name}</strong>'
other: '<strong>%{start_num}</strong> - <strong>%{end_num}</strong> of <strong>%{total_num} %{entry_name}</strong>'

truncation:
view_less: view less ▼
view_more: view more ▶
Expand Down
11 changes: 11 additions & 0 deletions spec/features/grouped_results_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,15 @@
end
end
end

describe 'custom pagination info' do
it 'displays with 1 collection' do
visit search_catalog_path q: 'alpha', group: 'true'
expect(page).to have_css '.page-entries', text: '1 collection found'
end
it 'displays with many collections' do
visit search_catalog_path q: '*', group: 'true'
expect(page).to have_css '.page-entries', text: '1 - 5 of 5 collections'
end
end
end

0 comments on commit 1ed0033

Please sign in to comment.