Module: Hyrax::HyraxHelperBehavior

Constant Summary

Constants included from CitationsBehaviors::TitleBehavior

CitationsBehaviors::TitleBehavior::EXPANDED_NOCAPS, CitationsBehaviors::TitleBehavior::TITLE_NOCAPS

Instance Method Summary collapse

Methods included from WorkflowsHelper

#workflow_restriction?

Methods included from WorkFormHelper

#form_progress_sections_for, #form_tabs_for

Methods included from PermissionLevelsHelper

#configured_owner_permission_levels, #configured_permission_levels, #configured_permission_options

Methods included from MembershipHelper

#member_of_collections_json, #work_members_json

Methods included from IiifHelper

#iiif_viewer_display, #iiif_viewer_display_partial, #universal_viewer_base_url, #universal_viewer_config_url

Methods included from DashboardHelperBehavior

#number_of_collections, #number_of_files, #number_of_works, #on_the_dashboard?

Methods included from ChartsHelper

#hash_to_chart

Methods included from CollectionsHelper

#append_collection_type_url, #button_for_remove_from_collection, #button_for_remove_selected_from_collection, #collection_member_sort_fields, #collection_metadata_label, #collection_metadata_value, #collection_search_parameters?, #collection_type_label, #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?

Methods included from EmbargoHelper

#assets_under_embargo, #assets_with_deactivated_embargoes, #assets_with_expired_embargoes, #embargo_enforced?

Methods included from AbilityHelper

#render_visibility_link, #visibility_badge, #visibility_options

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, #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_translationsHash{String => String}

Which translations are available for the user to select

Returns:

  • (Hash{String => String})

    locale abbreviations as keys and flags as values


33
34
35
36
37
38
39
40
41
42
43
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 33

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.

Returns:

  • (Array<String>)

    the list of all user groups


25
26
27
28
29
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 25

def available_user_groups(ability:)
  return ::User.group_service.role_names if ability.admin?

  ability.user_groups
end

47
48
49
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 47

def banner_image
  Hyrax.config.banner_image
end

#collection_thumbnail(_document, _image_options = {}, _url_options = {}) ⇒ Object

Used by the gallery view


287
288
289
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 287

def collection_thumbnail(_document, _image_options = {}, _url_options = {})
  tag.span("", class: [Hyrax::ModelIcon.css_class_for(::Collection), "collection-icon-search"])
end

#collection_title_by_id(id) ⇒ Object


291
292
293
294
295
296
297
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 291

def collection_title_by_id(id)
  solr_docs = controller.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
end

#current_search_parametersObject

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.


266
267
268
269
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 266

def current_search_parameters
  return if on_the_dashboard?
  params[:q]
end

#human_readable_date(options) ⇒ Date

A Blacklight helper_method

Parameters:

  • options (Hash)

    from blacklight invocation of helper_method

Returns:

  • (Date)

See Also:


133
134
135
136
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 133

def human_readable_date(options)
  value = options[:value].first
  Date.parse(value).to_formatted_s(:standard)
end

Uses Rails auto_link to add links to fields

Parameters:

  • field (String, Hash)

    string to format and escape, or a hash as per helper_method

  • show_link (Boolean) (defaults to: true)

Options Hash (field):

  • :document (SolrDocument)
  • :field (String)

    name of the solr field

  • :config (Blacklight::Configuration::IndexField, Blacklight::Configuration::ShowField)
  • :value (Array)

    array of values for the field

Returns:

  • (ActiveSupport::SafeBuffer)

188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 188

def iconify_auto_link(field, show_link = true)
  if field.is_a? Hash
    options = field[:config].separator_options || {}
    text = field[:value].to_sentence(options)
  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>#{('&nbsp;' + value) if show_link}"
  end
end

A Blacklight helper_method

Parameters:

  • options (Hash{Symbol=>Object})

    Blacklight sends :document, :field, :config, :value and whatever else was in options

Options Hash (options):

  • :value (Array{String})
  • :config (Hash)

    including {:field_name => “my_name”}

  • :document (Hash)
  • :value (Array{String})

    the strings you might otherwise have passed to this method singly

Returns:

  • (ActiveSupport::SafeBuffer)

    the html_safe link

Raises:

  • (ArgumentError)

145
146
147
148
149
150
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 145

def index_field_link(options)
  raise ArgumentError unless options[:config] && options[:config][:field_name]
  name = options[:config][:field_name]
  links = options[:value].map { |item| link_to_field(name, item, item) }
  safe_join(links, ", ")
end

A Blacklight index field helper_method

Parameters:

  • options (Hash)

    from blacklight helper_method invocation. Maps license URIs to links with labels.

Returns:

  • (ActiveSupport::SafeBuffer)

    license links, html_safe


234
235
236
237
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 234

