Class: Hyrax::BatchEditsController
Instance Method Summary
collapse
#batch, #batch=, #check_for_empty_batch?
#add_breadcrumb_for_action, #build_breadcrumbs, #default_trail, #trail_from_referer
#display_media_download_link?, #media_display, #media_display_partial, #parent_path
Instance Method Details
#after_destroy_collection ⇒ Object
30
31
32
|
# File 'app/controllers/hyrax/batch_edits_controller.rb', line 30
def after_destroy_collection
redirect_back fallback_location: hyrax.batch_edits_path
end
|
#after_update ⇒ Object
23
24
25
26
27
28
|
# File 'app/controllers/hyrax/batch_edits_controller.rb', line 23
def after_update
respond_to do |format|
format.json { head :no_content }
format.html { redirect_to_return_controller }
end
end
|
#check_for_empty! ⇒ Object
34
35
36
37
38
|
# File 'app/controllers/hyrax/batch_edits_controller.rb', line 34
def check_for_empty!
return unless check_for_empty_batch?
redirect_back fallback_location: hyrax.batch_edits_path
false
end
|
#destroy_collection ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
|
# File 'app/controllers/hyrax/batch_edits_controller.rb', line 40
def destroy_collection
batch.each do |doc_id|
resource = Hyrax.query_service.find_by(id: Valkyrie::ID.new(doc_id))
transactions['collection_resource.destroy']
.with_step_args('collection_resource.delete' => { user: current_user },
'collection_resource.remove_from_membership' => { user: current_user })
.call(resource).value!
end
flash[:notice] = "Batch delete complete"
after_destroy_collection
end
|
#edit ⇒ Object
17
18
19
20
21
|
# File 'app/controllers/hyrax/batch_edits_controller.rb', line 17
def edit
work = form_class.model_class.new
work.depositor = current_user.user_key
@form = form_class.new(work, current_user, batch)
end
|
#update ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'app/controllers/hyrax/batch_edits_controller.rb', line 78
def update
case params["update_type"]
when "update"
batch.each do |doc_id|
if Hyrax.config.use_valkyrie?
valkyrie_update_document(Hyrax.query_service.find_by(id: doc_id))
else
update_document(Hyrax.query_service.find_by_alternate_identifier(alternate_identifier: doc_id, use_valkyrie: false))
end
end
flash[:notice] = "Batch update complete"
after_update
when "delete_all"
destroy_batch
end
end
|
#update_document(obj) ⇒ Object
52
53
54
55
56
57
58
59
60
61
|
# File 'app/controllers/hyrax/batch_edits_controller.rb', line 52
def update_document(obj)
interpret_visiblity_params(obj)
obj.attributes = work_params(admin_set_id: obj.admin_set_id).except(*visibility_params)
obj.date_modified = TimeService.time_in_utc
InheritPermissionsJob.perform_now(obj)
VisibilityCopyJob.perform_now(obj)
obj.save
end
|
#valkyrie_update_document(obj) ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'app/controllers/hyrax/batch_edits_controller.rb', line 63
def valkyrie_update_document(obj)
form = form_class.new(obj, current_ability, nil)
return unless form.validate(params[form_class.model_class.model_name.param_key])
cleanup_form_fields form
result = transactions['change_set.update_work']
.with_step_args('work_resource.save_acl' => { permissions_params: form.input_params["permissions"] })
.call(form)
obj = result.value!
InheritPermissionsJob.perform_now(obj)
VisibilityCopyJob.perform_now(obj)
end
|