hydra-batch-edit 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -2,7 +2,7 @@
2
2
  require "bundler/gem_tasks"
3
3
  require 'rspec/core/rake_task'
4
4
 
5
- ENV["RAILS_ROOT"] = 'spec/internal'
5
+ ENV["RAILS_ROOT"] ||= 'spec/internal'
6
6
 
7
7
  desc 'Default: run specs.'
8
8
  task :default => :spec
@@ -28,6 +28,9 @@ task :generate do
28
28
  `bundle install`
29
29
  puts "running generator"
30
30
  puts `rails generate test_app`
31
+
32
+ puts "running migrations"
33
+ puts `rake db:migrate db:test:prepare`
31
34
  FileUtils.cd('../..')
32
35
  end
33
36
  puts "Running specs"
@@ -26,4 +26,9 @@ module BatchEditHelper
26
26
  def batch_edit_select(document)
27
27
  render :partial=>'/batch_edits/add_button', :locals=>{:document=>document}
28
28
  end
29
+
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
31
+ def batch_check_all
32
+ render :partial=>'/batch_edits/check_all'
33
+ end
29
34
  end
@@ -1,17 +1,26 @@
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
- -%>
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
+ else
11
+ method = "put"
12
+ label = 'add to batch'
13
+ cssClass = "addBatch"
14
+ end
15
+ -%>
16
+
17
+ <%= form_tag(batch_edit_path(document), :method => method, :class=> "batch_toggle #{cssClass}", "data-doc-id" => document.id, "data-behavior" => 'batch-add-form', :title=>h(document[document_show_link_field])) do -%>
18
+ <%= hidden_field(:bookmark, :title, :value => document[document_show_link_field]) %>
19
+ <%= submit_tag(label, :class=>"batch_submit", :id => "batch_submit_#{document.id}") %>
20
+ <% end %>
21
+
22
+ <% else %>
23
+ <br><span class="label label-warning">You don't have edit access</label>
24
+ <% end %>
25
+ </div>
13
26
 
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,4 @@
1
+ <%= form_tag(all_batch_edits_path, :method => :put, :class=> "batch-select-all hidden", "data-behavior" => 'batch-select-all') do -%>
2
+ <%= submit_tag("Use all results", :class=>'batch-all-button btn') %>
3
+ <% end %>
4
+
@@ -1,4 +1,4 @@
1
- <div class="btn-group hidden" data-behavior="batch-tools">
1
+ <div class="btn-group batch-tools hidden" data-behavior="batch-tools">
2
2
  <button class="btn"><i class="icon-cog"></i> Tools</button>
3
3
  <button class="btn dropdown-toggle" data-toggle="dropdown">
4
4
  <span class="caret"></span>
@@ -15,6 +15,8 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = Hydra::BatchEdit::VERSION
17
17
 
18
+ gem.add_dependency 'blacklight'
19
+
18
20
  gem.add_development_dependency 'rake'
19
21
  gem.add_development_dependency 'rails'
20
22
  gem.add_development_dependency 'rspec-rails'
@@ -1,14 +1,4 @@
1
- require "hydra/batch_edit/version"
2
- require "hydra/batch_edit/routes"
3
1
  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
2
+ require "hydra/batch_edit"
3
+ require "bundler/setup"
4
+ require "blacklight"
@@ -0,0 +1,14 @@
1
+ module Hydra
2
+ module BatchEdit
3
+ extend ActiveSupport::Autoload
4
+ autoload :SearchService
5
+ autoload :Routes
6
+ autoload :Version
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
@@ -19,6 +19,7 @@ module Hydra
19
19
  put :update
20
20
  delete :clear
21
21
  put :state
22
+ put :all
22
23
  end
23
24
  end
24
25
  match 'batch_edits/:id' => 'batch_edits#add', :via=>:put
