Module: Hyrax::HyraxHelperBehavior
- Includes:
- ERB::Util, AbilityHelper, ChartsHelper, CitationsBehavior, CollectionsHelper, DashboardHelperBehavior, EmbargoHelper, FileSetHelper, LeaseHelper, SearchPathsHelper, TitleHelper, UrlHelper
- Included in:
- HyraxHelper
- Defined in:
- app/helpers/hyrax/hyrax_helper_behavior.rb
Constant Summary
Constants included from CitationsBehaviors::TitleBehavior
CitationsBehaviors::TitleBehavior::EXPANDED_NOCAPS, CitationsBehaviors::TitleBehavior::TITLE_NOCAPS
Instance Method Summary collapse
-
#available_translations ⇒ Hash<String,String>
Which translations are available for the user to select.
- #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.
-
#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.
-
#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
-
#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 DashboardHelperBehavior
#link_to_additional_notifications, #notifications_for_dashboard, #number_of_collections, #number_of_files, #number_of_works, #on_my_works?, #on_the_dashboard?, #render_received_transfers, #render_recent_activity, #render_recent_notifications, #render_sent_transfers
Methods included from ChartsHelper
Methods included from CollectionsHelper
#button_for_remove_from_collection, #button_for_remove_selected_from_collection, #has_collection_search_parameters?, #render_collection_links, #single_item_action_remove_form_fields
Methods included from LeaseHelper
#assets_under_lease, #assets_with_deactivated_leases, #assets_with_expired_leases
Methods included from EmbargoHelper
#assets_under_embargo, #assets_with_deactivated_embargoes, #assets_with_expired_embargoes
Methods included from AbilityHelper
#render_visibility_link, #visibility_badge, #visibility_options
Methods included from SearchPathsHelper
#search_path_for_my_collections, #search_path_for_my_works
Methods included from FileSetHelper
#media_display, #media_display_partial, #parent_path
Methods included from TitleHelper
#application_name, #construct_page_title, #curation_concern_page_title, #default_page_title
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
#available_translations ⇒ Hash<String,String>
Which translations are available for the user to select
19 20 21 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 19 def available_translations { 'en' => 'English', 'es' => 'Español', 'zh' => '中文' } end |
#banner_image ⇒ Object
25 26 27 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 25 def Hyrax.config. end |
#browser_supports_directory_upload? ⇒ Boolean
Replace uses with more granular client-side detection (as jQuery-fileuploader already does)
Only Chrome supports this
45 46 47 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 45 def browser_supports_directory_upload? user_agent.include? 'Chrome' end |
#collection_thumbnail(_document, _image_options = {}, _url_options = {}) ⇒ Object
Used by the gallery view
218 219 220 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 218 def collection_thumbnail(_document, = {}, = {}) content_tag(:span, "", class: [Hyrax::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 Hyrax.
197 198 199 200 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 197 def current_search_parameters return if on_the_dashboard? params[:q] end |
#human_readable_date(options) ⇒ Date
A Blacklight helper_method
96 97 98 99 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 96 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
152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 152 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
108 109 110 111 112 113 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 108 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 |
#license_links(options) ⇒ ActiveSupport::SafeBuffer
A Blacklight index field helper_method
185 186 187 188 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 185 def license_links() service = Hyrax::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
129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 129 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.
61 62 63 64 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 61 def link_to_facet(item, field) path = main_app.search_catalog_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.
71 72 73 74 75 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 71 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.
83 84 85 86 87 88 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 83 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
169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 169 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, Hyrax::Engine.routes.url_helpers.profile_path(user) end |
#link_to_telephone(user) ⇒ Object
190 191 192 193 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 190 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
29 30 31 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 29 def orcid_label(style_class = '') "#{image_tag 'orcid.png', alt: t('hyrax.user_profile.orcid.alt'), class: style_class} #{t('hyrax.user_profile.orcid.label')}".html_safe end |
#search_form_action ⇒ String
Returns the appropriate action url for our search form (depending on our current page).
203 204 205 206 207 208 209 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 203 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
50 51 52 53 54 55 56 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 50 def show_transfer_request_title(req) if req.deleted_work? || req.canceled? req.to_s else link_to(req.to_s, [main_app, req.work]) end end |
#user_display_name_and_key(user_key) ⇒ Object
211 212 213 214 215 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 211 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
33 34 35 36 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 33 def zotero_label(opts = {}) html_class = opts[:html_class] || '' "#{image_tag 'zotero.png', alt: t('hyrax.user_profile.zotero.alt'), class: html_class} #{t('hyrax.user_profile.zotero.label')}".html_safe end |
#zotero_profile_url(zotero_user_id) ⇒ Object
38 39 40 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 38 def zotero_profile_url(zotero_user_id) "https://www.zotero.org/users/#{zotero_user_id}" end |