hydra-batch-edit 0.3.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.textile +6 -2
- data/app/helpers/batch_edit_helper.rb +1 -1
- data/app/views/batch_edits/_delete_batch.html.erb +1 -1
- data/app/views/batch_edits/_next_page.html.erb +1 -1
- data/app/views/batch_edits/edit.html.erb +1 -1
- data/hydra-batch-edit.gemspec +1 -0
- data/lib/hydra/batch_edit/version.rb +1 -1
- data/lib/hydra/batch_edit_behavior.rb +9 -78
- data/spec/controllers/batch_edits_controller_spec.rb +7 -58
- data/spec/support/Gemfile +1 -1
- metadata +16 -3
- data/app/views/batch_edits/_add_button.html.erb +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17d99ad991e18d8fd90baa75468017f65496ece8
|
4
|
+
data.tar.gz: 14778625a5af06ca4abeb453207a59fb13aa5947
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f041d1f2f3b7b86a656a728898fcbb15eebb31883200d709a31badc40b87ed53daab06b1f98af22612c8f9766e7b34a9cf3e990aa36cf51f1a692608ae3e065f
|
7
|
+
data.tar.gz: af4af94ac779069f2cba5d00d446a330d55e2ec37e34d71c8d4274f8f39b09b3d7cddf22acb5acd4748f31b630473ecf5f91dcf2bcf2c9dc8933a9b1a54feaa2
|
data/README.textile
CHANGED
@@ -21,7 +21,9 @@ The main thrust of the re-usable functionality this gem aims to provide:
|
|
21
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
22
|
# The BatchUpdatesController#update method applies Jackie's changes to each of the objects in the batch
|
23
23
|
|
24
|
-
*Note* The batches are
|
24
|
+
*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.
|
25
|
+
|
26
|
+
*Note* Version 0.3.1 and previous The batches are tracked as a list of pids _in the user session_. They are not persisted.
|
25
27
|
|
26
28
|
h2. Installing
|
27
29
|
|
@@ -51,6 +53,7 @@ In your Gemfile, add
|
|
51
53
|
h2. Dependencies
|
52
54
|
|
53
55
|
hydra-head
|
56
|
+
hydra-collections
|
54
57
|
bootstrap
|
55
58
|
blacklight.js
|
56
59
|
coffeescript & scss
|
@@ -107,7 +110,8 @@ Example app/views/batch_edit/edit.html.erb
|
|
107
110
|
<%= f.label :access_policy, "Access Policy:" %>
|
108
111
|
<%= f.select :access_policy, ... %>
|
109
112
|
|
110
|
-
|
113
|
+
<%# note the class submits-batches causes the batch ids to be returned with the updates %>
|
114
|
+
<%= f.submit "Save changes", :class=>'submits-batches btn btn-primary'%>
|
111
115
|
|
112
116
|
<% end %>
|
113
117
|
</pre>
|
@@ -24,7 +24,7 @@ module BatchEditHelper
|
|
24
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
25
|
# @param [Hash] document the Hash (aka Solr hit) for one Solr document
|
26
26
|
def batch_edit_select(document)
|
27
|
-
|
27
|
+
return button_for_add_to_batch document
|
28
28
|
end
|
29
29
|
|
30
30
|
# Displays the check all button to select/deselect items for your batch. Put this in your search result page template. We put it in catalog/index.html
|
@@ -1 +1 @@
|
|
1
|
-
<%= button_to label, batch_edit, :confirm => confirm, :method=>:delete, :class=>"btn btn-primary btn-delete hidden", 'data-behavior'=>'batch-edit', :id=>'batch-edit-delete' %>
|
1
|
+
<%= button_to label, batch_edit, :confirm => confirm, :method=>:delete, :class=>"btn btn-primary btn-delete hidden submits-batches", 'data-behavior'=>'batch-edit', :id=>'batch-edit-delete' %>
|
@@ -1 +1 @@
|
|
1
|
-
<%= button_to label, edit_batch_edits_path, :method=>:get, :class=>"btn btn-update btn-primary hidden", 'data-behavior'=>'batch-edit', :id=>'batch-edit' %>
|
1
|
+
<%= button_to label, edit_batch_edits_path, :method=>:get, :class=>"btn btn-update btn-primary hidden submits-batches", 'data-behavior'=>'batch-edit', :id=>'batch-edit' %>
|
data/hydra-batch-edit.gemspec
CHANGED
@@ -1,13 +1,16 @@
|
|
1
|
+
require 'hydra/collections'
|
2
|
+
|
1
3
|
module Hydra
|
2
4
|
module BatchEditBehavior
|
3
5
|
extend ActiveSupport::Concern
|
4
6
|
|
5
7
|
included do
|
8
|
+
include Hydra::Collections::AcceptsBatches
|
9
|
+
|
6
10
|
before_filter :filter_docs_with_access!, :only=>[:edit, :update, :destroy_collection]
|
7
11
|
before_filter :check_for_empty!, :only=>[:edit, :update, :destroy_collection]
|
8
12
|
end
|
9
13
|
|
10
|
-
|
11
14
|
# fetch the documents that match the ids in the folder
|
12
15
|
def index
|
13
16
|
@response, @documents = get_solr_response_for_field_values("id", batch)
|
@@ -18,45 +21,9 @@ module Hydra
|
|
18
21
|
render :json => {"OK" => "OK"}
|
19
22
|
end
|
20
23
|
|
21
|
-
# add a document_id to the batch. :id of action is solr doc id
|
22
|
-
def add
|
23
|
-
id = params[:id]
|
24
|
-
raise "Too many items in batch!" if ((batch.to_s.length+id.to_s.length) > 2200) # we are going to overflow our cookie
|
25
|
-
batch << id if ! batch.include? id
|
26
|
-
respond_to do |format|
|
27
|
-
format.html do
|
28
|
-
redirect_to :back, :notice => "#{params[:title] || "Item"} successfully added to batch"
|
29
|
-
end
|
30
|
-
format.js { render :json => batch }
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
# remove a document_id from the batch. :id of action is solr_doc_id
|
35
|
-
def destroy
|
36
|
-
batch.delete(params[:id])
|
37
|
-
respond_to do |format|
|
38
|
-
format.html do
|
39
|
-
redirect_to :back, :notice => "#{params[:title] || "Item"} successfully removed from batch"
|
40
|
-
end
|
41
|
-
format.js do
|
42
|
-
render :json => {"OK" => "OK"}
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
# get rid of the items in the batch
|
49
|
-
def clear
|
50
|
-
clear_batch!
|
51
|
-
respond_to do |format|
|
52
|
-
format.html { redirect_to :back, :notice=> "Batch has been cleared" }
|
53
|
-
format.js { render :json => batch }
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
24
|
def edit
|
58
25
|
end
|
59
|
-
|
26
|
+
|
60
27
|
#pulled out to allow a user to override the default redirect
|
61
28
|
def after_update
|
62
29
|
redirect_to catalog_index_path
|
@@ -75,7 +42,6 @@ module Hydra
|
|
75
42
|
obj.save
|
76
43
|
end
|
77
44
|
flash[:notice] = "Batch update complete"
|
78
|
-
clear_batch!
|
79
45
|
after_update
|
80
46
|
end
|
81
47
|
|
@@ -98,48 +64,13 @@ module Hydra
|
|
98
64
|
obj.destroy
|
99
65
|
end
|
100
66
|
flash[:notice] = "Batch delete complete"
|
101
|
-
clear_batch!
|
102
67
|
after_destroy_collection
|
103
68
|
end
|
104
|
-
|
105
|
-
def check_for_empty?
|
106
|
-
return batch.empty?
|
107
|
-
end
|
108
|
-
|
109
|
-
protected
|
110
|
-
|
111
|
-
def batch
|
112
|
-
session[:batch_document_ids] ||= []
|
113
|
-
end
|
114
|
-
|
115
|
-
def batch=(val)
|
116
|
-
session[:batch_document_ids] = val
|
117
|
-
end
|
118
|
-
|
119
|
-
|
120
|
-
def clear_batch!
|
121
|
-
self.batch = []
|
122
|
-
end
|
123
|
-
|
124
|
-
def check_for_empty!
|
125
|
-
if batch.empty?
|
126
|
-
redirect_to :back
|
127
|
-
return false
|
128
|
-
end
|
129
|
-
end
|
130
69
|
|
131
|
-
def
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
else
|
136
|
-
batch.dup.each do |doc_id|
|
137
|
-
unless can?(:edit, doc_id)
|
138
|
-
session[:batch_document_ids].delete(doc_id)
|
139
|
-
no_permissions << doc_id
|
140
|
-
end
|
141
|
-
end
|
142
|
-
flash[:notice] = "You do not have permission to edit the documents: #{no_permissions.join(', ')}" unless no_permissions.empty?
|
70
|
+
def check_for_empty!
|
71
|
+
if check_for_empty_batch?
|
72
|
+
redirect_to :back
|
73
|
+
return false
|
143
74
|
end
|
144
75
|
end
|
145
76
|
|
@@ -13,52 +13,6 @@ describe BatchEditsController do
|
|
13
13
|
it "should respond to after_delete" do
|
14
14
|
controller.respond_to? "after_delete"
|
15
15
|
end
|
16
|
-
it "should add items to list" do
|
17
|
-
@mock_response = mock()
|
18
|
-
@mock_document = mock()
|
19
|
-
@mock_document2 = mock()
|
20
|
-
@mock_document.stub(:export_formats => {})
|
21
|
-
controller.stub(:get_solr_response_for_field_values => [@mock_response, [@mock_document, @mock_document2]])
|
22
|
-
|
23
|
-
put :add, :id =>"77826928"
|
24
|
-
session[:batch_document_ids].length.should == 1
|
25
|
-
put :add, :id => "94120425"
|
26
|
-
session[:batch_document_ids].length.should == 2
|
27
|
-
session[:batch_document_ids].should include("77826928")
|
28
|
-
get :index
|
29
|
-
assigns[:documents].length.should == 2
|
30
|
-
assigns[:documents].first.should == @mock_document
|
31
|
-
end
|
32
|
-
it "should delete an item from list" do
|
33
|
-
put :add, :id =>"77826928"
|
34
|
-
put :add, :id => "94120425"
|
35
|
-
delete :destroy, :id =>"77826928"
|
36
|
-
session[:batch_document_ids].length.should == 1
|
37
|
-
session[:batch_document_ids].should_not include("77826928")
|
38
|
-
end
|
39
|
-
it "should clear list" do
|
40
|
-
put :add, :id =>"77826928"
|
41
|
-
put :add, :id => "94120425"
|
42
|
-
put :clear
|
43
|
-
session[:batch_document_ids].length.should == 0
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should generate flash messages for normal requests" do
|
47
|
-
put :add, :id => "77826928"
|
48
|
-
flash[:notice].length.should_not == 0
|
49
|
-
end
|
50
|
-
it "should clear flash messages after xhr request" do
|
51
|
-
xhr :put, :add, :id => "77826928"
|
52
|
-
flash[:notice].should == nil
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should check for empty" do
|
56
|
-
put :add, :id =>"77826928"
|
57
|
-
put :add, :id => "94120425"
|
58
|
-
controller.check_for_empty?.should == false
|
59
|
-
put :clear
|
60
|
-
controller.check_for_empty?.should == true
|
61
|
-
end
|
62
16
|
|
63
17
|
describe "edit" do
|
64
18
|
before do
|
@@ -68,8 +22,7 @@ describe BatchEditsController do
|
|
68
22
|
@two.save
|
69
23
|
end
|
70
24
|
it "should draw the form" do
|
71
|
-
|
72
|
-
put :add, :id =>@two.pid
|
25
|
+
controller.batch = [@one.pid, @two.pid]
|
73
26
|
controller.should_receive(:can?).with(:edit, @one.pid).and_return(true)
|
74
27
|
controller.should_receive(:can?).with(:edit, @two.pid).and_return(true)
|
75
28
|
get :edit
|
@@ -95,8 +48,7 @@ describe BatchEditsController do
|
|
95
48
|
flash[:notice].should == "Select something first"
|
96
49
|
end
|
97
50
|
it "should not update when the user doesn't have permissions" do
|
98
|
-
|
99
|
-
put :add, :id => @two.pid
|
51
|
+
controller.batch = [@one.pid, @two.pid]
|
100
52
|
controller.should_receive(:can?).with(:edit, @one.pid).and_return(false)
|
101
53
|
controller.should_receive(:can?).with(:edit, @two.pid).and_return(false)
|
102
54
|
put :update, :multiresimage=>{:titleSet_display=>'My title' }
|
@@ -107,8 +59,7 @@ describe BatchEditsController do
|
|
107
59
|
before do
|
108
60
|
@one.save
|
109
61
|
@two.save
|
110
|
-
|
111
|
-
put :add, :id => @two.pid
|
62
|
+
controller.batch = [@one.pid, @two.pid]
|
112
63
|
controller.should_receive(:can?).with(:edit, @one.pid).and_return(true)
|
113
64
|
controller.should_receive(:can?).with(:edit, @two.pid).and_return(true)
|
114
65
|
ActiveFedora::Base.should_receive(:find).with( @one.pid, :cast=>true).and_return(@one)
|
@@ -145,8 +96,7 @@ describe BatchEditsController do
|
|
145
96
|
flash[:notice].should == "Select something first"
|
146
97
|
end
|
147
98
|
it "should not update when the user doesn't have permissions" do
|
148
|
-
|
149
|
-
put :add, :id => @two.pid
|
99
|
+
controller.batch = [@one.pid, @two.pid]
|
150
100
|
controller.should_receive(:can?).with(:edit, @one.pid).and_return(false)
|
151
101
|
controller.should_receive(:can?).with(:edit, @two.pid).and_return(false)
|
152
102
|
delete :destroy_collection
|
@@ -157,8 +107,7 @@ describe BatchEditsController do
|
|
157
107
|
before do
|
158
108
|
@one.save
|
159
109
|
@two.save
|
160
|
-
|
161
|
-
put :add, :id => @two.pid
|
110
|
+
controller.batch = [@one.pid, @two.pid]
|
162
111
|
controller.should_receive(:can?).with(:edit, @one.pid).and_return(true)
|
163
112
|
controller.should_receive(:can?).with(:edit, @two.pid).and_return(true)
|
164
113
|
ActiveFedora::Base.should_receive(:find).with( @one.pid, :cast=>true).and_return(@one)
|
@@ -197,12 +146,12 @@ describe BatchEditsController do
|
|
197
146
|
it "should add every document in the current resultset to the batch" do
|
198
147
|
put :all
|
199
148
|
response.should redirect_to edit_batch_edits_path
|
200
|
-
|
149
|
+
controller.batch = [123, 456]
|
201
150
|
end
|
202
151
|
it "ajax should add every document in the current resultset to the batch but not redirect" do
|
203
152
|
xhr :put, :all
|
204
153
|
response.should_not redirect_to edit_batch_edits_path
|
205
|
-
|
154
|
+
controller.batch = [123, 456]
|
206
155
|
end
|
207
156
|
end
|
208
157
|
|
data/spec/support/Gemfile
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hydra-batch-edit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Coyne
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: blacklight
|
@@ -25,6 +25,20 @@ dependencies:
|
|
25
25
|
- - '>='
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: hydra-collections
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
28
42
|
- !ruby/object:Gem::Dependency
|
29
43
|
name: rake
|
30
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -83,7 +97,6 @@ files:
|
|
83
97
|
- app/assets/stylesheets/batch_edit.css.scss
|
84
98
|
- app/controllers/batch_edits_controller.rb
|
85
99
|
- app/helpers/batch_edit_helper.rb
|
86
|
-
- app/views/batch_edits/_add_button.html.erb
|
87
100
|
- app/views/batch_edits/_check_all.html.erb
|
88
101
|
- app/views/batch_edits/_delete_batch.html.erb
|
89
102
|
- app/views/batch_edits/_next_page.html.erb
|
@@ -1,28 +0,0 @@
|
|
1
|
-
<div data-behavior="batch-add-button">
|
2
|
-
<% if can? :edit, document.id %>
|
3
|
-
|
4
|
-
<%-
|
5
|
-
# pass in local :document with a SolrDocument
|
6
|
-
if item_in_batch?(document.id)
|
7
|
-
method = :delete
|
8
|
-
label = 'remove from batch'
|
9
|
-
cssClass = "deleteBatch"
|
10
|
-
action = "destroy"
|
11
|
-
else
|
12
|
-
method = :put
|
13
|
-
label = 'add to batch'
|
14
|
-
cssClass = "addBatch"
|
15
|
-
action = "add"
|
16
|
-
end
|
17
|
-
-%>
|
18
|
-
|
19
|
-
<%= form_tag({:controller => "batch_edits", :action => action, :id => document.id}, :method => method, :class=> "batch_toggle #{cssClass}", "data-doc-id" => document.id, "data-behavior" => 'batch-add-form', :title=>h(document[document_show_link_field])) do -%>
|
20
|
-
<%= hidden_field(:bookmark, :title, :value => document[document_show_link_field]) %>
|
21
|
-
<%= submit_tag(label, :class=>"batch_submit", :id => "batch_submit_#{document.id}") %>
|
22
|
-
<% end %>
|
23
|
-
|
24
|
-
<% else %>
|
25
|
-
<br><span class="label label-warning">You don't have edit access</label>
|
26
|
-
<% end %>
|
27
|
-
</div>
|
28
|
-
|