Class: Hyrax::Dashboard::CollectionMembersController

Inherits:
My::CollectionsController show all
Includes:
Collections::AcceptsBatches
Defined in:
app/controllers/hyrax/dashboard/collection_members_controller.rb

Overview

Shows a list of all collections to the admins

Instance Method Summary collapse

Methods included from Collections::AcceptsBatches

#batch, #batch=, #check_for_empty_batch?

Methods inherited from My::CollectionsController

configure_facets, #index

Methods inherited from MyController

configure_facets, #index

Instance Method Details

#after_updateObject



14
15
16
17
18
19
# File 'app/controllers/hyrax/dashboard/collection_members_controller.rb', line 14

def after_update
  respond_to do |format|
    format.html { redirect_to success_return_path, notice: t('hyrax.dashboard.my.action.collection_update_success') }
    format.json { render json: @collection, status: :updated, location: dashboard_collection_path(@collection) }
  end
end

#after_update_error(err_msg) ⇒ Object



21
22
23
24
25
26
# File 'app/controllers/hyrax/dashboard/collection_members_controller.rb', line 21

def after_update_error(err_msg)
  respond_to do |format|
    format.html { redirect_to err_return_path, alert: err_msg }
    format.json { render json: @collection.errors, status: :unprocessable_entity }
  end
end

#update_membersObject

rubocop:disable Metrics/MethodLength



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/hyrax/dashboard/collection_members_controller.rb', line 28

def update_members # rubocop:disable Metrics/MethodLength
  err_msg = validate
  after_update_error(err_msg) if err_msg.present?
  return if err_msg.present?

  begin
    Hyrax::Collections::CollectionMemberService.add_members_by_ids(collection_id: collection_id,
                                                                   new_member_ids: batch_ids,
                                                                   user: current_user)
    after_update
  rescue Hyrax::SingleMembershipError => err
    messages = JSON.parse(err.message)
    if messages.size == batch_ids.size
      after_update_error(messages.uniq.join(', '))
    elsif messages.present?
      flash[:error] = messages.uniq.join(', ')
      after_update
    end
  end
end