Module: Hyrax::CollectionsHelper
- Included in:
- HyraxHelperBehavior
- Defined in:
- app/helpers/hyrax/collections_helper.rb
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).
- #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_member_sort_fields ⇒ Object
- #collection_metadata_label(collection, field) ⇒ #to_s
- #collection_metadata_value(collection, field) ⇒ #to_s
- #collection_search_parameters? ⇒ Boolean
-
#collection_type_label(collection_type_gid) ⇒ String
The CollectionType’s title if found, else the gid.
- #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.
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)
67 68 69 70 71 |
# File 'app/helpers/hyrax/collections_helper.rb', line 67 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 |
#button_for_remove_from_collection(collection, document, label: 'Remove From Collection', btn_class: 'btn-primary') ⇒ Object
87 88 89 |
# File 'app/helpers/hyrax/collections_helper.rb', line 87 def (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
91 92 93 |
# File 'app/helpers/hyrax/collections_helper.rb', line 91 def (collection, label = 'Remove From Collection') render 'hyrax/dashboard/collections/button_for_remove_selected_from_collection', collection: collection, label: label end |
#collection_member_sort_fields ⇒ Object
35 36 37 |
# File 'app/helpers/hyrax/collections_helper.rb', line 35 def collection_member_sort_fields active_sort_fields end |
#collection_metadata_label(collection, field) ⇒ #to_s
7 8 9 |
# File 'app/helpers/hyrax/collections_helper.rb', line 7 def (collection, field) Hyrax::PresenterRenderer.new(collection, self).label(field) end |
#collection_metadata_value(collection, field) ⇒ #to_s
14 15 16 |
# File 'app/helpers/hyrax/collections_helper.rb', line 14 def (collection, field) Hyrax::PresenterRenderer.new(collection, self).value(field) end |
#collection_search_parameters? ⇒ Boolean
75 76 77 |
# File 'app/helpers/hyrax/collections_helper.rb', line 75 def collection_search_parameters? params[:cq].present? end |
#collection_type_label(collection_type_gid) ⇒ String
Returns The CollectionType’s title if found, else the gid.
102 103 104 105 106 |
# File 'app/helpers/hyrax/collections_helper.rb', line 102 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 |
#has_collection_search_parameters? ⇒ Boolean
Deprecated.
82 83 84 85 |
# File 'app/helpers/hyrax/collections_helper.rb', line 82 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.
23 24 25 26 27 28 29 |
# File 'app/helpers/hyrax/collections_helper.rb', line 23 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
39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/helpers/hyrax/collections_helper.rb', line 39 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
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/helpers/hyrax/collections_helper.rb', line 51 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
96 97 98 |
# File 'app/helpers/hyrax/collections_helper.rb', line 96 def single_item_action_remove_form_fields(form, document) single_item_action_form_fields(form, document, 'remove') end |