@@ -0,0 +1,50 @@
1
+ module Hydra
2
+ module BatchEdit
3
+ class SearchService
4
+ include Blacklight::Configurable
5
+ include Blacklight::SolrHelper
6
+
7
+
8
+ def initialize(session, user_key)
9
+ @session = session
10
+ @user_key = user_key
11
+ self.class.copy_blacklight_config_from(::CatalogController)
12
+ end
13
+
14
+ solr_search_params_logic << :apply_gated_search
15
+
16
+ def last_search_documents
17
+ return [] if @session[:history].blank?
18
+ last_search_id = @session[:history].first
19
+ search = Search.find(last_search_id)
20
+ result, document_list = get_search_results(search.query_params, :fl=>'id', :rows=>1000)
21
+ document_list
22
+ end
23
+
24
+ # filter that sets up access-controlled lucene query in order to provide gated search behavior
25
+ # @param solr_parameters the current solr parameters
26
+ # @param user_parameters the current user-subitted parameters
27
+ def apply_gated_search(solr_parameters, user_parameters)
28
+ solr_parameters[:fq] ||= []
29
+ # Grant access to public content
30
+ user_access_filters = []
31
+
32
+ user_access_filters << "edit_access_group_t:public"
33
+
34
+ # Grant access based on user id & role
35
+ unless @user_key.nil?
36
+ # for roles
37
+ ::RoleMapper.roles(@user_key).each_with_index do |role, i|
38
+ user_access_filters << "edit_access_group_t:#{role}"
39
+ end
40
+ # for individual person access
41
+ user_access_filters << "edit_access_person_t:#{@user_key}"
42
+ end
43
+ solr_parameters[:fq] << user_access_filters.join(" OR ")
44
+ logger.debug("Solr parameters: #{ solr_parameters.inspect }")
45
+ end
46
+
47
+ end
48
+ end
49
+ end
50
+
@@ -1,5 +1,5 @@
1
1
  module Hydra
2
2
  module BatchEdit
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
@@ -67,19 +67,29 @@ module Hydra::BatchEditBehavior
67
67
 
68
68
  end
69
69
 
70
+ def all
71
+ self.batch = Hydra::BatchEdit::SearchService.new(session, current_user.user_key).last_search_documents.map(&:id)
72
+ redirect_to edit_batch_edits_path
73
+ end
74
+
70
75
  protected
71
76
 
72
77
  def batch
73
78
  session[:batch_document_ids] ||= []
74
79
  end
75
80
 
81
+ def batch=(val)
82
+ session[:batch_document_ids] = val
83
+ end
84
+
85
+
76
86
  def clear_batch!
77
- session[:batch_document_ids] = []
87
+ self.batch = []
78
88
  end
79
89
 
80
90
  def check_for_empty!
81
91
  if batch.empty?
82
- redirect_to catalog_index_path
92
+ redirect_to :back
83
93
  return false
84
94
  end
85
95
  end
@@ -75,10 +75,12 @@ describe BatchEditsController do
75
75
  end
76
76
  before do
77
77
  controller.stub(:catalog_index_path).and_return('/catalog')
78
+ request.env["HTTP_REFERER"] = "where_i_came_from"
79
+
78
80
  end
79
81
  it "should complain when none are in the batch " do
80
82
  put :update, :multiresimage=>{:titleSet_display=>'My title' }
81
- response.should redirect_to '/catalog'
83
+ response.should redirect_to 'where_i_came_from'
82
84
  flash[:notice].should == "Select something first"
83
85
  end
84
86
  it "should not update when the user doesn't have permissions" do
@@ -87,7 +89,7 @@ describe BatchEditsController do
87
89
  controller.should_receive(:can?).with(:edit, @one.pid).and_return(false)
88
90
  controller.should_receive(:can?).with(:edit, @two.pid).and_return(false)
89
91
  put :update, :multiresimage=>{:titleSet_display=>'My title' }
90
- response.should redirect_to '/catalog'
92
+ response.should redirect_to 'where_i_came_from'
91
93
  flash[:notice].should == "You do not have permission to edit the documents: #{@one.pid}, #{@two.pid}"
92
94
  end
93
95
  describe "when current user has access to the documents" do
@@ -124,5 +126,22 @@ describe BatchEditsController do
124
126
  end
125
127
  end
126
128
 
