Module: Hyrax::HyraxHelperBehavior
- Includes:
- ERB::Util, AbilityHelper, AttributesHelper, ChartsHelper, CitationsBehavior, CollectionsHelper, ContactFormHelper, DashboardHelperBehavior, EmbargoHelper, FacetsHelper, FileSetFormHelper, FileSetHelper, IiifHelper, LeaseHelper, MembershipHelper, PermalinkHelper, PermissionLevelsHelper, TitleHelper, WorkFormHelper, WorkflowsHelper, WorksHelper
- 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_admin_sets_for_creating_works(ability:) ⇒ Array<String>
The list of admin sets available for creating works for this user.
-
#available_translations ⇒ Hash{String => String}
Which translations are available for the user to select.
-
#available_user_groups(ability:) ⇒ Array<String>
The list of all user groups.
- #banner_image ⇒ Object
- #cast_to_date_time_format(value, format:) ⇒ String
-
#collection_thumbnail(_document, _image_options = {}, _url_options = {}) ⇒ Object
Used by the gallery view.
- #collection_title_by_id(id) ⇒ Object
-
#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", 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 rubocop:disable Metrics/CyclomaticComplexity.
- #link_to_telephone(user) ⇒ Object
- #orcid_label(style_class = '') ⇒ Object
- #render_notifications(user:) ⇒ Object
-
#rights_statement_links(options) ⇒ ActiveSupport::SafeBuffer
A Blacklight index field 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
-
#suppressed_to_status(value) ⇒ String
A Blacklight facet field helper_method.
-
#thumbnail_alt_text_for(document, block_name: nil) ⇒ String
Returns alt text for a thumbnail image.
-
#thumbnail_label_for(object:) ⇒ String
A label for the object's thumbnail.
- #user_display_name_and_key(user_key) ⇒ Object
- #zotero_label(opts = {}) ⇒ Object
- #zotero_profile_url(zotero_user_id) ⇒ Object
Methods included from FileSetFormHelper
#render_transcript_ids_field?, #transcript_ids_select_options
Methods included from WorksHelper
Methods included from PermalinkHelper
#canonical_url_for, #copy_permalink_enabled?, #permalink_for
Methods included from AttributesHelper
#conform_field, #conform_options, #field_visible?, #schema, #view_options_for, #view_options_without_flexibility
Methods included from WorkflowsHelper
Methods included from WorkFormHelper
#admin_set_options, #form_file_set_select_for, #form_progress_sections_for, #form_tab_label_for, #form_tabs_for
Methods included from RedirectsTabHelper
#redirects_supported_form?, #redirects_tab?
Methods included from PermissionLevelsHelper
#configured_owner_permission_levels, #configured_permission_levels, #configured_permission_options
Methods included from MembershipHelper
#add_collection_from_params, #member_of_collections_json, #work_members_json
Methods included from IiifHelper
#iiif_viewer_base_url, #iiif_viewer_display, #iiif_viewer_display_partial, #universal_viewer_base_url, #universal_viewer_config_url
Methods included from DashboardHelperBehavior
#link_to_works, #number_of_collections, #number_of_files, #number_of_works, #on_the_dashboard?
Methods included from ChartsHelper
Methods included from CollectionsHelper
#append_collection_type_url, #available_child_collections, #available_parent_collections_data, #button_for_remove_from_collection, #button_for_remove_selected_from_collection, #collection_brandable?, #collection_discoverable?, #collection_member_sort_fields, #collection_metadata_label, #collection_metadata_value, #collection_permission_template_form_for, #collection_search_parameters?, #collection_sharable?, #collection_type_label, #collection_type_label_for, #has_collection_search_parameters?, #present_terms, #render_collection_links, #render_other_collection_links, #single_item_action_remove_form_fields
Methods included from LeaseHelper
#assets_under_lease, #assets_with_deactivated_leases, #assets_with_expired_leases, #lease_enforced?, #lease_history
Methods included from EmbargoHelper
#assets_under_embargo, #assets_with_deactivated_embargoes, #assets_with_expired_embargoes, #embargo_enforced?, #embargo_history
Methods included from AbilityHelper
#render_visibility_link, #visibility_badge, #visibility_options
Methods included from FileSetHelper
#display_media_download_link?, #media_display, #media_display_partial, #parent_path
Methods included from TitleHelper
#application_name, #construct_page_title, #curation_concern_page_title, #default_page_title, #title_presenter
Methods included from ContactFormHelper
#contact_form_issue_type_options
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_admin_sets_for_creating_works(ability:) ⇒ Array<String>
Returns the list of admin sets available for creating works for this user.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 29 def available_admin_sets_for_creating_works(ability:) return [] unless Flipflop.assign_admin_set? return [] unless ability source_ids = Hyrax::Collections::PermissionsService.source_ids_for_deposit(ability:, source_type: 'admin_set') admin_sets_list = Hyrax.query_service.find_many_by_ids(ids: source_ids).map do |source| [source.title.first, source.id] end # Sorts the default admin set to be first, then the rest by title. admin_sets_list.sort do |a, b| if Hyrax::AdminSetCreateService.default_admin_set?(id: a[1]) -1 elsif Hyrax::AdminSetCreateService.default_admin_set?(id: b[1]) 1 else a[0] <=> b[0] end end end |
#available_translations ⇒ Hash{String => String}
Which translations are available for the user to select
61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 61 def available_translations { 'de' => 'Deutsch', 'en' => 'English', 'es' => 'Español', 'fr' => 'Français', 'it' => 'Italiano', 'pt-BR' => 'Português do Brasil', 'zh' => '中文' } end |
#available_user_groups(ability:) ⇒ Array<String>
Returns the list of all user groups.
53 54 55 56 57 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 53 def available_user_groups(ability:) return ::User.group_service.role_names if ability.admin? ability.user_groups end |
#banner_image ⇒ Object
75 76 77 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 75 def Hyrax.config. end |
#cast_to_date_time_format(value, format:) ⇒ String
366 367 368 369 370 371 372 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 366 def cast_to_date_time_format(value, format:) return value.strftime(format).to_s if value.respond_to?(:strftime) (Time.zone.parse(value)&.strftime(format) || value).to_s rescue ArgumentError, TypeError value.to_s end |
#collection_thumbnail(_document, _image_options = {}, _url_options = {}) ⇒ Object
Used by the gallery view
321 322 323 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 321 def collection_thumbnail(_document, = {}, = {}) tag.span("", class: [Hyrax::ModelIcon.css_class_for(::Collection), "collection-icon-search"]) end |
#collection_title_by_id(id) ⇒ Object
340 341 342 343 344 345 346 347 348 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 340 def collection_title_by_id(id) solr_docs = controller.blacklight_config.repository.find(id).docs return nil if solr_docs.empty? solr_field = solr_docs.first["title_tesim"] return nil if solr_field.nil? solr_field.first rescue Blacklight::Exceptions::RecordNotFound nil 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.
300 301 302 303 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 300 def current_search_parameters return if on_the_dashboard? params[:q] end |
#human_readable_date(options) ⇒ Date
A Blacklight helper_method
161 162 163 164 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 161 def human_readable_date() value = [:value].first Date.parse(value).to_formatted_s(:standard) end |
#iconify_auto_link(field, show_link = true) ⇒ ActiveSupport::SafeBuffer
Uses Rails auto_link to add links to fields
216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 216 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='fa fa-external-link'></span>#{(' ' + value) if show_link}" end end |
#index_field_link(options) ⇒ ActiveSupport::SafeBuffer
A Blacklight helper_method
173 174 175 176 177 178 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 173 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
262 263 264 265 266 267 268 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 262 def license_links() service = Hyrax.config.license_service_class.new to_sentence([:value].map do |right| label = service.label(right) { right } Hyrax::AuthorityRenderingHelper.linkable_uri?(right) ? link_to(label, right) : ERB::Util.h(label) end) end |
#link_to_each_facet_field(options) ⇒ Object
A Blacklight helper_method
194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 194 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.
122 123 124 125 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 122 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", separator = ", ") ⇒ ActiveSupport::SafeBuffer
Returns the html_safe link.
132 133 134 135 136 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 132 def link_to_facet_list(values, solr_field, = "No value entered", separator = ", ") return if values.blank? facet_field = solr_field.to_s + "_sim" 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.
144 145 146 147 148 149 150 151 152 153 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 144 def link_to_field(name, value, label = nil, facet_hash = {}) label ||= value params = {} if name.present? params[:search_field] = name params[:q] = "\"#{value}\"" end 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 rubocop:disable Metrics/CyclomaticComplexity
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 234 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 user_path_params = [user] # Oh the antics, because in some cases (stares at # jobs/content_deposit_event_job_spec.rb) the controller is nil, # which means calling params will raise a NoMethodError. I also # suppose it's possible that the controller won't have a set # params. These precautions should help with that. I'd love to # use params[:locale] in this case, but the & try syntax doesn't # work with that. So you get this lovely bit of logic. locale = controller&.params&.fetch(:locale, nil) || controller&.params&.fetch('locale', nil) user_path_params << { locale: locale } if locale link_to text, Hyrax::Engine.routes.url_helpers.user_path(*user_path_params) end |
#link_to_telephone(user) ⇒ Object
293 294 295 296 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 293 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
79 80 81 82 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 79 def orcid_label(style_class = '') safe_join([image_tag('orcid.png', alt: t('hyrax.user_profile.orcid.alt'), class: style_class), t('hyrax.user_profile.orcid.label')], ' ') end |
#render_notifications(user:) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 95 def render_notifications(user:) mailbox = UserMailbox.new(user) unread_notifications = mailbox.unread_count link_to(hyrax.notifications_path, 'aria-description' => mailbox.label(params[:locale]), class: 'notify-number nav-link') do capture do concat tag.span('', class: 'fa fa-bell', 'aria-label': t('hyrax.admin.sidebar.notifications')) concat "\n" concat tag.span(unread_notifications, class: count_classes_for(unread_notifications)) end end end |
#rights_statement_links(options) ⇒ ActiveSupport::SafeBuffer
A Blacklight index field helper_method
273 274 275 276 277 278 279 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 273 def rights_statement_links() service = Hyrax.config.rights_statement_service_class.new to_sentence([:value].map do |right| label = service.label(right) { right } Hyrax::AuthorityRenderingHelper.linkable_uri?(right) ? link_to(label, right) : ERB::Util.h(label) end) end |
#search_form_action ⇒ String
Returns the appropriate action url for our search form (depending on our current page).
306 307 308 309 310 311 312 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 306 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
111 112 113 114 115 116 117 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 111 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 |
#suppressed_to_status(value) ⇒ String
A Blacklight facet field helper_method
284 285 286 287 288 289 290 291 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 284 def suppressed_to_status(value) case value when 'false' t('hyrax.admin.workflows.index.tabs.published') else t('hyrax.admin.workflows.index.tabs.under_review') end end |
#thumbnail_alt_text_for(document, block_name: nil) ⇒ String
Returns alt text for a thumbnail image. When the document has a custom thumbnail (thumbnail_alt_text indexed), delegates to alt_text_for_view to get the specific alt text. Otherwise returns a generic fallback (hyrax.sr.thumbnail) indicating a default representative image is shown. Apps can override this method to inject content-block lookups or other custom logic.
334 335 336 337 338 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 334 def thumbnail_alt_text_for(document, block_name: nil) # rubocop:disable Lint/UnusedMethodArgument return document.alt_text_for_view if document.respond_to?(:thumbnail_alt_text) && document.thumbnail_alt_text.present? t('hyrax.sr.thumbnail') end |
#thumbnail_label_for(object:) ⇒ String
Returns a label for the object's thumbnail.
354 355 356 357 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 354 def thumbnail_label_for(object:) object.try(:thumbnail_title).presence || "" end |
#user_display_name_and_key(user_key) ⇒ Object
314 315 316 317 318 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 314 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
84 85 86 87 88 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 84 def zotero_label(opts = {}) html_class = opts[:html_class] || '' safe_join([image_tag('zotero.png', alt: t('hyrax.user_profile.zotero.alt'), class: html_class), t('hyrax.user_profile.zotero.label')], ' ') end |
#zotero_profile_url(zotero_user_id) ⇒ Object
90 91 92 |
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 90 def zotero_profile_url(zotero_user_id) "https://www.zotero.org/users/#{zotero_user_id}" end |