Batch Editing Functionality for Hydra Heads
This is Alpha Software! While working on a specific Hydra Head with specific content & use cases, we added batch editing functionality. We wrote the code as a separate gem so that others can use this as a starting point, but you will have to modify the code to get this to work. If other Hydra partners start using the gem, it will become more immediately useful & configurable out of the box. At that point, someone will delete this message.
The initial code for this gem was written by MediaShelf on behalf of Northwestern University. It is used in the NWU Digital Image Library (DIL) Hydra Head. As with all Hydra code, this software is distributed under the Apache 2 License.
The main thrust of the re-usable functionality this gem aims to provide:
- Jackie User constructs a batch of objects from Blacklight/Hydra search results
- When Jackie has selected everything for the batch, she clicks a button to proceed to the next step
- (Might want to have a sanity check page here where Jackie sees all of the objects she has selected. We skipped that step for now.)
- Before displaying the next step, a before_filter in the controller makes sure Jackie has edit permissions for each of the objects, filtering out the non-editable content and notifying Jackie that they’ve been removed from her batch
- Jackie sees a form for specifying what changes to apply to the batch
- Jackie submits her changes and they are applied to each of the objects in the batch
- Before applying the submitted updates, the before_filter in the controller checks (again) that Jackie has edit permissions for everything in the batch
- The BatchUpdatesController#update method applies Jackie’s changes to each of the objects in the batch
Note As of version 1.0.0 The batches are tracke using the batches behavior in hydra-collections. They are not persisted between page changes and only exist on the current page.
Note Version 0.3.1 and previous The batches are tracked as a list of pids in the user session. They are not persisted.
In your Gemfile, add
- Run the install generator
$ rails g hydra_batch_edit:install
- Call batch_edit_tools view helper in your search result page template. We recommend putting it in catalog/_sort_and_per_page.html.erb
- Call batch_edit_continue in the search result page template. We put it in catalog/index.html
- Call batch_edit_select(document) [passing in the solr document] on the index partial that’s rendered for each search result
hydra-head curation_concerns bootstrap blacklight coffeescript & scss
This is Alpha Software These instructions assume that you know how to work with rails and are familiar with Hydra
What you will need to do
You will definitely need to override the edit form. `app/views/batch_edits/edit.html.erb` You will probably need to override BatchEditController#update You might need to override BatchEditController#edit
Extend Hydra::BatchEditController update and/or edit methods
class BatchEditController < ApplicationController include :: def update batch.each do |doc_id| obj = ActiveFedora::Base.find(doc_id, :cast=>true) type = obj.class.to_s.underscore.to_sym obj.update_attributes(params[type]) obj.do_something_special obj.save end flash[:notice] = "Batch update complete" clear_batch! redirect_to catalog_index_path end end
Override Edit View
<%= form_for MyModel.new, :url=>batch_edit_path, :method=>:put do |f| %> <%= f.label :title, "Title:" %> <%= f.text_field :title %> <%= f.label :description, "Description:" %> <%= f.text_field :description %> <%= f.label :license, "License:" %> <%= f.text_field :license %> <%= f.label :access_policy, "Access Policy:" %> <%= f.select :access_policy, ... %> <%# note the class submits-batches causes the batch ids to be returned with the updates %> <%= f.submit "Save changes", :class=>'submits-batches btn btn-primary'%> <% end %>