Skip to content

Commit

Permalink
Merge pull request #2297 from projectblacklight/search-context-idea
Browse files Browse the repository at this point in the history
Only show search context controls if the current context matches the …
  • Loading branch information
mejackreed committed Sep 30, 2020
2 parents 9865d4d + 2ca1c96 commit 9701904
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,15 @@ Metrics/ClassLength:
Metrics/CyclomaticComplexity:
Max: 14

# Offense count: 60
# Offense count: 61
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods.
Metrics/MethodLength:
Max: 30

# Offense count: 8
# Configuration parameters: CountComments, CountAsOne.
Metrics/ModuleLength:
Max: 212
Max: 213

# Offense count: 3
# Configuration parameters: CountKeywordArgs.
Expand Down
1 change: 1 addition & 0 deletions app/controllers/concerns/blacklight/catalog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def track
search_session['counter'] = params[:counter]
search_session['id'] = params[:search_id]
search_session['per_page'] = params[:per_page]
search_session['document_id'] = params[:document_id]

if params[:redirect] && (params[:redirect].starts_with?('/') || params[:redirect] =~ URI::DEFAULT_PARSER.make_regexp)
uri = URI.parse(params[:redirect])
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/blacklight/url_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def link_to_next_document(next_document)
# session_tracking_params(SolrDocument.new(id: 123), 7)
# => { data: { :'context-href' => '/catalog/123/track?counter=7&search_id=999' } }
def session_tracking_params document, counter
path = session_tracking_path(document, per_page: params.fetch(:per_page, search_session['per_page']), counter: counter, search_id: current_search_session.try(:id))
path = session_tracking_path(document, per_page: params.fetch(:per_page, search_session['per_page']), counter: counter, search_id: current_search_session.try(:id), document_id: document&.id)

if path.nil?
return {}
Expand Down
2 changes: 1 addition & 1 deletion app/views/catalog/_show_main_content.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= render 'previous_next_doc' if @search_context %>
<%= render 'previous_next_doc' if @search_context && search_session['document_id'] == @document.id %>
<% @page_title = t('blacklight.search.show.title', :document_title => document_show_html_title, :application_name => application_name).html_safe %>
<% content_for(:head) { render_link_rel_alternates } %>
Expand Down
5 changes: 5 additions & 0 deletions spec/controllers/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@
expect(session[:search]['per_page']).to eq "15"
end

it "records the document id being viewed" do
put :track, params: { id: doc_id, counter: 3, document_id: 1234 }
expect(session[:search]['document_id']).to eq "1234"
end

it "redirects to show action for doc id" do
put :track, params: { id: doc_id, counter: 3 }
assert_redirected_to(solr_document_path(doc_id))
Expand Down
14 changes: 12 additions & 2 deletions spec/features/search_context_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
click_on 'Pluvial nectar of blessings'
expect(page).to have_content "« Previous | 10 of 30 | Next »"
prev = page.find(".pagination-search-widgets .previous")
expect(prev['data-context-href']).to eq "/catalog/2003546302/track?counter=9&search_id=#{search_id}"
expect(prev['data-context-href']).to eq "/catalog/2003546302/track?counter=9&document_id=2003546302&search_id=#{search_id}"

click_on "« Previous"

prev = page.find(".pagination-search-widgets .previous")
expect(prev['data-context-href']).to eq "/catalog/2004310986/track?counter=8&search_id=#{search_id}"
expect(prev['data-context-href']).to eq "/catalog/2004310986/track?counter=8&document_id=2004310986&search_id=#{search_id}"
end

it "redirects context urls to the original url" do
Expand All @@ -31,6 +31,16 @@
end
end

it "does not display stale previous and next links for direct item views" do
search_for ''
click_on 'Pluvial nectar of blessings'

# Go to the number 9 result separately
visit '/catalog/2003546302'
expect(page).not_to have_selector '.page-links'
expect(page).not_to have_content "« Previous | 10 of 30 | Next »"
end

context "navigating between search results using context pagination" do
it "updates the back to search link with the current search pagination context" do
search_for ''
Expand Down

0 comments on commit 9701904

Please sign in to comment.