-
Notifications
You must be signed in to change notification settings - Fork 257
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?
Conversation
return true if total == 1 | ||
|
||
@search_context.present? && (@search_context[:prev] || @search_context[:next]) |
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.
is this effectively the same as:
return true if total == 1 | |
@search_context.present? && (@search_context[:prev] || @search_context[:next]) | |
@search_context.present? |
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.
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 comment
The 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 comment
The 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 | ||
'|' unless total == 1 |
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.
I would make this display separator a translation.
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.
I have tried to do that in the latest commit.
@@ -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 comment
The 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 comment
The 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.
For anyone else who is interested in the history, this conditional originated in the initial git commit 15 years aog: cfc4743#diff-c732a210586cc78a766262d89f052850316eef0ddeb8a1fc63020dff9a77a85bR1 However it didn't have any pagination at that time. @cbeer added pagination in d619178 and it did support "1 of 1" |
@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 comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we need to check for @search_context
here. Otherwise it will display on pages with no search context.
Thanks for the comments @jcoyne. I should be able to look at this today/tomorrow. |
@jcoyne I believe I addressed your comments. Thanks! |
@search_context.present? && (@search_context[:prev] || @search_context[:next]) && (@search_session['document_id'] == @current_document_id) | ||
return false unless @search_context.present? && @search_session['document_id'] == @current_document_id | ||
|
||
total == 1 || (@search_context[:prev] || @search_context[:next]) |
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.
total == 1 || (@search_context[:prev] || @search_context[:next]) | |
total == 1 || @search_context[:prev] || @search_context[:next] |
app/components/blacklight/search_context/server_item_pagination_component.rb
Show resolved
Hide resolved
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need a conditional here?
total == 1 ? total : number_with_delimiter(count) | |
number_with_delimiter(count) |
@@ -20,7 +20,7 @@ def render? | |||
end | |||
|
|||
def display_separator | |||
'|' unless total == 1 | |||
t('views.pagination.separator') unless total == 1 |
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.
Do we really want to configure the delimiter separately for each language that we want to support? This seems to me like something better suited for Blacklight::Config rather than an i18n.
@@ -1,7 +1,7 @@ | |||
<div class="search-context page-links"> | |||
<%= link_to_previous_document %> | | |||
<%= link_to_previous_document %> <%= display_separator %> |
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.
What this pull request does:
Adds a check to see if there is only one search result, and shows "1 of 1" in the view without showing previous or next links.
Adds a test for this particular case.
Closes #3314 .
Addresses a ticket in EarthWorks: sul-dlss/earthworks#1367