Giter VIP home page Giter VIP logo

hydra-batch-edit's Introduction

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. 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
  4. Add routes to config/routes.rb

    Hydra::BatchEdit.add_routes(self)
  5. Add javascript to app/assets/javascripts/application.js

    //= require batch_edit
  6. Add css to app/assets/stylesheets/application.css
  7. require batch_edit

Dependencies

hydra-head
hydra-collections
bootstrap
blacklight.js
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 %>

hydra-batch-edit's People

Contributors

jcoyne avatar carolyncole avatar mjgiarlo avatar flyingzumwalt avatar jeremyf avatar

Watchers

Brian Maddy avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.