Module: Blacklight::UrlHelperBehavior
- Extended by:
- Deprecation
- Included in:
- BlacklightHelperBehavior
- Defined in:
- app/helpers/blacklight/url_helper_behavior.rb
Overview
URL helper methods
Instance Method Summary collapse
- #add_group_facet_params_and_redirect(group) ⇒ Hash deprecated Deprecated.
- #bookmarks_export_url(format, params = {}) ⇒ Object deprecated Deprecated.
- #controller_tracking_method ⇒ Object
-
#link_back_to_catalog(opts = { label: nil }) ⇒ Object
Create a link back to the index screen, keeping the user’s facet, query and paging choices intact by using session.
-
#link_to_document(doc, field_or_opts = nil, opts = { counter: nil }) ⇒ Object
Uses the catalog_path route to create a link to the show page for an item.
- #link_to_next_document(next_document, classes: 'next', **addl_link_opts) ⇒ Object deprecated Deprecated.
- #link_to_previous_document(previous_document, classes: 'previous', **addl_link_opts) ⇒ Object deprecated Deprecated.
-
#link_to_previous_search(params) ⇒ Object
Search History and Saved Searches display.
- #link_to_query(query) ⇒ Object deprecated Deprecated.
-
#session_tracking_path(document, params = {}) ⇒ Object
Get the URL for tracking search sessions across pages using polymorphic routing.
- #start_over_path(query_params = params) ⇒ Object deprecated Deprecated.
- #url_for_document(doc, options = {}) ⇒ Object deprecated Deprecated.
Instance Method Details
#add_group_facet_params_and_redirect(group) ⇒ Hash
Get url parameters to a search within a grouped result set
181 182 183 |
# File 'app/helpers/blacklight/url_helper_behavior.rb', line 181 def add_group_facet_params_and_redirect group search_state.add_facet_params_and_redirect(group.field, group.key) end |
#bookmarks_export_url(format, params = {}) ⇒ Object
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.
191 192 193 |
# File 'app/helpers/blacklight/url_helper_behavior.rb', line 191 def bookmarks_export_url(format, params = {}) bookmarks_url(params.merge(format: format, encrypted_user_id: encrypt_user_id(current_or_guest_user.id))) end |
#controller_tracking_method ⇒ Object
107 108 109 |
# File 'app/helpers/blacklight/url_helper_behavior.rb', line 107 def controller_tracking_method "track_#{controller_name}_path" end |
#link_back_to_catalog(opts = { label: nil }) ⇒ Object
Create a link back to the index screen, keeping the user’s facet, query and paging choices intact by using session.
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'app/helpers/blacklight/url_helper_behavior.rb', line 141 def link_back_to_catalog(opts = { label: nil }) scope = opts.delete(:route_set) || self query_params = search_state.reset(current_search_session.try(:query_params)).to_hash if search_session['counter'] per_page = (search_session['per_page'] || blacklight_config.default_per_page).to_i counter = search_session['counter'].to_i query_params[:per_page] = per_page unless search_session['per_page'].to_i == blacklight_config.default_per_page query_params[:page] = ((counter - 1) / per_page) + 1 end link_url = if query_params.empty? search_action_path(only_path: true) else scope.url_for(query_params) end label = opts.delete(:label) if link_url =~ /bookmarks/ label ||= t('blacklight.back_to_bookmarks') end label ||= t('blacklight.back_to_search') link_to label, link_url, opts end |
#link_to_document(doc, field_or_opts = nil, opts = { counter: nil }) ⇒ Object
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
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/helpers/blacklight/url_helper_behavior.rb', line 25 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 end |
#link_to_next_document(next_document, classes: 'next', **addl_link_opts) ⇒ Object
Link to the next document in the current search context
66 67 68 69 70 71 |
# File 'app/helpers/blacklight/url_helper_behavior.rb', line 66 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 |
#link_to_previous_document(previous_document, classes: 'previous', **addl_link_opts) ⇒ Object
Link to the previous document in the current search context
55 56 57 58 59 60 |
# File 'app/helpers/blacklight/url_helper_behavior.rb', line 55 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 |
#link_to_previous_search(params) ⇒ Object
Search History and Saved Searches display
170 171 172 173 174 |
# File 'app/helpers/blacklight/url_helper_behavior.rb', line 170 def link_to_previous_search(params) Deprecation.silence(Blacklight::SearchHistoryConstraintsHelperBehavior) do link_to(render_search_to_s(params), search_action_path(params)) end end |
#link_to_query(query) ⇒ Object
create link to query (e.g. spelling suggestion)
117 118 119 120 121 |
# File 'app/helpers/blacklight/url_helper_behavior.rb', line 117 def link_to_query(query) p = search_state.to_h.except(:page, :action) p[:q] = query link_to(query, search_action_path(p)) end |
#session_tracking_path(document, params = {}) ⇒ Object
Get the URL for tracking search sessions across pages using polymorphic routing
96 97 98 99 100 101 102 103 104 105 |
# File 'app/helpers/blacklight/url_helper_behavior.rb', line 96 def session_tracking_path document, params = {} return if document.nil? || !blacklight_config&.track_search_session 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`?" end |
#start_over_path(query_params = params) ⇒ Object
Get the path to the search action with any parameters (e.g. view type) that should be persisted across search sessions.
128 129 130 131 132 133 134 |
# File 'app/helpers/blacklight/url_helper_behavior.rb', line 128 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 |
#url_for_document(doc, options = {}) ⇒ Object
8 9 10 |
# File 'app/helpers/blacklight/url_helper_behavior.rb', line 8 def url_for_document(doc, = {}) search_state.url_for_document(doc, ) end |