Module: Hyrax::CollectionsHelper
Overview
rubocop:disable Metrics/ModuleLength
Instance Method Summary
collapse
-
#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).
-
#available_child_collections(collection:) ⇒ Array<SolrDocument>
-
#available_parent_collections_data(collection:) ⇒ String
JSON document containing id/title pairs for eligible parent collections to be displayed in an "Add to Collection" dropdown.
-
#button_for_remove_from_collection(collection, document, label: 'Remove From Collection', btn_class: 'btn-primary') ⇒ Object
-
#button_for_remove_selected_from_collection(collection, label = 'Remove From Collection') ⇒ Object
-
#collection_brandable?(collection:) ⇒ Boolean
-
#collection_discoverable?(collection:) ⇒ Boolean
-
#collection_member_sort_fields ⇒ Object
-
#collection_metadata_label(collection, field) ⇒ #to_s
-
#collection_metadata_value(collection, field) ⇒ #to_s
-
#collection_permission_template_form_for(form:) ⇒ PermissionTemplateForm
-
#collection_search_parameters? ⇒ Boolean
-
#collection_sharable?(collection:) ⇒ Boolean
-
#collection_type_label(collection_type_gid) ⇒ String
The CollectionType's title if found, else the gid.
-
#collection_type_label_for(collection:) ⇒ Object
-
#has_collection_search_parameters? ⇒ Boolean
deprecated
Deprecated.
-
#present_terms(presenter, terms = :all, &block) ⇒ Object
deprecated
Deprecated.
Use #collection_metadata_label and #collection_metadata_value instead.
-
#render_collection_links(solr_doc) ⇒ Object
-
#render_other_collection_links(solr_doc, collection_id) ⇒ Object
-
#single_item_action_remove_form_fields(form, document) ⇒ Object
add hidden fields to a form for removing a single document from a collection.
#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)
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>
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.
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
|
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
|
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
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
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_fields ⇒ Object
60
61
62
|
# File 'app/helpers/hyrax/collections_helper.rb', line 60
def collection_member_sort_fields
active_sort_fields
end
|
32
33
34
|
# File 'app/helpers/hyrax/collections_helper.rb', line 32
def collection_metadata_label(collection, field)
Hyrax::PresenterRenderer.new(collection, self).label(field)
end
|
39
40
41
|
# File 'app/helpers/hyrax/collections_helper.rb', line 39
def collection_metadata_value(collection, field)
Hyrax::PresenterRenderer.new(collection, self).value(field)
end
|
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
100
101
102
|
# File 'app/helpers/hyrax/collections_helper.rb', line 100
def collection_search_parameters?
params[:cq].present?
end
|
#collection_sharable?(collection:) ⇒ 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.
#collection_type_label_for(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
107
108
109
110
|
# File 'app/helpers/hyrax/collections_helper.rb', line 107
def has_collection_search_parameters? 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.
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
|
#render_collection_links(solr_doc) ⇒ Object
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
|
#render_other_collection_links(solr_doc, collection_id) ⇒ Object
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
|
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
|