Skip to content
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

allow multiple browse windows to be open at the same time #3189

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions app/controllers/spotlight/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ def show

authenticate_user! && authorize!(:curate, current_exhibit) if @document.private? current_exhibit

session[@document.id] ||= {}
@previous_page = request.referer

add_document_breadcrumbs(@document)
end

Expand Down Expand Up @@ -231,11 +234,12 @@ def add_breadcrumb_with_search_params
add_breadcrumb(t(:'spotlight.catalog.breadcrumb.index'), spotlight.search_exhibit_catalog_path(params.to_unsafe_h), current: action_name == 'index')
end

# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
def add_document_breadcrumbs(document)
if current_browse_category
add_breadcrumb(current_browse_category.exhibit.main_navigations.browse.label_or_default, exhibit_browse_index_path(current_browse_category.exhibit))
add_breadcrumb(current_browse_category.title, exhibit_browse_path(current_browse_category.exhibit, current_browse_category))
if current_browse_category && @previous_page&.include?('browse')
browse_breadcrumbs = breadcrumbs_from_session(document) || breadcrumbs_from_browse(document)
add_breadcrumb(browse_breadcrumbs[:browse_label], browse_breadcrumbs[:browse_link])
add_breadcrumb(browse_breadcrumbs[:category_label], browse_breadcrumbs[:category_link])
elsif current_page_context&.title&.present? && !current_page_context.is_a?(Spotlight::HomePage)
add_breadcrumb(current_page_context.title, [current_page_context.exhibit, current_page_context])
elsif current_search_session && !current_page_context&.is_a?(Spotlight::HomePage)
Expand All @@ -244,7 +248,32 @@ def add_document_breadcrumbs(document)

add_breadcrumb(view_context.document_presenter(document).heading, polymorphic_path([current_exhibit, document]))
end
# rubocop:enable Metrics/AbcSize
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity

def breadcrumbs_from_session(document)
return unless session[document.id]['search_id'].present? && session[document.id]['search_id'] != current_search_session&.id

searches_from_history.find(session[document.id]['search_id']).query_params
end

def breadcrumbs_from_browse(document)
browse_breadcrumbs = { browse_label: current_browse_category.exhibit.main_navigations.browse.label_or_default,
browse_link: exhibit_browse_index_path(current_browse_category.exhibit),
category_label: current_browse_category.title,
category_link: exhibit_browse_path(current_browse_category.exhibit, current_browse_category) }
update_session_breadcrumbs(browse_breadcrumbs, document.id)
browse_breadcrumbs
end

# This adds breadcrumbs to the session information
# Allows for multiple browse tabs to be open (issue #3242)
def update_session_breadcrumbs(browse_breadcrumbs, doc_id)
return if current_search_session&.query_params.blank?

current_search_session.query_params = current_search_session.query_params.merge(browse_breadcrumbs)
current_search_session.save
session[doc_id]['search_id'] = current_search_session.id
end

def additional_export_formats(document, format)
super
Expand Down
1 change: 1 addition & 0 deletions spec/controllers/spotlight/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

it 'shows the item with breadcrumbs to the browse page' do
allow(controller).to receive_messages(current_browse_category: search)
controller.request.headers.merge({ HTTP_REFERER: '/spotlight/exhibit-title-1/browse' })

expect(controller).to receive(:add_breadcrumb).with('Home', exhibit_path(exhibit))
expect(controller).to receive(:add_breadcrumb).with('Browse', exhibit_browse_index_path(exhibit))
Expand Down