Module: Hyrax::MembershipHelper

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

Instance Method Summary collapse

Instance Method Details

#member_of_collections_json(resource) ⇒ String

TODO:

optimize collection name lookup. the legacy `WorkForm` implementation pulls all the collections already (though maybe with instance-level caching?), but we should consider doing this more efficiently.

Returns JSON for `data-members`.

Parameters:

Returns:

  • (String)

    JSON for `data-members`

See Also:

  • Hyrax::MembershipHelper.app/assets/javascripts/hyrax/relationshipsapp/assets/javascripts/hyrax/relationships.js

16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/helpers/hyrax/membership_helper.rb', line 16

def member_of_collections_json(resource)
  return resource.member_of_collections_json if
    resource.respond_to?(:member_of_collections_json)

  resource = resource.model if resource.respond_to?(:model)

  Hyrax.custom_queries.find_collections_for(resource: resource).map do |collection|
    { id: collection.id.to_s,
      label: collection.title.first,
      path: url_for(collection) }
  end.to_json
end

#work_members_json(resource) ⇒ String

Returns JSON for `data-members`.

Parameters:

Returns:

  • (String)

    JSON for `data-members`

See Also:

  • Hyrax::MembershipHelper.app/assets/javascripts/hyrax/relationshipsapp/assets/javascripts/hyrax/relationships.js

35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/helpers/hyrax/membership_helper.rb', line 35

def work_members_json(resource)
  return resource.work_members_json if
    resource.respond_to?(:work_members_json)

  resource = resource.model if resource.respond_to?(:model)

  Hyrax.custom_queries.find_child_works(resource: resource).map do |member|
    { id: member.id.to_s,
      label: member.title.first,
      path: url_for(member) }
  end.to_json
end