Module: Hyrax::CollectionsHelper

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

Overview

rubocop:disable Metrics/ModuleLength

Instance Method Summary collapse

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



90
91
92
93
94
# File 'app/helpers/hyrax/collections_helper.rb', line 90

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



7
8
9
10
# File 'app/helpers/hyrax/collections_helper.rb', line 7

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



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

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



110
111
112
# File 'app/helpers/hyrax/collections_helper.rb', line 110

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



114
115
116
# File 'app/helpers/hyrax/collections_helper.rb', line 114

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)


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

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

#collection_discoverable?(collection:) ⇒ Boolean

Parameters:

  • collection (Object)

Returns:

  • (Boolean)


141
142
143
# File 'app/helpers/hyrax/collections_helper.rb', line 141

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



58
59
60
# File 'app/helpers/hyrax/collections_helper.rb', line 58

def collection_member_sort_fields
  active_sort_fields
end

#collection_metadata_label(collection, field) ⇒ #to_s

Returns:

  • (#to_s)

Since:

  • 3.0.0



30
31
32
# File 'app/helpers/hyrax/collections_helper.rb', line 30

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



37
38
39
# File 'app/helpers/hyrax/collections_helper.rb', line 37

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

#collection_permission_template_form_for(form:) ⇒ PermissionTemplateForm

Parameters:

  • collection (Object)

Returns:

  • (PermissionTemplateForm)


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

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)


98
99
100
# File 'app/helpers/hyrax/collections_helper.rb', line 98

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

#collection_sharable?(collection:) ⇒ Boolean

Parameters:

  • collection (Object)

Returns:

  • (Boolean)


149
150
151
# File 'app/helpers/hyrax/collections_helper.rb', line 149

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



160
161
162
163
164
# File 'app/helpers/hyrax/collections_helper.rb', line 160

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)


125
126
127
# File 'app/helpers/hyrax/collections_helper.rb', line 125

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

#has_collection_search_parameters?Boolean

Deprecated.

Returns:

  • (Boolean)


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

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:



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

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


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

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


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

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



119
120
121
# File 'app/helpers/hyrax/collections_helper.rb', line 119

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