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, showLink = true) ⇒ Object
-
#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.
150 151 152 153 154 155 156 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 150 def current_search_parameters if on_the_dashboard? return nil else return params[:q] end end |
#display_user_name(recent_document) ⇒ Object
84 85 86 87 |
# 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) and 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, showLink = true) ⇒ Object
114 115 116 117 118 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 114 def iconify_auto_link(text, showLink = true) auto_link(text) do |value| "<i class='glyphicon glyphicon-new-window'></i> #{value if showLink}<br />" end 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
93 94 95 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 93 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
101 102 103 104 105 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 101 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
107 108 109 110 111 112 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 107 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
120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 120 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
142 143 144 145 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 142 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
134 135 136 137 138 139 140 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 134 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
89 90 91 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 89 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
173 174 175 176 177 178 179 180 181 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 173 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
168 169 170 171 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 168 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.
160 161 162 163 164 165 166 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 160 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
183 184 185 186 187 188 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 183 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 |