Module: Blacklight::UrlHelperBehavior
- Includes:
- DeprecatedUrlHelperBehavior
- Included in:
- BlacklightUrlHelper
- 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
Get url parameters to a search within a grouped result set.
-
#bookmarks_export_url(format, params = {}) ⇒ Object
A URL to refworks export, with an embedded callback URL to this app.
- #controller_tracking_method ⇒ Object
- #document_link_params(doc, opts) ⇒ Object protected
-
#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
link_to_document(doc, 'VIEW', :counter => 3) Use the catalog_path RESTful route to create a link to the show page for a specific item.
-
#link_to_next_document(next_document) ⇒ Object
Link to the next document in the current search context.
-
#link_to_previous_document(previous_document) ⇒ Object
Link to the previous document in the current search context.
-
#link_to_previous_search(params) ⇒ Object
Search History and Saved Searches display.
-
#link_to_query(query) ⇒ Object
create link to query (e.g. spelling suggestion).
-
#session_tracking_params(document, counter) ⇒ Object
protected
Attributes for a link that gives a URL we can use to track clicks for the current search session.
-
#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
Get the path to the search action with any parameters (e.g. view type) that should be persisted across search sessions.
-
#url_for_document(doc, options = {}) ⇒ Object
Extension point for downstream applications to provide more interesting routing to documents.
Methods included from DeprecatedUrlHelperBehavior
#add_facet_params, #params_for_search, #remove_facet_params, #reset_search_params, #sanitize_search_params
Instance Method Details
#add_group_facet_params_and_redirect(group) ⇒ Hash
Get url parameters to a search within a grouped result set
152 153 154 |
# File 'app/helpers/blacklight/url_helper_behavior.rb', line 152 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.
160 161 162 |
# File 'app/helpers/blacklight/url_helper_behavior.rb', line 160 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
85 86 87 |
# File 'app/helpers/blacklight/url_helper_behavior.rb', line 85 def controller_tracking_method "track_#{controller_name}_path" end |
#document_link_params(doc, opts) ⇒ Object (protected)
32 33 34 |
# File 'app/helpers/blacklight/url_helper_behavior.rb', line 32 def document_link_params(doc, opts) session_tracking_params(doc, opts[:counter]).deep_merge(opts.except(:label, :counter)) 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.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'app/helpers/blacklight/url_helper_behavior.rb', line 115 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'] || default_per_page).to_i counter = search_session['counter'].to_i query_params[:per_page] = per_page unless search_session['per_page'].to_i == 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
link_to_document(doc, 'VIEW', :counter => 3) Use the catalog_path RESTful route to create a link to the show page for a specific 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
20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/helpers/blacklight/url_helper_behavior.rb', line 20 def link_to_document(doc, field_or_opts = nil, opts={:counter => nil}) if field_or_opts.is_a? Hash opts = field_or_opts else field = field_or_opts end field ||= document_show_link_field(doc) label = index_presenter(doc).label field, opts link_to label, url_for_document(doc), document_link_params(doc, opts) end |
#link_to_next_document(next_document) ⇒ Object
Link to the next document in the current search context
48 49 50 51 52 53 |
# File 'app/helpers/blacklight/url_helper_behavior.rb', line 48 def link_to_next_document(next_document) link_opts = session_tracking_params(next_document, search_session['counter'].to_i + 1).merge(:class => "next", :rel => 'next') link_to_unless next_document.nil?, raw(t('views.pagination.next')), url_for_document(next_document), link_opts do content_tag :span, raw(t('views.pagination.next')), :class => 'next' end end |
#link_to_previous_document(previous_document) ⇒ Object
Link to the previous document in the current search context
39 40 41 42 43 44 |
# File 'app/helpers/blacklight/url_helper_behavior.rb', line 39 def link_to_previous_document(previous_document) link_opts = session_tracking_params(previous_document, search_session['counter'].to_i - 1).merge(:class => "previous", :rel => 'prev') link_to_unless previous_document.nil?, raw(t('views.pagination.previous')), url_for_document(previous_document), link_opts do content_tag :span, raw(t('views.pagination.previous')), :class => 'previous' end end |
#link_to_previous_search(params) ⇒ Object
Search History and Saved Searches display
144 145 146 |
# File 'app/helpers/blacklight/url_helper_behavior.rb', line 144 def link_to_previous_search(params) link_to(render_search_to_s(params), search_action_path(params)) end |
#link_to_query(query) ⇒ Object
create link to query (e.g. spelling suggestion)
94 95 96 97 98 |
# File 'app/helpers/blacklight/url_helper_behavior.rb', line 94 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_params(document, counter) ⇒ Object (protected)
Attributes for a link that gives a URL we can use to track clicks for the current search session
62 63 64 65 66 67 68 69 70 |
# File 'app/helpers/blacklight/url_helper_behavior.rb', line 62 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)) if path.nil? return {} end { data: {:'context-href' => path } } end |
#session_tracking_path(document, params = {}) ⇒ Object
Get the URL for tracking search sessions across pages using polymorphic routing
75 76 77 78 79 80 81 82 83 |
# File 'app/helpers/blacklight/url_helper_behavior.rb', line 75 def session_tracking_path document, params = {} return if document.nil? if respond_to?(controller_tracking_method) send(controller_tracking_method, params.merge(id: document)) else blacklight.track_search_context_path(params.merge(id: document)) end 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.
103 104 105 106 107 108 109 |
# File 'app/helpers/blacklight/url_helper_behavior.rb', line 103 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
Extension point for downstream applications to provide more interesting routing to documents
11 12 13 |
# File 'app/helpers/blacklight/url_helper_behavior.rb', line 11 def url_for_document(doc, = {}) search_state.url_for_document(doc, ) end |