129
+ describe "select all" do
130
+ before do
131
+ doc1 = stub(:id=>123)
132
+ doc2 = stub(:id=>456)
133
+ Hydra::BatchEdit::SearchService.any_instance.should_receive(:last_search_documents).and_return([doc1, doc2])
134
+ controller.stub(:current_user=>stub(:user_key=>'vanessa'))
135
+ end
136
+ it "should add every document in the current resultset to the batch" do
137
+ put :all
138
+ response.should redirect_to edit_batch_edits_path
139
+ session[:batch_document_ids].should == [123, 456]
140
+ end
141
+ end
142
+
143
+ describe "clear" do
144
+ it "should clear the batch"
145
+ end
127
146
 
128
147
  end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hydra::BatchEdit::SearchService do
4
+
5
+ before do
6
+ @session = {:history => [17, 14, 12, 9]}
7
+ @service = Hydra::BatchEdit::SearchService.new(@session, 'vanessa')
8
+ end
9
+
10
+ it "should get the documents for the first history entry" do
11
+ Search.should_receive(:find).with(17).and_return(Search.new(:query_params=>{:q=>"World Peace"}))
12
+ @service.should_receive(:get_search_results).and_return([:one, [:doc1, :doc2]])
13
+ @service.last_search_documents.should == [:doc1, :doc2]
14
+
15
+ end
16
+
17
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Routes for batch_update" do
4
+ it "should route index" do
5
+ { :get => '/batch_edits' }.should route_to( :controller => "batch_edits", :action => "index")
6
+ end
7
+ it "should route edit" do
8
+ { :get => edit_batch_edits_path }.should route_to( :controller => "batch_edits", :action => "edit")
9
+ end
10
+ it "should route update" do
11
+ { :put => batch_edits_path }.should route_to( :controller => "batch_edits", :action => "update")
12
+ end
13
+ it "should route add" do
14
+ { :put => '/batch_edits/7'}.should route_to( :controller => "batch_edits", :action => "add", :id=>'7')
15
+ end
16
+ it "should route delete" do
17
+ { :delete => '/batch_edits/7' }.should route_to( :controller => "batch_edits", :action => "destroy", :id=>'7')
18
+ batch_edit_path(7).should == "/batch_edits/7"
19
+ end
20
+
21
+ it "should route all" do
22
+ { :put => '/batch_edits/all'}.should route_to( :controller => "batch_edits", :action => "all")
23
+ all_batch_edits_path.should == "/batch_edits/all"
24
+ end
25
+
26
+
27
+ end
data/spec/spec_helper.rb CHANGED
@@ -7,7 +7,6 @@ require 'rspec/rails'
7
7
  require 'hydra-batch-edit'
8
8
 
9
9
 
10
-
11
10
  RSpec.configure do |config|
12
11
  config.use_transactional_fixtures = true
13
12
  end
@@ -0,0 +1,5 @@
1
+ # -*- encoding : utf-8 -*-
2
+ class SolrDocument
3
+
4
+ include Blacklight::Solr::Document
5
+ end
@@ -0,0 +1,16 @@
1
+ # -*- encoding : utf-8 -*-
2
+ class CreateSearches < ActiveRecord::Migration
3
+ def self.up
4
+ create_table :searches do |t|
5
+ t.text :query_params
6
+ t.integer :user_id
7
+
8
+ t.timestamps
9
+ end
10
+ add_index :searches, :user_id
11
+ end
12
+
13
+ def self.down
14
+ drop_table :searches
15
+ end
16
+ end
@@ -13,5 +13,7 @@ class TestAppGenerator < Rails::Generators::Base
13
13
 
14
14
  def copy_test_models
15
15
  copy_file "app/models/sample.rb"
16
+ copy_file "app/models/solr_document.rb"
17
+ copy_file "db/migrate/20111101221803_create_searches.rb"
16
18
  end
17
19
  end
@@ -1,7 +1,7 @@
1
1
  $ ->
2
2
  $("[data-behavior='batch-tools']").removeClass('hidden')
3
3
 
