Module: Sufia::SufiaHelperBehavior
- Included in:
- SufiaHelper
- Defined in:
- app/helpers/sufia/sufia_helper_behavior.rb
Instance Method Summary collapse
-
#current_search_parameters ⇒ Object
Only display the current search parameters if the user is not in the dashboard.
- #display_user_name(recent_document) ⇒ Object
- #error_messages_for(object) ⇒ Object
- #has_collection_search_parameters? ⇒ Boolean
- #iconify_auto_link(text, show_link = true) ⇒ Object
- #iconify_link(text) ⇒ Object
- #is_url?(str) ⇒ Boolean
-
#link_back_to_dashboard(opts = { label: 'Back to Search' }) ⇒ Object
Create a link back to the dashboard screen, keeping the user’s facet, query and paging choices intact by using session.
- #link_to_dashboard_query(query) ⇒ Object
- #link_to_facet(field, field_string) ⇒ Object
- #link_to_facet_list(values, solr_field, empty_message = "No value entered", separator = ", ") ⇒ Object
- #link_to_field(fieldname, fieldvalue, displayvalue = nil) ⇒ Object
- #link_to_profile(login) ⇒ Object
- #link_to_telephone(user = nil) ⇒ Object
- #linkify_chat_id(chat_id) ⇒ Object
- #number_of_deposits(user) ⇒ Object
- #orcid_label(style_class = '') ⇒ Object
- #render_visibility_label(document) ⇒ Object
- #render_visibility_link(document) ⇒ Object
-
#search_form_action ⇒ Object
Depending on which page we’re landed on, we’ll need to set the appropriate action url for our search form.
- #show_transfer_request_title(req) ⇒ Object
-
#sufia_thumbnail_tag(document, options) ⇒ Object
You can configure blacklight to use this as the thumbnail example: config.index.thumbnail_method = :sufia_thumbnail_tag.
- #user_display_name_and_key(user_key) ⇒ Object
- #zotero_label(opts = {}) ⇒ Object
- #zotero_profile_url(zotero_user_id) ⇒ Object
Instance Method Details
#current_search_parameters ⇒ Object
Only display the current search parameters if the user is not in the dashboard. If they are in the dashboard, then the search defaults to the user’s files and not all of Sufia.
159 160 161 162 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 159 def current_search_parameters return if on_the_dashboard? params[:q] end |
#display_user_name(recent_document) ⇒ Object
84 85 86 87 88 89 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 84 def display_user_name(recent_document) return "no display name" unless recent_document.depositor ::User.find_by_user_key(recent_document.depositor).name rescue recent_document.depositor end |
#error_messages_for(object) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 16 def (object) if object.try(:errors) && object.errors..any? content_tag(:div, class: 'alert alert-block alert-error validation-errors') do content_tag(:h4, I18n.t('sufia.errors.header', model: object.class.model_name.human.downcase), class: 'alert-heading') + content_tag(:ul) do object.errors..map do || content_tag(:li, ) end.join('').html_safe end end else '' # return empty string end end |
#has_collection_search_parameters? ⇒ Boolean
80 81 82 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 80 def has_collection_search_parameters? !params[:cq].blank? end |
#iconify_auto_link(text, show_link = true) ⇒ Object
116 117 118 119 120 121 122 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 116 def iconify_auto_link(text, show_link = true) # this block is only executed when a link is inserted; # if we pass text containing no links, it just returns text. auto_link(text) do |value| "<i class='glyphicon glyphicon-new-window'></i>#{(' ' + value) if show_link}<br />" end end |
#iconify_link(text) ⇒ Object
124 125 126 127 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 124 def iconify_link(text) # different from above in that if text is not a url, return nil. iconify_auto_link(text, false) if is_url?(text) end |
#is_url?(str) ⇒ Boolean
196 197 198 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 196 def is_url?(str) str =~ /\A#{URI.regexp(['http', 'https'])}\z/ end |
#link_back_to_dashboard(opts = { label: 'Back to Search' }) ⇒ Object
Create a link back to the dashboard screen, keeping the user’s facet, query and paging choices intact by using session.
63 64 65 66 67 68 69 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 63 def link_back_to_dashboard(opts = { label: 'Back to Search' }) query_params = session[:search] ? session[:search].dup : {} query_params.delete :counter query_params.delete :total link_url = dashboard_index_path + "?" + query_params.to_query link_to opts[:label], link_url end |
#link_to_dashboard_query(query) ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 71 def link_to_dashboard_query(query) p = params.dup p.delete :page p.delete :action p[:q] = query link_url = dashboard_index_path(p) link_to(query, link_url) end |
#link_to_facet(field, field_string) ⇒ Object
95 96 97 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 95 def link_to_facet(field, field_string) link_to(field, add_facet_params(field_string, field).merge!(controller: "catalog", action: "index")) end |
#link_to_facet_list(values, solr_field, empty_message = "No value entered", separator = ", ") ⇒ Object
103 104 105 106 107 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 103 def link_to_facet_list(values, solr_field, = "No value entered", separator = ", ") return if values.blank? facet_field = Solrizer.solr_name(solr_field, :facetable) safe_join(values.map { |item| link_to_facet(item, facet_field) }, separator) end |
#link_to_field(fieldname, fieldvalue, displayvalue = nil) ⇒ Object
109 110 111 112 113 114 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 109 def link_to_field(fieldname, fieldvalue, displayvalue = nil) p = { search_field: 'advanced', fieldname => '"' + fieldvalue + '"' } link_url = catalog_index_path(p) display = displayvalue.blank? ? fieldvalue : displayvalue link_to(display, link_url) end |
#link_to_profile(login) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 129 def link_to_profile(login) user = ::User.find_by_user_key(login) return login if user.nil? text = if user.respond_to? :name user.name else login end link_to text, Sufia::Engine.routes.url_helpers.profile_path(user) end |
#link_to_telephone(user = nil) ⇒ Object
151 152 153 154 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 151 def link_to_telephone(user = nil) @user ||= user link_to @user.telephone, "wtai://wp/mc;#{@user.telephone}" if @user.telephone end |
#linkify_chat_id(chat_id) ⇒ Object
143 144 145 146 147 148 149 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 143 def linkify_chat_id(chat_id) if chat_id.end_with? '@chat.psu.edu' "<a href=\"xmpp:#{chat_id}\">#{chat_id}</a>" else chat_id end end |
#number_of_deposits(user) ⇒ Object
91 92 93 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 91 def number_of_deposits(user) ActiveFedora::Base.where(Solrizer.solr_name('depositor', :symbol) => user.user_key).count end |
#orcid_label(style_class = '') ⇒ Object
3 4 5 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 3 def orcid_label(style_class = '') "#{image_tag 'orcid.png', alt: t('sufia.user_profile.orcid.alt'), class: style_class} #{t('sufia.user_profile.orcid.label')}".html_safe end |
#render_visibility_label(document) ⇒ Object
179 180 181 182 183 184 185 186 187 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 179 def render_visibility_label(document) if document.registered? content_tag :span, t('sufia.institution_name'), class: "label label-info", title: t('sufia.institution_name') elsif document.public? content_tag :span, t('sufia.visibility.open'), class: "label label-success", title: t('sufia.visibility.open_title_attr') else content_tag :span, t('sufia.visibility.private'), class: "label label-danger", title: t('sufia.visibility.private_title_attr') end end |
#render_visibility_link(document) ⇒ Object
174 175 176 177 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 174 def render_visibility_link(document) link_to render_visibility_label(document), sufia.edit_generic_file_path(document, anchor: "permissions_display"), id: "permission_" + document.id, class: "visibility-link" end |
#search_form_action ⇒ Object
Depending on which page we’re landed on, we’ll need to set the appropriate action url for our search form.
166 167 168 169 170 171 172 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 166 def search_form_action if on_the_dashboard? search_action_for_dashboard else catalog_index_path end end |
#show_transfer_request_title(req) ⇒ Object
31 32 33 34 35 36 37 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 31 def show_transfer_request_title(req) if req.deleted_file? req.title else link_to(req.title, sufia.generic_file_path(req.generic_file_id)) end end |
#sufia_thumbnail_tag(document, options) ⇒ Object
You can configure blacklight to use this as the thumbnail example:
config.index.thumbnail_method = :sufia_thumbnail_tag
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 42 def sufia_thumbnail_tag(document, ) # collection if document.collection? content_tag(:span, "", class: "glyphicon glyphicon-th collection-icon-search") # file else path = if document.image? || document.pdf? || document.video? || document.office_document? sufia.download_path document, file: 'thumbnail' elsif document.audio? "audio.png" else "default.png" end [:alt] = "" image_tag path, end end |
#user_display_name_and_key(user_key) ⇒ Object
189 190 191 192 193 194 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 189 def user_display_name_and_key(user_key) user = ::User.find_by_user_key(user_key) return user_key if user.nil? user.respond_to?(:name) ? "#{user.name} (#{user_key})" : user_key end |
#zotero_label(opts = {}) ⇒ Object
7 8 9 10 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 7 def zotero_label(opts = {}) html_class = opts[:html_class] || '' "#{image_tag 'zotero.png', alt: t('sufia.user_profile.zotero.alt'), class: html_class} #{t('sufia.user_profile.zotero.label')}".html_safe end |
#zotero_profile_url(zotero_user_id) ⇒ Object
12 13 14 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 12 def zotero_profile_url(zotero_user_id) "https://www.zotero.org/users/#{zotero_user_id}" end |