Skip to content

samvera-deprecated/hydra-batch-edit

Repository files navigation

hydra-batch-edit

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.

As far as we can tell, the code is sufficiently “test-coveraged” and html/javascript is “fall-backable”.

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.

Features

The main thrust of the re-usable functionality this gem aims to provide:

  1. Jackie User constructs a batch of objects from Blacklight/Hydra search results
  2. When Jackie has selected everything for the batch, she clicks a button to proceed to the next step
  3. (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.)
  4. 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
  5. Jackie sees a form for specifying what changes to apply to the batch
  6. Jackie submits her changes and they are applied to each of the objects in the batch
  7. Before applying the submitted updates, the before_filter in the controller checks (again) that Jackie has edit permissions for everything in the batch
  8. 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.

Installing

In your Gemfile, add

gem 'hydra-batch-edit'
  1. Run the install generator

    $ rails g hydra_batch_edit:install
  1. Call batch_edit_tools view helper in your search result page template. We recommend putting it in catalog/_sort_and_per_page.html.erb
  2. Call batch_edit_continue in the search result page template. We put it in catalog/index.html
  3. Call batch_edit_select(document) [passing in the solr document] on the index partial that’s rendered for each search result

Dependencies

hydra-head
curation_concerns
bootstrap
blacklight
coffeescript & scss

Customizing

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

Example app/controllers/batch_updates_controller.rb

  class BatchEditController < ApplicationController
    include Hydra::BatchEditBehavior
    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

Example app/views/batch_edits/edit.html.erb

  <%= 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 %>

About

[DEPRECATED] Batch Editing Functionality for Hydra Heads

Resources

License

Stars

Watchers

Forks

Packages

No packages published