4
- $("[data-behavior='batch-add-button']").bl_checkbox_submit({
4
+ $("[data-behavior='batch-add-form']").bl_checkbox_submit({
5
5
  checked_label: "Selected",
6
6
  unchecked_label: "Select",
7
7
  css_class: "batch_toggle"
@@ -12,11 +12,13 @@ $ ->
12
12
  obj.find('a i').addClass('icon-ok')
13
13
  $("[data-behavior='batch-edit']").removeClass('hidden')
14
14
  $("[data-behavior='batch-add-button']").removeClass('hidden')
15
+ $("[data-behavior='batch-select-all']").removeClass('hidden')
15
16
 
16
17
  deactivate = ->
17
18
  obj.find('a i').removeClass('icon-ok')
18
19
  $("[data-behavior='batch-edit']").addClass('hidden')
19
20
  $("[data-behavior='batch-add-button']").addClass('hidden')
21
+ $("[data-behavior='batch-select-all']").addClass('hidden')
20
22
 
21
23
  if obj.attr("data-state") == 'off'
22
24
  deactivate(obj)
@@ -1,4 +1,11 @@
1
+ .batch-select-all {
2
+ display: inline;
3
+ }
1
4
  .hidden {
2
- display: none;
5
+ visibility: hidden;
3
6
 
4
7
  }
8
+ .batch-tools {
9
+ display: inline-block;
10
+ }
11
+
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.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,8 +10,24 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-06-18 00:00:00.000000000 Z
13
+ date: 2012-06-19 00:00:00.000000000 Z
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: blacklight
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
15
31
  - !ruby/object:Gem::Dependency
16
32
  name: rake
17
33
  requirement: !ruby/object:Gem::Requirement
@@ -75,6 +91,7 @@ files:
75
91
  - app/controllers/batch_edits_controller.rb
76
92
  - app/helpers/batch_edit_helper.rb
77
93
  - app/views/batch_edits/_add_button.html.erb
94
+ - app/views/batch_edits/_check_all.html.erb
78
95
  - app/views/batch_edits/_next_page.html.erb
79
96
  - app/views/batch_edits/_tools.html.erb
80
97
  - app/views/batch_edits/edit.html.erb
@@ -82,15 +99,21 @@ files:
82
99
  - config/routes.rb
83
100
  - hydra-batch-edit.gemspec
84
101
  - lib/hydra-batch-edit.rb
102
+ - lib/hydra/batch_edit.rb
85
103
  - lib/hydra/batch_edit/routes.rb
104
+ - lib/hydra/batch_edit/search_service.rb
86
105
  - lib/hydra/batch_edit/version.rb
87
106
  - lib/hydra/batch_edit_behavior.rb
88
107
  - spec/.gitignore
89
108
  - spec/controllers/batch_edits_controller_spec.rb
90
109
  - spec/helpers/batch_edit_helper_spec.rb
110
+ - spec/lib/search_service_spec.rb
111
+ - spec/routing/batch_edit_routes_spec.rb
91
112
  - spec/spec_helper.rb
92
113
  - spec/support/Gemfile
93
114
  - spec/support/app/models/sample.rb
115
+ - spec/support/app/models/solr_document.rb
116
+ - spec/support/db/migrate/20111101221803_create_searches.rb
94
117
  - spec/support/lib/generators/test_app_generator.rb
95
118
  - vendor/assets/javascripts/batch_edit.js.coffee
96
119
  - vendor/assets/stylesheets/batch_edit.css.scss
@@ -114,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
137
  version: '0'
115
138
  requirements: []
116
139
  rubyforge_project:
117
- rubygems_version: 1.8.21
140
+ rubygems_version: 1.8.24
118
141
  signing_key:
119
142
  specification_version: 3
120
143
  summary: Rails engine to do batch editing with hydra-head
@@ -122,7 +145,11 @@ test_files:
122
145
  - spec/.gitignore
123
146
  - spec/controllers/batch_edits_controller_spec.rb
124
147
  - spec/helpers/batch_edit_helper_spec.rb
148
+ - spec/lib/search_service_spec.rb
149
+ - spec/routing/batch_edit_routes_spec.rb
125
150
  - spec/spec_helper.rb
126
151
  - spec/support/Gemfile
127
152
  - spec/support/app/models/sample.rb
153
+ - spec/support/app/models/solr_document.rb
154
+ - spec/support/db/migrate/20111101221803_create_searches.rb
128
155
  - spec/support/lib/generators/test_app_generator.rb