Module: Hyrax::MembershipHelper

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

Instance Method Summary collapse

Instance Method Details

#add_collection_from_paramsObject



31
32
33
34
35
36
37
38
39
# File 'app/helpers/hyrax/membership_helper.rb', line 31

def add_collection_from_params
  # avoid errors when creating Valkyrie resources from Dashboard >> Works
  return [] if controller.params[:add_works_to_collection].blank?

  # new valkyrie works need the collection from params when depositing directly into an existing collection
  return [Hyrax..query_service.find_by(id: Valkyrie::ID.new(controller.params[:add_works_to_collection]))] if Hyrax.config.use_valkyrie?

  [::Collection.find(@controller.params[:add_works_to_collection])]
end

#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
28
29
# File 'app/helpers/hyrax/membership_helper.rb', line 16

def member_of_collections_json(resource)
  # this is where we return for dassie
  return resource.member_of_collections_json if
    resource.respond_to?(:member_of_collections_json)

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

  existing_collections_array = Hyrax.custom_queries.find_collections_for(resource: resource) + add_collection_from_params
  existing_collections_array.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


47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/helpers/hyrax/membership_helper.rb', line 47

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: main_app.url_for([member, { only_path: true }]) }
  end.to_json
end