Module: Hydra::BatchEditBehavior
- Extended by:
- ActiveSupport::Concern
- Included in:
- Hyrax::BatchEditsController, Hyrax::MyControllerBehavior
- Defined in:
- app/controllers/concerns/hydra/batch_edit_behavior.rb
Instance Method Summary collapse
-
#after_destroy_collection ⇒ Object
pulled out to allow a user to override the default redirect.
-
#after_update ⇒ Object
pulled out to allow a user to override the default redirect.
- #all ⇒ Object
- #check_for_empty! ⇒ Object
- #destroy_collection ⇒ Object
- #edit ⇒ Object
-
#index ⇒ Object
fetch the documents that match the ids in the folder.
- #state ⇒ Object
- #update ⇒ Object
-
#update_document(obj) ⇒ Object
called before the save of the document on update to do addition processes on the document beyond update_attributes.
Instance Method Details
#after_destroy_collection ⇒ Object
pulled out to allow a user to override the default redirect
54 55 56 |
# File 'app/controllers/concerns/hydra/batch_edit_behavior.rb', line 54 def after_destroy_collection redirect_to catalog_index_path end |
#after_update ⇒ Object
pulled out to allow a user to override the default redirect
25 26 27 |
# File 'app/controllers/concerns/hydra/batch_edit_behavior.rb', line 25 def after_update redirect_to catalog_index_path end |
#all ⇒ Object
45 46 47 48 49 50 51 |
# File 'app/controllers/concerns/hydra/batch_edit_behavior.rb', line 45 def all self.batch = Hyrax::Collections::SearchService.new(session, current_user.user_key).last_search_documents.map(&:id) respond_to do |format| format.html { redirect_to edit_batch_edits_path } format.js { render json: batch } end end |
#check_for_empty! ⇒ Object
67 68 69 70 71 |
# File 'app/controllers/concerns/hydra/batch_edit_behavior.rb', line 67 def check_for_empty! return unless check_for_empty_batch? redirect_back fallback_location: hyrax.batch_edits_path false end |
#destroy_collection ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'app/controllers/concerns/hydra/batch_edit_behavior.rb', line 58 def destroy_collection batch.each do |doc_id| obj = ActiveFedora::Base.find(doc_id, cast: true) obj.destroy end flash[:notice] = "Batch delete complete" after_destroy_collection end |
#edit ⇒ Object
22 |
# File 'app/controllers/concerns/hydra/batch_edit_behavior.rb', line 22 def edit; end |
#index ⇒ Object
fetch the documents that match the ids in the folder
13 14 15 |
# File 'app/controllers/concerns/hydra/batch_edit_behavior.rb', line 13 def index @response, @documents = get_solr_response_for_field_values("id", batch) end |
#state ⇒ Object
17 18 19 20 |
# File 'app/controllers/concerns/hydra/batch_edit_behavior.rb', line 17 def state session[:batch_edit_state] = params[:state] render json: { "OK" => "OK" } end |
#update ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'app/controllers/concerns/hydra/batch_edit_behavior.rb', line 35 def update batch.each do |doc_id| obj = ActiveFedora::Base.find(doc_id, cast: true) update_document(obj) obj.save end flash[:notice] = "Batch update complete" after_update end |
#update_document(obj) ⇒ Object
called before the save of the document on update to do addition processes on the document beyond update_attributes
30 31 32 33 |
# File 'app/controllers/concerns/hydra/batch_edit_behavior.rb', line 30 def update_document(obj) type = obj.class.to_s.underscore.to_sym obj.update_attributes(params[type].reject { |_k, v| v.blank? }) end |