Module: Curate::CollectionsHelper
- Defined in:
- app/helpers/curate/collections_helper.rb
Overview
require Hydra::Collections::Engine.root + ‘/app/helpers/collections_helper.rb’ View Helpers for Hydra Collections functionality
Instance Method Summary collapse
- #actions_for_member(collection, member) ⇒ Object
-
#actions_for_profile_section(collection, member) ⇒ Object
NOTE: Profile Sections and Collections are being rendered the same way.
-
#button_for_create_new_collection(label = 'Create Collection') ⇒ Object
Displays the Collections create collection button.
- #can_edit_profile_collection?(person) ⇒ Boolean
- #collection_line_item(collection, terminate, options = {}) ⇒ Object
- #collection_member_actions(collection, member) ⇒ Object
- #contributors(work) ⇒ Object
- #has_any_collections? ⇒ Boolean
- #hidden_collection_members ⇒ Object
- #line_item_class(collection) ⇒ Object
-
#list_items_in_collection(collection, terminate = false, options = {}) ⇒ Object
‘terminate’ indicates whether to drill down and display the content of collections within the given collection (i.e. recurse by calling list_items_in_collection on collections within the given collection).
- #member_line_item(collection, member, terminate, options = {}) ⇒ Object
- #title_for_new_form(profile_section) ⇒ Object
- #work_line_item(work, options = {}) ⇒ Object
Instance Method Details
#actions_for_member(collection, member) ⇒ Object
113 114 115 116 117 |
# File 'app/helpers/curate/collections_helper.rb', line 113 def actions_for_member(collection, member) remove_member_collections_path(id: collection.to_param, item_id: member.pid), data: { confirm: 'Are you sure you want to remove this item from the collection?' }, method: :put, id: "remove-#{member.noid}", class: 'btn btn-danger', form_class: 'remove-member', remote: true do raw('<i class="icon-white icon-minus"></i> Remove') end end |
#actions_for_profile_section(collection, member) ⇒ Object
NOTE: Profile Sections and Collections are being rendered the same way.
105 106 107 108 109 110 111 |
# File 'app/helpers/curate/collections_helper.rb', line 105 def actions_for_profile_section(collection, member) if can? :edit, member link_to edit_collection_path(id: member.to_param), class: 'btn' do raw('<i class="icon-pencil"></i> Edit') end end end |
#button_for_create_new_collection(label = 'Create Collection') ⇒ Object
Displays the Collections create collection button.
6 7 8 |
# File 'app/helpers/curate/collections_helper.rb', line 6 def (label = 'Create Collection') render partial: 'button_create_collection', locals:{label:label} end |
#can_edit_profile_collection?(person) ⇒ Boolean
14 15 16 |
# File 'app/helpers/curate/collections_helper.rb', line 14 def can_edit_profile_collection?(person) person.profile && can?(:edit, person.profile) end |
#collection_line_item(collection, terminate, options = {}) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/helpers/curate/collections_helper.rb', line 71 def collection_line_item(collection, terminate, ={}) # A collection listed as a terminal (terminate is true) member of another collection gets a # normal-sized (<p>) font versus a collection heading-sized (<h3>) font. headertag = terminate ? :p : :h3 list_item = content_tag headertag, class: 'collection-section-heading' do link_to(collection.to_s, collection_path(collection)) end if collection.description.present? list_item << content_tag( :div, collection.description, class: 'collection-section-description') end list_item << list_items_in_collection(collection, true, ) unless terminate # limit nesting list_item end |
#collection_member_actions(collection, member) ⇒ Object
93 94 95 96 97 98 99 100 101 102 |
# File 'app/helpers/curate/collections_helper.rb', line 93 def collection_member_actions(collection, member) content_tag :span, class: 'collection-member-actions' do if member.respond_to?(:members) markup = actions_for_member(collection, member) markup << actions_for_profile_section(collection, member) else actions_for_member(collection, member) end end end |
#contributors(work) ⇒ Object
85 86 87 88 89 90 91 |
# File 'app/helpers/curate/collections_helper.rb', line 85 def contributors(work) if work.respond_to?(:contributors) "(#{work.contributors.to_a.join(', ')})" else '' end end |
#has_any_collections? ⇒ Boolean
28 29 30 |
# File 'app/helpers/curate/collections_helper.rb', line 28 def has_any_collections? current_user.collections.count > 0 if current_user end |
#hidden_collection_members ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'app/helpers/curate/collections_helper.rb', line 18 def hidden_collection_members _erbout = '' if params[:batch_document_ids].present? params[:batch_document_ids].each do |batch_item| _erbout.concat hidden_field_tag("batch_document_ids[]", batch_item) end end _erbout.html_safe end |
#line_item_class(collection) ⇒ Object
59 60 61 62 63 |
# File 'app/helpers/curate/collections_helper.rb', line 59 def line_item_class(collection) css_class = 'collection-member' css_class << ' with-controls' if can? :edit, collection css_class end |
#list_items_in_collection(collection, terminate = false, options = {}) ⇒ Object
‘terminate’ indicates whether to drill down and display the content of collections within the given collection (i.e. recurse by calling list_items_in_collection on collections within the given collection).
‘options’ hash may include the following:
:display_contributors - boolean - Indicates whether to display a list of contributors next to the work/collection title.
Default is true. When omitted from options hash or present and set to true, the contributors will be listed.
When set to false, the contributors are not listed.
39 40 41 42 43 44 45 |
# File 'app/helpers/curate/collections_helper.rb', line 39 def list_items_in_collection(collection, terminate=false, ={}) content_tag :ul, class: 'collection-listing' do collection.members.inject('') do |output, member| output << member_line_item(collection, member, terminate, ) end.html_safe end end |
#member_line_item(collection, member, terminate, options = {}) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/helpers/curate/collections_helper.rb', line 47 def member_line_item(collection, member, terminate, ={}) content_tag :li, class: line_item_class(collection), data: { noid: member.noid }do markup = member.respond_to?(:members) ? collection_line_item(member, terminate, ) : work_line_item(member, ) if can? :edit, collection markup << collection_member_actions(collection, member) end markup end end |
#title_for_new_form(profile_section) ⇒ Object
10 11 12 |
# File 'app/helpers/curate/collections_helper.rb', line 10 def title_for_new_form(profile_section) profile_section == 'true' ? 'Add a Section to my Profile' : 'Create a New Collection' end |
#work_line_item(work, options = {}) ⇒ Object
65 66 67 68 69 |
# File 'app/helpers/curate/collections_helper.rb', line 65 def work_line_item(work, ={}) link = link_to work.to_s, polymorphic_path_for_asset(work) link = link + ' ' + contributors(work) if .fetch(:display_contributors, true) link end |