Module: Hyrax::CollectionsHelper

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

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



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 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



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

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_member_sort_fieldsObject

See Also:

  • Blacklight::ConfigurationHelperBehavior#active_sort_fields

Since:

  • 3.0.0



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

Returns:

  • (#to_s)

Since:

  • 3.0.0



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

Returns:

  • (#to_s)

Since:

  • 3.0.0



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

Returns:

  • (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.

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



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.

Returns:

  • (Boolean)


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.

Parameters:



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


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


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