def license_links(options)
  service = Hyrax.config.license_service_class.new
  to_sentence(options[:value].map { |right| link_to service.label(right), right })
end

A Blacklight helper_method

Examples:

link_to_each_facet_field({ value: "Imaging > Object Photography", config: { helper_facet: :document_types_sim }})
```html
<a href=\"/catalog?f%5Bdocument_types_sim%5D%5B%5D=Imaging\">Imaging</a> &gt; <a href=\"/catalog?f%5Bdocument_types_sim%5D%5B%5D=Object+Photography\">Object Photography</a>
```

Parameters:

  • options (Hash)

    from blacklight invocation of helper_method

Options Hash (options):

  • :value (Array<#strip>)
  • ] (Hash)

    :config Example: { separator: '>', helper_facet: :document_types_sim, output_separator: '::' }

Returns:

  • the html_safe facet links separated by the given separator (default: ' > ') to indicate facet hierarchy

Raises:

  • KeyError when the options are note properly configured


166
167
168
169
170
171
172
173
174
175
176
177
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 166

def link_to_each_facet_field(options)
  config = options.fetch(:config)
  separator = config.fetch(:separator, ' > ')
  output_separator = config.fetch(:output_separator, separator)
  facet_search = config.fetch(:helper_facet)
  facet_fields = Array.wrap(options.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

Returns the html_safe link.

Parameters:

  • item (Object)
  • field (String)

Returns:

  • (ActiveSupport::SafeBuffer)

    the html_safe link


94
95
96
97
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 94

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

Returns the html_safe link.

Parameters:

  • values (Array{String})

    strings to display

  • solr_field (String)

    name of the solr field to link to, without its suffix (:facetable)

  • empty_message (String) (defaults to: "No value entered")

    message to display if no values are passed in

  • separator (String) (defaults to: ", ")

    value to join with

Returns:

  • (ActiveSupport::SafeBuffer)

    the html_safe link


104
105
106
107
108
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 104

def link_to_facet_list(values, solr_field, empty_message = "No value entered", separator = ", ")
  return empty_message if values.blank?
  facet_field = solr_field.to_s + "_sim"
  safe_join(values.map { |item| link_to_facet(item, facet_field) }, separator)
end

Returns the html_safe link.

Parameters:

  • name (String)

    field name

  • value (String)

    field value

  • label (String) (defaults to: nil)

    defaults to value

  • facet_hash (Hash) (defaults to: {})

    first argument to Blacklight::SearchState.new

Returns:

  • (ActiveSupport::SafeBuffer)

    the html_safe link

See Also:

  • Blacklight::SearchState#initialize

116
117
118
119
120
121
122
123
124
125
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 116

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

Sometimes a Blacklight index field helper_method rubocop:disable Metrics/CyclomaticComplexity

Parameters:

  • args (String, User, Hash{Symbol=>Array})

    if a hash, the user_key must be under :value

Returns:

  • (ActiveSupport::SafeBuffer)

    the html_safe link


206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 206

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

259
260
261
262
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 259

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


51
52
53
54
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 51

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

Parameters:


67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 67

def render_notifications(user:)
  mailbox = UserMailbox.new(user)
  unread_notifications = mailbox.unread_count
  link_to(hyrax.notifications_path,
          'aria-label' => mailbox.label(params[:locale]),
          class: 'notify-number') do
    capture do
      concat tag.span('', class: 'fa fa-bell')
      concat "\n"
      concat tag.span(unread_notifications,
                         class: count_classes_for(unread_notifications))
    end
  end
end

A Blacklight index field helper_method

Parameters:

  • options (Hash)

    from blacklight helper_method invocation. Maps rights statement URIs to links with labels.

Returns:

  • (ActiveSupport::SafeBuffer)

    rights statement links, html_safe


242
243
244
245
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 242

def rights_statement_links(options)
  service = Hyrax.config.rights_statement_service_class.new
  to_sentence(options[:value].map { |right| link_to service.label(right), right })
end

#search_form_actionString

Returns the appropriate action url for our search form (depending on our current page).

Returns:

  • (String)

    the appropriate action url for our search form (depending on our current page)


272
273
274
275
276
277
278
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 272

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

Parameters:


83
84
85
86
87
88
89
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 83

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

Parameters:

  • value (String)

    from blacklight helper_method invocation.

Returns:

  • (String)

    the decoded meaning of the boolean field


250
251
252
253
254
255
256
257
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 250

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

#user_display_name_and_key(user_key) ⇒ Object


280
281
282
283
284
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 280

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


56
57
58
59
60
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 56

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


62
63
64
# File 'app/helpers/hyrax/hyrax_helper_behavior.rb', line 62

def zotero_profile_url(zotero_user_id)
  "https://www.zotero.org/users/#{zotero_user_id}"
end