-
Notifications
You must be signed in to change notification settings - Fork 256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adding option for single page count #3315
base: main
Are you sure you want to change the base?
Changes from 3 commits
62d7716
450d68f
83bc05f
b0cd865
003bf03
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<div class="search-context page-links"> | ||
<%= link_to_previous_document %> | | ||
<%= link_to_previous_document %> <%= display_separator %> | ||
|
||
<%= item_page_entry_info %> | | ||
<%= item_page_entry_info %> <%= display_separator %> | ||
|
||
<%= link_to_next_document %> | ||
</div> |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -12,35 +12,52 @@ def initialize(search_context:, search_session:, current_document:) | |||||||||
end | ||||||||||
|
||||||||||
def render? | ||||||||||
@search_context.present? && (@search_context[:prev] || @search_context[:next]) && (@search_session['document_id'] == @current_document_id) | ||||||||||
return false unless @search_session['document_id'] == @current_document_id | ||||||||||
|
||||||||||
return true if total == 1 | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe we need to check for |
||||||||||
|
||||||||||
@search_context.present? && (@search_context[:prev] || @search_context[:next]) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this effectively the same as:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure, because maybe you can have a search_context but not have a :prev or :next? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right – my guess is that case (you have a context, but no prev or next) is the same thing as having a single result. But just a guess! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Separately I have to remove the "|" separating the different sections, so that will be another commit. |
||||||||||
end | ||||||||||
|
||||||||||
def display_separator | ||||||||||
jcoyne marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
'|' unless total == 1 | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would make this display separator a translation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have tried to do that in the latest commit. |
||||||||||
end | ||||||||||
|
||||||||||
## | ||||||||||
# Displays "showing X of Y items" message. | ||||||||||
# | ||||||||||
# @return [String] | ||||||||||
def item_page_entry_info | ||||||||||
t('blacklight.search.entry_pagination_info.other', current: number_with_delimiter(count), | ||||||||||
t('blacklight.search.entry_pagination_info.other', current: current_count, | ||||||||||
total: number_with_delimiter(total), | ||||||||||
count: total).html_safe | ||||||||||
end | ||||||||||
|
||||||||||
def link_to_previous_document(previous_document = nil, classes: 'previous', **link_opts) | ||||||||||
return if total == 1 | ||||||||||
|
||||||||||
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 | ||||||||||
|
||||||||||
def link_to_next_document(next_document = nil, classes: 'next', **link_opts) | ||||||||||
return if total == 1 | ||||||||||
|
||||||||||
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 | ||||||||||
|
||||||||||
def current_count | ||||||||||
total == 1 ? total : number_with_delimiter(count) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need a conditional here?
Suggested change
|
||||||||||
end | ||||||||||
|
||||||||||
private | ||||||||||
|
||||||||||
def count | ||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,18 @@ | |
end | ||
end | ||
|
||
context 'when there is exactly one search result with no next or previous document' do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if someone goes directly to a show page without any session history. Will they still see this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After the most recent changes, I went directly to an item page url in a separate browser and that did not show the "1 of 1" content. |
||
let(:search_context) { {} } | ||
let(:search_session) { { 'document_id' => current_document_id, 'total' => '1' } } | ||
|
||
it "renders single page count" do | ||
expect(render.to_html).to include '<strong>1</strong> of <strong>1</strong>' | ||
expect(render.to_html).not_to include '|' | ||
expect(render.css('span.previous').to_html).to be_blank | ||
expect(render.css('span.next').to_html).to be_blank | ||
end | ||
end | ||
|
||
context 'when there is next and previous' do | ||
let(:search_context) { { next: next_doc, prev: prev_doc } } | ||
let(:prev_doc) { SolrDocument.new(id: '777') } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we put the conditional for
total == 1
here, then we can avoid checking it several times in the component class. I think that'll make the code simpler to read.