hydra-batch-edit 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
19
+
20
+ *.swp
21
+ *.swo
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hydra-batch-edit.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,14 @@
1
+ ##########################################################################
2
+ # Copyright 2012 Northwestern University Libraries and MediaShelf, LLC
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
data/README.textile ADDED
@@ -0,0 +1,114 @@
1
+ h1. hydra-batch-edit
2
+
3
+ Batch Editing Functionality for Hydra Heads
4
+
5
+ *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.
6
+
7
+ As far as we can tell, the code is sufficiently "test-coveraged" and html/javascript is "fall-backable".
8
+
9
+ The initial code for this gem was written by "MediaShelf":http://yourmediashelf.com 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":http://www.apache.org/licenses/LICENSE-2.0.
10
+
11
+ h2. Features
12
+
13
+ The main thrust of the re-usable functionality this gem aims to provide:
14
+
15
+ # Jackie User constructs a batch of objects from Blacklight/Hydra search results
16
+ # When Jackie has selected everything for the batch, she clicks a button to proceed to the next step
17
+ # (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.)
18
+ # 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
19
+ # Jackie sees a form for specifying what changes to apply to the batch
20
+ # Jackie submits her changes and they are applied to each of the objects in the batch
21
+ # Before applying the submitted updates, the before_filter in the controller checks (again) that Jackie has edit permissions for everything in the batch
22
+ # The BatchUpdatesController#update method applies Jackie's changes to each of the objects in the batch
23
+
24
+ *Note* The batches are tracked as a list of pids _in the user session_. They are not persisted.
25
+
26
+ h2. Installing
27
+
28
+ In your Gemfile, add
29
+
30
+ <pre>gem 'hydra-batch-edit'</pre>
31
+
32
+ # Call batch_edit_tools view helper in your search result page template. We recommend putting it in catalog/_sort_and_per_page.html.erb
33
+ # Call batch_edit_continue in the search result page template. We put it in catalog/index.html
34
+ # Call batch_edit_select(document) [passing in the solr document] on the index partial that's rendered for each search result
35
+ # Add routes to config/routes.rb
36
+ <pre>
37
+ Hydra::BatchEdit.add_routes(self)
38
+ </pre>
39
+ # Add javascript to app/assets/javascripts/application.js
40
+ <pre>
41
+ //= require batch_edit
42
+ </pre>
43
+ # Add css to app/assets/stylesheets/application.css
44
+ <pre>
45
+ *= require batch_edit
46
+ </pre>
47
+
48
+
49
+
50
+
51
+ h2. Dependencies
52
+
53
+ hydra-head
54
+ bootstrap
55
+ blacklight.js
56
+ coffeescript & scss
57
+
58
+
59
+ h2. Customizing
60
+
61
+ *This is Alpha Software* These instructions assume that you know how to work with rails and are familiar with Hydra
62
+
63
+ h3. What you will need to do
64
+
65
+ You will *definitely* need to override the edit form.
66
+ You will probably need to override BatchEditController#update
67
+ You might need to override BatchEditController#edit
68
+
69
+ h3. Extend Hydra::BatchEditController update and/or edit methods
70
+
71
+ Example app/controllers/batch_updates_controller.rb
72
+
73
+ <pre>
74
+ class BatchEditController < ApplicationController
75
+ include Hydra::BatchEditBehavior
76
+ def update
77
+ batch.each do |doc_id|
78
+ obj = ActiveFedora::Base.find(doc_id, :cast=>true)
79
+ type = obj.class.to_s.underscore.to_sym
80
+ obj.update_attributes(params[type])
81
+ obj.do_something_special
82
+ obj.save
83
+ end
84
+ flash[:notice] = "Batch update complete"
85
+ clear_batch!
86
+ redirect_to catalog_index_path
87
+ end
88
+ end
89
+ </pre>
90
+
91
+ h3. Override Edit View
92
+
93
+ Example app/views/batch_edit/edit.html.erb
94
+
95
+ <pre>
96
+ <%= form_for MyModel.new, :url=>batch_edit_path, :method=>:put do |f| %>
97
+
98
+ <%= f.label :title, "Title:" %>
99
+ <%= f.text_field :title %>
100
+
101
+ <%= f.label :description, "Description:" %>
102
+ <%= f.text_field :description %>
103
+
104
+ <%= f.label :license, "License:" %>
105
+ <%= f.text_field :license %>
106
+
107
+ <%= f.label :access_policy, "Access Policy:" %>
108
+ <%= f.select :access_policy, ... %>
109
+
110
+ <%= f.submit "Save changes", :class=>'btn btn-primary'%>
111
+
112
+ <% end %>
113
+ </pre>
114
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,4 @@
1
+ class BatchEditsController < ApplicationController
2
+ include Hydra::BatchEditBehavior
3
+ end
4
+
@@ -0,0 +1,29 @@
1
+ # View Helpers for Hydra Batch Edit functionality
2
+ module BatchEditHelper
3
+
4
+ # determines if the given document id is in the batch
5
+ def item_in_batch?(doc_id)
6
+ session[:batch_document_ids] && session[:batch_document_ids].include?(doc_id) ? true : false
7
+ end
8
+
9
+ # Returns true if user has activated batch edit mode in session
10
+ def batch_edit_active?
11
+ session[:batch_edit_state] == 'on'
12
+ end
13
+
14
+ # Displays the batch edit tools. Put this in your search result page template. We recommend putting it in catalog/_sort_and_per_page.html.erb
15
+ def batch_edit_tools
16
+ render :partial=>'/batch_edits/tools'
17
+ end
18
+
19
+ # Displays the button that users click when they are done selecting items for a batch. Put this in your search result page template. We put it in catalog/index.html
20
+ def batch_edit_continue
21
+ render :partial => '/batch_edits/next_page'
22
+ end
23
+
24
+ # Displays the button to select/deselect items for your batch. Call this in the index partial that's rendered for each search result.
25
+ # @param [Hash] document the Hash (aka Solr hit) for one Solr document
26
+ def batch_edit_select(document)
27
+ render :partial=>'/batch_edits/add_button', :locals=>{:document=>document}
28
+ end
29
+ end
@@ -0,0 +1,17 @@
1
+ <%-
2
+ # pass in local :document with a SolrDocument
3
+ if item_in_batch?(document.id)
4
+ method = "delete"
5
+ label = 'remove from batch'
6
+ cssClass = "deleteBatch"
7
+ else
8
+ method = "put"
9
+ label = 'add to batch'
10
+ cssClass = "addBatch"
11
+ end
12
+ -%>
13
+
14
+ <%= form_tag(batch_edit_path(document), :method => method, :class=> "batch_toggle #{cssClass} hidden", "data-doc-id" => document.id, "data-behavior" => 'batch-add-button', :title=>h(document[document_show_link_field])) do -%>
15
+ <%= hidden_field(:bookmark, :title, :value => document[document_show_link_field]) %>
16
+ <%= submit_tag(label, :class=>"batch_submit", :id => "batch_submit_#{document.id}") %>
17
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= button_to "Update Selected", edit_batch_edits_path, :method=>:get, :class=>"btn btn-primary hidden", 'data-behavior'=>'batch-edit', :id=>'batch-edit' %>
@@ -0,0 +1,10 @@
1
+ <div class="btn-group hidden" data-behavior="batch-tools">
2
+ <button class="btn"><i class="icon-cog"></i> Tools</button>
3
+ <button class="btn dropdown-toggle" data-toggle="dropdown">
4
+ <span class="caret"></span>
5
+ </button>
6
+ <ul class="dropdown-menu">
7
+ <li data-behavior="batch-edit-activate" data-state="off"><a href="#"><i class=""></i> Batch edit</a></li>
8
+ </ul>
9
+ </div>
10
+
@@ -0,0 +1,26 @@
1
+ <%= form_for Multiresimage.new, :url=>batch_edits_path, :method=>:put do |f| %>
2
+
3
+ <div class="control-group">
4
+ <%= f.label :titleSet_display, "Title:" %>
5
+ <div class="controls">
6
+ <%= f.text_field :titleSet_display %>
7
+ </div>
8
+ </div>
9
+ <div class="control-group">
10
+ <%= f.label :agentSet_display, "Agent:" %>
11
+ <div class="controls">
12
+ <%= f.text_field :agentSet_display %>
13
+ </div>
14
+ </div>
15
+ <div class="control-group">
16
+ <%= f.label :dateSet_display, "Date:" %>
17
+ <div class="controls">
18
+ <%= f.text_field :dateSet_display %>
19
+ </div>
20
+ </div>
21
+
22
+ <div class="form-actions">
23
+ <%= f.submit "Save changes", :class=>'btn btn-primary'%>
24
+ </div>
25
+
26
+ <% end %>
@@ -0,0 +1,2 @@
1
+ Yo:w
2
+
data/config/routes.rb ADDED
@@ -0,0 +1,15 @@
1
+ Hydra::BatchEdit::Engine.routes.draw do
2
+ ###NOTE this isn't used
3
+
4
+ match 'batch_edits/:id' => 'batch_edits#add', :via=>:put
5
+ resources :batch_edits, :only=>[:index] do
6
+ member do
7
+ delete :destroy
8
+ end
9
+ collection do
10
+ get :edit
11
+ put :update
12
+ delete :clear
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/hydra/batch_edit/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Justin Coyne", "Matt Zumwalt"]
6
+ gem.email = ["justin.coyne@yourmediashelf.com"]
7
+ gem.description = %q{Rails engine to do batch editing with hydra-head}
8
+ gem.summary = %q{Rails engine to do batch editing with hydra-head}
9
+ gem.homepage = "https://github.com/projecthydra/hydra-batch-edit"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "hydra-batch-edit"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Hydra::BatchEdit::VERSION
17
+ end
@@ -0,0 +1,14 @@
1
+ require "hydra/batch_edit/version"
2
+ require "hydra/batch_edit/routes"
3
+ require "hydra/batch_edit_behavior"
4
+
5
+ module Hydra
6
+ module BatchEdit
7
+ def self.add_routes(router, options = {})
8
+ Routes.new(router, options).draw
9
+ end
10
+ class Engine < ::Rails::Engine
11
+ # Make rails look at the vendored assets
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,35 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module Hydra
3
+ module BatchEdit
4
+ class Routes
5
+
6
+ def initialize(router, options)
7
+ @router = router
8
+ @options = options
9
+ end
10
+
11
+ def draw
12
+ add_routes do |options|
13
+ match 'batch_edits/:id' => 'batch_edits#add', :via=>:put
14
+ resources :batch_edits, :only=>[:index] do
15
+ member do
16
+ delete :destroy
17
+ end
18
+ collection do
19
+ get :edit
20
+ put :update
21
+ delete :clear
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ protected
28
+
29
+ def add_routes &blk
30
+ @router.instance_exec(@options, &blk)
31
+ end
32
+ end
33
+ end
34
+ end
35
+
@@ -0,0 +1,5 @@
1
+ module Hydra
2
+ module BatchEdit
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,102 @@
1
+ module Hydra::BatchEditBehavior
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ before_filter :filter_docs_with_access!, :only=>[:edit, :update]
6
+ before_filter :check_for_empty!, :only=>[:edit, :update]
7
+ end
8
+
9
+
10
+ # fetch the documents that match the ids in the folder
11
+ def index
12
+ @response, @documents = get_solr_response_for_field_values("id", batch)
13
+ end
14
+
15
+ def state
16
+ session[:batch_edit_state] = params[:state]
17
+ render :json => {"OK" => "OK"}
18
+ end
19
+
20
+ # add a document_id to the batch. :id of action is solr doc id
21
+ def add
22
+ batch << params[:id]
23
+ respond_to do |format|
24
+ format.html do
25
+ redirect_to :back, :notice => "#{params[:title] || "Item"} successfully added to batch"
26
+ end
27
+ format.js { render :json => batch }
28
+ end
29
+ end
30
+
31
+ # remove a document_id from the batch. :id of action is solr_doc_id
32
+ def destroy
33
+ batch.delete(params[:id])
34
+ respond_to do |format|
35
+ format.html do
36
+ redirect_to :back, :notice => "#{params[:title] || "Item"} successfully removed from batch"
37
+ end
38
+ format.js do
39
+ render :json => {"OK" => "OK"}
40
+ end
41
+ end
42
+
43
+ end
44
+
45
+ # get rid of the items in the batch
46
+ def clear
47
+ clear_batch!
48
+ respond_to do |format|
49
+ format.html { redirect_to :back, :notice=> "Batch has been cleared" }
50
+ format.js { render :json => batch }
51
+ end
52
+ end
53
+
54
+ def edit
55
+ end
56
+
57
+ def update
58
+ batch.each do |doc_id|
59
+ obj = ActiveFedora::Base.find(doc_id, :cast=>true)
60
+ type = obj.class.to_s.underscore.to_sym
61
+ obj.update_attributes(params[type])
62
+ obj.save
63
+ end
64
+ flash[:notice] = "Batch update complete"
65
+ clear_batch!
66
+ redirect_to catalog_index_path
67
+
68
+ end
69
+
70
+ protected
71
+
72
+ def batch
73
+ session[:batch_document_ids] ||= []
74
+ end
75
+
76
+ def clear_batch!
77
+ session[:batch_document_ids] = []
78
+ end
79
+
80
+ def check_for_empty!
81
+ if batch.empty?
82
+ redirect_to catalog_index_path
83
+ return false
84
+ end
85
+ end
86
+
87
+ def filter_docs_with_access!
88
+ no_permissions = []
89
+ if batch.empty?
90
+ flash[:notice] = "Select something first"
91
+ else
92
+ batch.dup.each do |doc_id|
93
+ unless can?(:edit, doc_id)
94
+ session[:batch_document_ids].delete(doc_id)
95
+ no_permissions << doc_id
96
+ end
97
+ end
98
+ flash[:notice] = "You do not have permission to edit the documents: #{no_permissions.join(', ')}" unless no_permissions.empty?
99
+ end
100
+ end
101
+
102
+ end
@@ -0,0 +1,23 @@
1
+ $ ->
2
+ $("[data-behavior='batch-tools']").removeClass('hidden')
3
+
4
+ $("[data-behavior='batch-add-button']").bl_checkbox_submit({
5
+ checked_label: "Selected",
6
+ unchecked_label: "Select",
7
+ css_class: "batch_toggle"
8
+ })
9
+
10
+ $("[data-behavior='batch-edit-activate']").click (e) ->
11
+ e.preventDefault()
12
+ if $(this).attr("data-state") == 'off'
13
+ $(this).attr("data-state", 'on')
14
+ $(this).find('a i').addClass('icon-ok')
15
+ $("[data-behavior='batch-edit']").removeClass('hidden')
16
+ $("[data-behavior='batch-add-button']").removeClass('hidden')
17
+ else
18
+ $(this).attr("data-state", 'off')
19
+ $(this).find('a i').removeClass('icon-ok')
20
+ $("[data-behavior='batch-edit']").addClass('hidden')
21
+ $("[data-behavior='batch-add-button']").addClass('hidden')
22
+ # TODO check-all
23
+
@@ -0,0 +1,4 @@
1
+ #batch-edit {
2
+ clear: all;
3
+ display: block;
4
+ }
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hydra-batch-edit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Justin Coyne
9
+ - Matt Zumwalt
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-06-15 00:00:00.000000000 Z
14
+ dependencies: []
15
+ description: Rails engine to do batch editing with hydra-head
16
+ email:
17
+ - justin.coyne@yourmediashelf.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gitignore
23
+ - Gemfile
24
+ - LICENSE
25
+ - README.textile
26
+ - Rakefile
27
+ - app/controllers/batch_edits_controller.rb
28
+ - app/helpers/batch_edit_helper.rb
29
+ - app/views/batch_edits/_add_button.html.erb
30
+ - app/views/batch_edits/_next_page.html.erb
31
+ - app/views/batch_edits/_tools.html.erb
32
+ - app/views/batch_edits/edit.html.erb
33
+ - app/views/batch_edits/index.html.erb
34
+ - config/routes.rb
35
+ - hydra-batch-edit.gemspec
36
+ - lib/hydra-batch-edit.rb
37
+ - lib/hydra/batch_edit/routes.rb
38
+ - lib/hydra/batch_edit/version.rb
39
+ - lib/hydra/batch_edit_behavior.rb
40
+ - vendor/assets/javascripts/batch_edit.js.coffee
41
+ - vendor/assets/stylesheets/batch_edit.css.scss
42
+ homepage: https://github.com/projecthydra/hydra-batch-edit
43
+ licenses: []
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 1.8.24
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: Rails engine to do batch editing with hydra-head
66
+ test_files: []