Module: Hyrax::CollectionsHelper

Includes:
RedirectsTabHelper
Included in:
HyraxHelperBehavior
Defined in:
app/helpers/hyrax/collections_helper.rb

Overview

rubocop:disable Metrics/ModuleLength

Instance Method Summary collapse

Methods included from RedirectsTabHelper

#redirects_supported_form?, #redirects_tab?

Instance Method Details

#append_collection_type_url(url, collection_type_id) ⇒ String

Append a collection_type_id to the existing querystring (whether or not it has pre-existing params)

Returns:

  • (String)

    the original url with and added collection_type_id param



92
93
94
95
96
# File 'app/helpers/hyrax/collections_helper.rb', line 92

def append_collection_type_url(url, collection_type_id)
  uri = URI.parse(url)
  uri.query = [uri.query, "collection_type_id=#{collection_type_id}"].compact.join('&')
  uri.to_s
end

#available_child_collections(collection:) ⇒ Array<SolrDocument>

Returns:

Since:

  • 3.1.0



9
10
11
12
# File 'app/helpers/hyrax/collections_helper.rb', line 9

def available_child_collections(collection:)
  Hyrax::Collections::NestedCollectionQueryService
    .available_child_collections(parent: collection, scope: controller, limit_to_id: nil)
end

#available_parent_collections_data(collection:) ⇒ String

Note:

provides data for handleAddToCollection javascript

Returns JSON document containing id/title pairs for eligible parent collections to be displayed in an "Add to Collection" dropdown.

Returns:

  • (String)

    JSON document containing id/title pairs for eligible parent collections to be displayed in an "Add to Collection" dropdown

Since:

  • 3.1.0



21
22
23
24
25
26
27
# File 'app/helpers/hyrax/collections_helper.rb', line 21

def available_parent_collections_data(collection:)
  Hyrax::Collections::NestedCollectionQueryService
    .available_parent_collections(child: collection, scope: controller, limit_to_id: nil)
    .map do |result|
    { "id" => result.id, "title_first" => result.title.first }
  end.to_json
end

#button_for_remove_from_collection(collection, document, label: 'Remove From Collection', btn_class: 'btn-primary') ⇒ Object



112
113
114
# File 'app/helpers/hyrax/collections_helper.rb', line 112

def button_for_remove_from_collection(collection, document, label: 'Remove From Collection', btn_class: 'btn-primary')
  render 'hyrax/dashboard/collections/button_remove_from_collection', collection: collection, label: label, document: document, btn_class: btn_class
end

#button_for_remove_selected_from_collection(collection, label = 'Remove From Collection') ⇒ Object



116
117
118
# File 'app/helpers/hyrax/collections_helper.rb', line 116

def button_for_remove_selected_from_collection(collection, label = 'Remove From Collection')
  render 'hyrax/dashboard/collections/button_for_remove_selected_from_collection', collection: collection, label: label
end

#collection_brandable?(collection:) ⇒ Boolean

Parameters:

  • collection (Object)

Returns:

  • (Boolean)


135
136
137
# File 'app/helpers/hyrax/collections_helper.rb', line 135

def collection_brandable?(collection:)
  CollectionType.for(collection: collection).brandable?
end

#collection_discoverable?(collection:) ⇒ Boolean

Parameters:

  • collection (Object)

Returns:

  • (Boolean)


143
144
145
# File 'app/helpers/hyrax/collections_helper.rb', line 143

def collection_discoverable?(collection:)
  CollectionType.for(collection: collection).discoverable?
end

#collection_member_sort_fieldsObject

See Also:

  • Blacklight::ConfigurationHelperBehavior#active_sort_fields

Since:

  • 3.0.0



60
61
62
# File 'app/helpers/hyrax/collections_helper.rb', line 60

def collection_member_sort_fields
  active_sort_fields
end

#collection_metadata_label(collection, field) ⇒ #to_s

