Module: Sufia::SufiaHelperBehavior
- Extended by:
- Deprecation
- Includes:
- ERB::Util, CitationsBehavior
- Included in:
- SufiaHelper
- Defined in:
- app/helpers/sufia/sufia_helper_behavior.rb
Constant Summary
Constants included from CitationsBehaviors::TitleBehavior
CitationsBehaviors::TitleBehavior::EXPANDED_NOCAPS, CitationsBehaviors::TitleBehavior::TITLE_NOCAPS
Instance Method Summary collapse
- #application_name ⇒ Object
- #banner_image ⇒ Object
-
#browser_supports_directory_upload? ⇒ Boolean
Only Chrome supports this.
-
#collection_thumbnail(_document, _image_options = {}, _url_options = {}) ⇒ Object
Used by the gallery view.
-
#current_search_parameters ⇒ Object
Only display the current search parameters if the user is not in the dashboard.
- #error_messages_for(object) ⇒ Object
- #has_collection_search_parameters? ⇒ Boolean
-
#human_readable_date(options) ⇒ Date
A Blacklight helper_method.
-
#iconify_auto_link(field, show_link = true) ⇒ ActiveSupport::SafeBuffer
Uses Rails auto_link to add links to fields.
-
#index_field_link(options) ⇒ ActiveSupport::SafeBuffer
A Blacklight helper_method.
- #institution_name ⇒ Object
- #institution_name_full ⇒ Object
-
#license_links(options) ⇒ ActiveSupport::SafeBuffer
A Blacklight index field helper_method.
-
#link_to_each_facet_field(options) ⇒ Object
A Blacklight helper_method.
-
#link_to_facet(item, field) ⇒ ActiveSupport::SafeBuffer
The html_safe link.
-
#link_to_facet_list(values, solr_field, empty_message = "No value entered".html_safe, separator = ", ") ⇒ ActiveSupport::SafeBuffer
The html_safe link.
-
#link_to_field(name, value, label = nil, facet_hash = {}) ⇒ ActiveSupport::SafeBuffer
The html_safe link.
-
#link_to_profile(args) ⇒ ActiveSupport::SafeBuffer
Sometimes a Blacklight index field helper_method.
- #link_to_telephone(user) ⇒ Object
- #orcid_label(style_class = '') ⇒ Object
- #render_visibility_link(document) ⇒ Object
-
#rights_statement_links(options) ⇒ ActiveSupport::SafeBuffer
A Blacklight helper_method.
-
#search_form_action ⇒ String
The appropriate action url for our search form (depending on our current page).
- #show_transfer_request_title(req) ⇒ Object
- #user_display_name_and_key(user_key) ⇒ Object
- #zotero_label(opts = {}) ⇒ Object
- #zotero_profile_url(zotero_user_id) ⇒ Object
Methods included from CitationsBehavior
#export_as_apa_citation, #export_as_chicago_citation, #export_as_mla_citation, #export_as_openurl_ctx_kev
Methods included from CitationsBehaviors::TitleBehavior
#chicago_citation_title, #mla_citation_title, #process_title_parts, #setup_title_info
Methods included from CitationsBehaviors::CommonBehavior
#clean_end_punctuation, #persistent_url
Methods included from CitationsBehaviors::NameBehavior
#abbreviate_name, #all_authors, #author_list, #given_name_first, #surname_first
Methods included from CitationsBehaviors::PublicationBehavior
#setup_pub_date, #setup_pub_info, #setup_pub_place, #setup_pub_publisher
Instance Method Details
#application_name ⇒ Object
7 8 9 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 7 def application_name t('sufia.product_name', default: super) end |
#banner_image ⇒ Object
19 20 21 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 19 def Sufia.config. end |
#browser_supports_directory_upload? ⇒ Boolean
Replace uses with more granular client-side detection (as jQuery-fileuploader already does)
Only Chrome supports this
39 40 41 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 39 def browser_supports_directory_upload? user_agent.include? 'Chrome' end |
#collection_thumbnail(_document, _image_options = {}, _url_options = {}) ⇒ Object
Used by the gallery view
245 246 247 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 245 def collection_thumbnail(_document, = {}, = {}) content_tag(:span, "", class: [Sufia::ModelIcon.css_class_for(Collection), "collection-icon-search"]) end |
#current_search_parameters ⇒ Object
Only display the current search parameters if the user is not in the dashboard. Otherwise, search defaults to the user’s works and not all of Sufia.
216 217 218 219 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 216 def current_search_parameters return if on_the_dashboard? params[:q] end |
#error_messages_for(object) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 43 def (object) return '' unless 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 end |
#has_collection_search_parameters? ⇒ Boolean
65 66 67 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 65 def has_collection_search_parameters? !params[:cq].blank? end |
#human_readable_date(options) ⇒ Date
A Blacklight helper_method
107 108 109 110 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 107 def human_readable_date() value = [:value].first Date.parse(value).to_formatted_s(:standard) end |
#iconify_auto_link(field, show_link = true) ⇒ ActiveSupport::SafeBuffer
stop being a helper_method, start being part of the Blacklight render stack?
Uses Rails auto_link to add links to fields
163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 163 def iconify_auto_link(field, show_link = true) if field.is_a? Hash = field[:config]. || {} text = field[:value].to_sentence() else text = field end # this block is only executed when a link is inserted; # if we pass text containing no links, it just returns text. auto_link(html_escape(text)) do |value| "<span class='glyphicon glyphicon-new-window'></span>#{(' ' + value) if show_link}" end end |
#index_field_link(options) ⇒ ActiveSupport::SafeBuffer
A Blacklight helper_method
119 120 121 122 123 124 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 119 def index_field_link() raise ArgumentError unless [:config] && [:config][:field_name] name = [:config][:field_name] links = [:value].map { |item| link_to_field(name, item, item) } safe_join(links, ", ") end |
#institution_name ⇒ Object
11 12 13 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 11 def institution_name t('sufia.institution_name') end |
#institution_name_full ⇒ Object
15 16 17 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 15 def institution_name_full t('sufia.institution_name_full', default: institution_name) end |
#license_links(options) ⇒ ActiveSupport::SafeBuffer
A Blacklight index field helper_method
204 205 206 207 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 204 def license_links() service = CurationConcerns::LicenseService.new [:value].map { |right| link_to service.label(right), right }.to_sentence.html_safe end |
#link_to_each_facet_field(options) ⇒ Object
A Blacklight helper_method
140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 140 def link_to_each_facet_field() config = .fetch(:config) separator = config.fetch(:separator, ' > ') output_separator = config.fetch(:output_separator, separator) facet_search = config.fetch(:helper_facet) facet_fields = Array.wrap(.fetch(:value)).first.split(separator).map(&:strip) facet_links = facet_fields.map do |type| link_to(type, main_app.search_catalog_path(f: { facet_search => [type] })) end safe_join(facet_links, output_separator) end |
#link_to_facet(item, field) ⇒ ActiveSupport::SafeBuffer
Returns the html_safe link.
72 73 74 75 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 72 def link_to_facet(item, field) path = search_action_path(search_state.add_facet_params_and_redirect(field, item)) link_to(item, path) end |
#link_to_facet_list(values, solr_field, empty_message = "No value entered".html_safe, separator = ", ") ⇒ ActiveSupport::SafeBuffer
Returns the html_safe link.
82 83 84 85 86 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 82 def link_to_facet_list(values, solr_field, = "No value entered".html_safe, 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(name, value, label = nil, facet_hash = {}) ⇒ ActiveSupport::SafeBuffer
Returns the html_safe link.
94 95 96 97 98 99 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 94 def link_to_field(name, value, label = nil, facet_hash = {}) label ||= value params = { search_field: name, q: "\"#{value}\"" } state = search_state_with_facets(params, facet_hash) link_to(label, main_app.search_catalog_path(state)) end |
#link_to_profile(args) ⇒ ActiveSupport::SafeBuffer
Sometimes a Blacklight index field helper_method
180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 180 def link_to_profile(args) user_or_key = args.is_a?(Hash) ? args[:value].first : args user = case user_or_key when User user_or_key when String ::User.find_by_user_key(user_or_key) end return user_or_key if user.nil? text = user.respond_to?(:name) ? user.name : user_or_key link_to text, Sufia::Engine.routes.url_helpers.profile_path(user) end |
#link_to_telephone(user) ⇒ Object
209 210 211 212 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 209 def link_to_telephone(user) return unless user link_to user.telephone, "wtai://wp/mc;#{user.telephone}" if user.telephone end |
#orcid_label(style_class = '') ⇒ Object
23 24 25 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 23 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_link(document) ⇒ Object
230 231 232 233 234 235 236 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 230 def render_visibility_link(document) # Anchor must match with a tab in # https://github.com/projecthydra/sufia/blob/master/app/views/curation_concerns/base/_guts4form.html.erb#L2 link_to render_visibility_label(document), edit_polymorphic_path([main_app, document], anchor: "share"), id: "permission_" + document.id, class: "visibility-link" end |
#rights_statement_links(options) ⇒ ActiveSupport::SafeBuffer
A Blacklight helper_method
196 197 198 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 196 def rights_statement_links() license_links() end |
#search_form_action ⇒ String
Returns the appropriate action url for our search form (depending on our current page).
222 223 224 225 226 227 228 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 222 def search_form_action if on_the_dashboard? search_action_for_dashboard else main_app.search_catalog_path end end |
#show_transfer_request_title(req) ⇒ Object
56 57 58 59 60 61 62 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 56 def show_transfer_request_title(req) if req.deleted_work? || req.canceled? req.to_s else link_to(req.to_s, req.work) end end |
#user_display_name_and_key(user_key) ⇒ Object
238 239 240 241 242 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 238 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
27 28 29 30 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 27 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
32 33 34 |
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 32 def zotero_profile_url(zotero_user_id) "https://www.zotero.org/users/#{zotero_user_id}" end |