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_type_label(collection_type_gid) ⇒ String
The CollectionType’s title if found, else the gid.
- #has_collection_search_parameters? ⇒ Boolean
-
#present_terms(presenter, terms = :all, &block) ⇒ Object
TODO: we could move this to CollectionPresenter if it had a view_context.
- #render_collection_links(solr_doc) ⇒ 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)
26 27 28 29 30 |
# File 'app/helpers/hyrax/collections_helper.rb', line 26 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
37 38 39 |
# File 'app/helpers/hyrax/collections_helper.rb', line 37 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
41 42 43 |
# File 'app/helpers/hyrax/collections_helper.rb', line 41 def (collection, label = 'Remove From Collection') render 'hyrax/dashboard/collections/button_for_remove_selected_from_collection', collection: collection, label: label end |
#collection_type_label(collection_type_gid) ⇒ String
Returns The CollectionType’s title if found, else the gid.
52 53 54 55 56 |
# File 'app/helpers/hyrax/collections_helper.rb', line 52 def collection_type_label(collection_type_gid) CollectionType.find_by_gid!(collection_type_gid).title rescue ActiveRecord::RecordNotFound, URI::BadURIError CollectionType.find_or_create_default_collection_type.title end |
#has_collection_search_parameters? ⇒ Boolean
33 34 35 |
# File 'app/helpers/hyrax/collections_helper.rb', line 33 def has_collection_search_parameters? params[:cq].present? end |
#present_terms(presenter, terms = :all, &block) ⇒ Object
TODO: we could move this to CollectionPresenter if it had a view_context
6 7 8 9 |
# File 'app/helpers/hyrax/collections_helper.rb', line 6 def present_terms(presenter, terms = :all, &block) terms = presenter.terms if terms == :all Hyrax::PresenterRenderer.new(presenter, self).fields(terms, &block) end |
#render_collection_links(solr_doc) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'app/helpers/hyrax/collections_helper.rb', line 11 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 content_tag :span, safe_join([t('hyrax.collection.is_part_of'), ': '] + 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
46 47 48 |
# File 'app/helpers/hyrax/collections_helper.rb', line 46 def single_item_action_remove_form_fields(form, document) single_item_action_form_fields(form, document, 'remove') end |