Returns:

  • (#to_s)

Since:

  • 3.0.0



32
33
34
# File 'app/helpers/hyrax/collections_helper.rb', line 32

def (collection, field)
  Hyrax::PresenterRenderer.new(collection, self).label(field)
end

#collection_metadata_value(collection, field) ⇒ #to_s

Returns:

  • (#to_s)

Since:

  • 3.0.0



39
40
41
# File 'app/helpers/hyrax/collections_helper.rb', line 39

def (collection, field)
  Hyrax::PresenterRenderer.new(collection, self).value(field)
end

#collection_permission_template_form_for(form:) ⇒ PermissionTemplateForm

Parameters:

  • collection (Object)

Returns:

  • (PermissionTemplateForm)


172
173
174
175
176
177
178
179
180
# File 'app/helpers/hyrax/collections_helper.rb', line 172

def collection_permission_template_form_for(form:)
  case form
  when Valkyrie::ChangeSet
    template_model = Hyrax::PermissionTemplate.find_or_create_by(source_id: form.id.to_s)
    Hyrax::Forms::PermissionTemplateForm.new(template_model)
  else
    form.permission_template
  end
end

#collection_search_parameters?Boolean

Returns:

  • (Boolean)


100
101
102
# File 'app/helpers/hyrax/collections_helper.rb', line 100

def collection_search_parameters?
  params[:cq].present?
end

#collection_sharable?(collection:) ⇒ Boolean

Parameters:

  • collection (Object)

Returns:

  • (Boolean)


151
152
153
# File 'app/helpers/hyrax/collections_helper.rb', line 151

def collection_sharable?(collection:)
  CollectionType.for(collection: collection).sharable?
end

#collection_type_label(collection_type_gid) ⇒ String

Note:

this helper is primarily intended for use with blacklight facet fields. it assumes we index a collection_type_gid and the helper can be passed as as a helper_method: to add_facet_field.

Returns The CollectionType's title if found, else the gid.

Parameters:

  • collection_type_gid (String)

    The gid of the CollectionType to be looked up

Returns:

  • (String)

    The CollectionType's title if found, else the gid



162
163
164
165
166
# File 'app/helpers/hyrax/collections_helper.rb', line 162

def collection_type_label(collection_type_gid)
  CollectionType.find_by_gid!(collection_type_gid).title
rescue ActiveRecord::RecordNotFound, URI::InvalidURIError, URI::BadURIError
  CollectionType.find_or_create_default_collection_type.title
end

#collection_type_label_for(collection:) ⇒ Object

Parameters:

  • collection (Object)


127
128
129
# File 'app/helpers/hyrax/collections_helper.rb', line 127

def collection_type_label_for(collection:)
  CollectionType.for(collection: collection).title
end

#has_collection_search_parameters?Boolean

Deprecated.

Returns:

  • (Boolean)


107
108
109
110
# File 'app/helpers/hyrax/collections_helper.rb', line 107

def has_collection_search_parameters? # rubocop:disable Naming/PredicateName:
  Deprecation.warn('use #collection_search_parameters? helper instead')
  collection_search_parameters?
end

#present_terms(presenter, terms = :all, &block) ⇒ Object

Deprecated.

Use #collection_metadata_label and #collection_metadata_value instead.

Parameters:



48
49
50
51
52
53
54
# File 'app/helpers/hyrax/collections_helper.rb', line 48

def present_terms(presenter, terms = :all, &block)
  Deprecation.warn("the .present_terms is deprecated for removal in Hyrax 4.0.0; " \
                   "use #collection_metadata_label/value instead")

  terms = presenter.terms if terms == :all
  Hyrax::PresenterRenderer.new(presenter, self).fields(terms, &block)
end


64
65
66
67
68
69
70
71
72
73
74
# File 'app/helpers/hyrax/collections_helper.rb', line 64

def render_collection_links(solr_doc)
  collection_list = Hyrax::CollectionMemberService.run(solr_doc, controller.current_ability)
  return if collection_list.empty?
  links = collection_list.map { |collection| link_to collection.title_or_label, hyrax.collection_path(collection.id) }
  collection_links = []
  links.each_with_index do |link, n|
    collection_links << link
    collection_links << ', ' unless links[n + 1].nil?
  end
  tag.span safe_join([t('hyrax.collection.is_part_of'), ': '] + collection_links)
end


76
77
78
79
80
81
82
83
84
85
86
87
# File 'app/helpers/hyrax/collections_helper.rb', line 76

def render_other_collection_links(solr_doc, collection_id)
  collection_list = Hyrax::CollectionMemberService.run(solr_doc, controller.current_ability)
  return if collection_list.empty?
  links = collection_list.select { |collection| collection.id != collection_id }.map { |collection| link_to collection.title_or_label, hyrax.collection_path(collection.id) }
  return if links.empty?
  collection_links = []
  links.each_with_index do |link, n|
    collection_links << link
    collection_links << ', ' unless links[n + 1].nil?
  end
  tag.span safe_join([t('hyrax.collection.also_belongs_to'), ': '] + collection_links)
end

#single_item_action_remove_form_fields(form, document) ⇒ Object

add hidden fields to a form for removing a single document from a collection



121
122
123
# File 'app/helpers/hyrax/collections_helper.rb', line 121

def single_item_action_remove_form_fields(form, document)
  single_item_action_form_fields(form, document, 'remove')
end