app/helpers/blacklight/url_helper_behavior.rb in blacklight-7.40.0 vs app/helpers/blacklight/url_helper_behavior.rb in blacklight-8.0.0.beta1
- old
+ new
@@ -1,97 +1,55 @@
# frozen_string_literal: true
+
##
# URL helper methods
module Blacklight::UrlHelperBehavior
- extend Deprecation
-
- # @deprecated
- def url_for_document(doc, options = {})
- search_state.url_for_document(doc, options)
- end
- deprecation_deprecate url_for_document: 'Use SearchState#url_for_document directly'
-
# Uses the catalog_path route to create a link to the show page for an item.
# catalog_path accepts a hash. The solr query params are stored in the session,
# so we only need the +counter+ param here. We also need to know if we are viewing to document as part of search results.
# TODO: move this to the IndexPresenter
# @param doc [SolrDocument] the document
# @param field_or_opts [Hash, String] either a string to render as the link text or options
# @param opts [Hash] the options to create the link with
# @option opts [Number] :counter (nil) the count to set in the session (for paging through a query result)
# @example Passing in an image
- # link_to_document(doc, '<img src="thumbnail.png">', counter: 3) #=> "<a href=\"catalog/123\" data-tracker-href=\"/catalog/123/track?counter=3&search_id=999\"><img src="thumbnail.png"></a>
+ # link_to_document(doc, '<img src="thumbnail.png">', counter: 3) #=> "<a href=\"catalog/123\" data-context-href=\"/catalog/123/track?counter=3&search_id=999\"><img src="thumbnail.png"></a>
# @example With the default document link field
- # link_to_document(doc, counter: 3) #=> "<a href=\"catalog/123\" data-tracker-href=\"/catalog/123/track?counter=3&search_id=999\">My Title</a>
+ # link_to_document(doc, counter: 3) #=> "<a href=\"catalog/123\" data-context-href=\"/catalog/123/track?counter=3&search_id=999\">My Title</a>
def link_to_document(doc, field_or_opts = nil, opts = { counter: nil })
label = case field_or_opts
when NilClass
document_presenter(doc).heading
when Hash
opts = field_or_opts
document_presenter(doc).heading
- when Proc, Symbol
- Deprecation.warn(self, "passing a #{field_or_opts.class} to link_to_document is deprecated and will be removed in Blacklight 8")
- Deprecation.silence(Blacklight::IndexPresenter) do
- index_presenter(doc).label field_or_opts, opts
- end
else # String
field_or_opts
end
- Deprecation.silence(Blacklight::UrlHelperBehavior) do
- link_to label, url_for_document(doc), document_link_params(doc, opts)
- end
+ link_to label, search_state.url_for_document(doc), document_link_params(doc, opts)
end
# @private
def document_link_params(doc, opts)
session_tracking_params(doc, opts[:counter]).deep_merge(opts.except(:label, :counter))
end
private :document_link_params
##
- # Link to the previous document in the current search context
- # @deprecated
- def link_to_previous_document(previous_document, classes: 'previous', **addl_link_opts)
- link_opts = session_tracking_params(previous_document, search_session['counter'].to_i - 1).merge(class: classes, rel: 'prev').merge(addl_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
- deprecation_deprecate link_to_previous_document: 'Moving to Blacklight::SearchContextComponent'
-
- ##
- # Link to the next document in the current search context
- # @deprecated
- def link_to_next_document(next_document, classes: 'next', **addl_link_opts)
- link_opts = session_tracking_params(next_document, search_session['counter'].to_i + 1).merge(class: classes, rel: 'next').merge(addl_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
- deprecation_deprecate link_to_previous_document: 'Moving to Blacklight::SearchContextComponent'
-
- ##
# Attributes for a link that gives a URL we can use to track clicks for the current search session
- # We disable turbo prefetch (InstantClick), because since we replace the link with a form, it's just wasted.
- # @private
# @param [SolrDocument] document
# @param [Integer] counter
# @example
# 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), document_id: document&.id)
+ def session_tracking_params document, counter, per_page: search_session['per_page'], search_id: current_search_session&.id
+ path = session_tracking_path(document, per_page: params.fetch(:per_page, per_page), counter: counter, search_id: search_id, document_id: document&.id)
+ return {} if path.nil?
- if path.nil?
- return {}
- end
-
- { data: { context_href: path, turbo_prefetch: false } }
+ { data: { context_href: path } }
end
- private :session_tracking_params
##
# Get the URL for tracking search sessions across pages using polymorphic routing
def session_tracking_path document, params = {}
return if document.nil? || !blacklight_config&.track_search_session
@@ -99,43 +57,21 @@
if main_app.respond_to?(controller_tracking_method)
return main_app.public_send(controller_tracking_method, params.merge(id: document))
end
raise "Unable to find #{controller_tracking_method} route helper. " \
- "Did you add `concerns :searchable` routing mixin to your `config/routes.rb`?"
+ "Did you add `concerns :searchable` routing mixin to your `config/routes.rb`?"
end
def controller_tracking_method
"track_#{controller_name}_path"
end
#
# link based helpers ->
#
- # create link to query (e.g. spelling suggestion)
- # @deprecated
- def link_to_query(query)
- p = search_state.to_h.except(:page, :action)
- p[:q] = query
- link_to(query, search_action_path(p))
- end
- deprecation_deprecate link_to_query: 'Removed without replacement'
-
- ##
- # Get the path to the search action with any parameters (e.g. view type)
- # that should be persisted across search sessions.
- # @deprecated
- def start_over_path query_params = params
- h = {}
- current_index_view_type = document_index_view_type(query_params)
- h[:view] = current_index_view_type unless current_index_view_type == default_document_index_view_type
-
- search_action_path(h)
- end
- deprecation_deprecate start_over_path: 'Removed without replacement'
-
# Create a link back to the index screen, keeping the user's facet, query and paging choices intact by using session.
# @example
# link_back_to_catalog(label: 'Back to Search')
# link_back_to_catalog(label: 'Back to Search', route_set: my_engine)
def link_back_to_catalog(opts = { label: nil })
@@ -164,32 +100,11 @@
label ||= t('blacklight.back_to_search')
link_to label, link_url, opts
end
- # Search History and Saved Searches display
+ # Use in e.g. the search history display, where we want something more like text instead of the normal constraints
def link_to_previous_search(params)
- Deprecation.silence(Blacklight::SearchHistoryConstraintsHelperBehavior) do
- link_to(render_search_to_s(params), search_action_path(params))
- end
+ search_state = controller.search_state_class.new(params, blacklight_config, self)
+ link_to(render(Blacklight::ConstraintsComponent.for_search_history(search_state: search_state)), search_action_path(params))
end
-
- # Get url parameters to a search within a grouped result set
- #
- # @deprecated
- # @param [Blacklight::Solr::Response::Group] group
- # @return [Hash]
- def add_group_facet_params_and_redirect group
- search_state.add_facet_params_and_redirect(group.field, group.key)
- end
- deprecation_deprecate add_group_facet_params_and_redirect: 'Removed without replacement'
-
- # A URL to refworks export, with an embedded callback URL to this app.
- # the callback URL is to bookmarks#export, which delivers a list of
- # user's bookmarks in 'refworks marc txt' format -- we tell refworks
- # to expect that format.
- # @deprecated
- def bookmarks_export_url(format, params = {})
- bookmarks_url(params.merge(format: format, encrypted_user_id: encrypt_user_id(current_or_guest_user.id)))
- end
- deprecation_deprecate bookmarks_export_url: 'Removed without replacement'
end