hydra-collections 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.gitmodules +4 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +16 -0
  7. data/Gemfile +12 -0
  8. data/LICENSE.txt +22 -0
  9. data/README.md +133 -0
  10. data/Rakefile +12 -0
  11. data/app/assets/javascripts/hydra/batch_select.js +41 -0
  12. data/app/assets/javascripts/hydra_collections.js +12 -0
  13. data/app/controllers/collections_controller.rb +18 -0
  14. data/app/helpers/batch_select_helper.rb +25 -0
  15. data/app/helpers/collections_helper.rb +14 -0
  16. data/app/models/collection.rb +16 -0
  17. data/app/views/batch_select/_add_button.html.erb +3 -0
  18. data/app/views/batch_select/_check_all.html.erb +4 -0
  19. data/app/views/batch_select/_tools.html.erb +10 -0
  20. data/app/views/collections/_button_create_collection.html.erb +2 -0
  21. data/app/views/collections/_form.html.erb +36 -0
  22. data/app/views/collections/_form_for_select_collection.html.erb +13 -0
  23. data/app/views/collections/new.html.erb +3 -0
  24. data/app/views/collections/show.html.erb +9 -0
  25. data/config/jetty.yml +6 -0
  26. data/config/routes.rb +3 -0
  27. data/fedora_conf/conf/development/fedora.fcfg +946 -0
  28. data/fedora_conf/conf/test/fedora.fcfg +946 -0
  29. data/hydra-collections.gemspec +27 -0
  30. data/lib/hydra-collections.rb +7 -0
  31. data/lib/hydra/collection.rb +52 -0
  32. data/lib/hydra/collections.rb +12 -0
  33. data/lib/hydra/collections/accepts_batches.rb +55 -0
  34. data/lib/hydra/collections/collectible.rb +24 -0
  35. data/lib/hydra/collections/search_service.rb +58 -0
  36. data/lib/hydra/collections/version.rb +5 -0
  37. data/lib/hydra/collections_controller_behavior.rb +108 -0
  38. data/lib/hydra/datastreams/collection_rdf_datastream.rb +36 -0
  39. data/solr_conf/conf/schema.xml +372 -0
  40. data/solr_conf/conf/solrconfig.xml +163 -0
  41. data/solr_conf/solr.xml +35 -0
  42. data/spec/controllers/accepts_batches_spec.rb +72 -0
  43. data/spec/controllers/collections_controller_spec.rb +93 -0
  44. data/spec/factories.rb +18 -0
  45. data/spec/factories/.gitkeep +0 -0
  46. data/spec/factories/users.rb +31 -0
  47. data/spec/helpers/collections_helper_spec.rb +29 -0
  48. data/spec/lib/collectible_spec.rb +31 -0
  49. data/spec/lib/search_service_spec.rb +41 -0
  50. data/spec/models/collection_spec.rb +100 -0
  51. data/spec/spec_helper.rb +24 -0
  52. data/spec/support/Gemfile +19 -0
  53. data/spec/support/app/models/sample.rb +37 -0
  54. data/spec/support/app/models/solr_document.rb +5 -0
  55. data/spec/support/app/views/catalog/_document_header.html.erb +11 -0
  56. data/spec/support/app/views/catalog/_sort_and_per_page.html.erb +20 -0
  57. data/spec/support/config/initializers/hydra_config.rb +28 -0
  58. data/spec/support/db/migrate/20111101221803_create_searches.rb +16 -0
  59. data/spec/support/lib/generators/test_app_generator.rb +54 -0
  60. data/spec/support/lib/tasks/rspec.rake +9 -0
  61. data/tasks/hydra-collections-dev.rake +68 -0
  62. data/tasks/jetty.rake +40 -0
  63. metadata +194 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9c5a786d66ac76371de611ba60c82a417cb7bf2e
4
+ data.tar.gz: d2aa7e948ff445d78cf8850a42cf3f1eb6c4f0bf
5
+ SHA512:
6
+ metadata.gz: df8819b16d5c05fb2bba1c0d8ea75b7cdab1f4222a468c91c0ae72eafbe66ecd5ae06439d85b65241e5a5595d27bc3fb5ba11fe3966108b074724476ede2cf58
7
+ data.tar.gz: 0501175dc1e84dd91992945b8ae666355d2577e83bedcc692ba61211c5c738eefa6685ea3bdc87a6d27dff82785537c002247d7e98a6df77c70697608534edce
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .buildpath
7
+ .project
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
20
+ spec/internal
data/.gitmodules ADDED
@@ -0,0 +1,4 @@
1
+ [submodule "jetty"]
2
+ path = jetty
3
+ url = git://github.com/projecthydra/hydra-jetty.git
4
+ ignore = dirty
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ hydra-collections
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.0.0-p0
data/.travis.yml ADDED
@@ -0,0 +1,16 @@
1
+ language: ruby
2
+ rvm:
3
+ - "2.0.0"
4
+ notifications:
5
+ email:
6
+ recipients:
7
+ - "michael@psu.edu"
8
+ - "cam156@psu.edu"
9
+ - "dmc186@psu.edu"
10
+ on_success: "change"
11
+ on_failure: "always"
12
+ irc:
13
+ channels:
14
+ - "irc.freenode.org#scholarsphere"
15
+ template:
16
+ - "%{repository}//%{branch}@%{commit} by %{author}: %{message} - %{build_url}"
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hydra-collections.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem 'sqlite3'
8
+ gem "factory_girl_rails", "~> 4.1.0"
9
+ gem 'devise'
10
+ gem 'capybara', '~>1.1.3'
11
+ gem 'jettywrapper'
12
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Carolyn Cole
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,133 @@
1
+ # Hydra::Collections [![Version](https://badge.fury.io/rb/hydra-collections.png)](http://badge.fury.io/rb/hydra-collections) [![Build Status](https://travis-ci.org/psu-stewardship/hydra-collections.png?branch=master)](https://travis-ci.org/psu-stewardship/hydra-collections) [![Dependency Status](https://gemnasium.com/psu-stewardship/hydra-collections.png)](https://gemnasium.com/psu-stewardship/hydra-collections)
2
+
3
+ Add collections to your Hydra application
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'hydra-collections'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install hydra-collections
18
+
19
+ ## Usage
20
+
21
+ ### Mount the engine to get the routes in config/routes.rb
22
+
23
+ mount Hydra::Collections::Engine => '/'
24
+
25
+ ### Call button_create_collection view helper in your search result page template.
26
+ We recommend putting it in catalog/_sort_and_per_page.html.erb which you will manually override in you app.
27
+
28
+ <%= button_create_collection %>
29
+
30
+ ### Any time you want to refer to the routes from hydra-collections use collections.
31
+ collections.new_collections_path
32
+
33
+ ### Make your Models Collectible
34
+
35
+ Add `include Hydra::Collections::Collectible` to the models for anything that you want to be able to add to collections (ie. GenericFile, Book, Article, etc.), then add `index_collection_pids` to the solrization logic (ie. put it in to_solr)
36
+
37
+ Example:
38
+ ```ruby
39
+ class GenericFile < ActiveFedora::Base
40
+ include Hydra::Collections::Collectible
41
+ ...
42
+ def to_solr(solr_doc={}, opts={})
43
+ super(solr_doc, opts)
44
+ index_collection_pids(solr_doc)
45
+ return solr_doc
46
+ end
47
+ end
48
+ ```
49
+
50
+ Any items that include the `Hydra::Collections::Collectible` module can look up which collections they belong to via `.collections`. The `index_collection_pids` puts the pids of all associated collections into the `collection` facet.
51
+
52
+ ### Make your Controller Accept a Batch
53
+
54
+ Add `include Hydra::Collections::AcceptsBatches` to the collections you would like to process batches of models
55
+
56
+ You can access the batch in your update.
57
+
58
+ Example:
59
+ ```ruby
60
+ class BatchEditsController < ApplicationController
61
+ include Hydra::Collections::AcceptsBatches
62
+ ...
63
+
64
+ def update
65
+ batch.each do |doc_id|
66
+ obj = ActiveFedora::Base.find(doc_id, :cast=>true)
67
+ update_document(obj)
68
+ obj.save
69
+ end
70
+ flash[:notice] = "Batch update complete"
71
+ after_update
72
+ end
73
+
74
+ end
75
+ ```
76
+ ### Include the javascript to discover checked batch items
77
+
78
+ include `//= require hydra/batch_select` in your application.js
79
+
80
+ ### Display a selection checkbox in each document partial
81
+
82
+ include `<%= button_for_add_to_batch document %>'
83
+
84
+ Example: views/catalog/_document_header.html.erb
85
+ ```ruby
86
+ <% # header bar for doc items in index view -%>
87
+ <div class="documentHeader clearfix">
88
+ <%= button_for_add_to_batch(document) %>
89
+
90
+ ...
91
+ </div>
92
+
93
+ ```
94
+
95
+
96
+ ### Update your view to submit a Batch
97
+
98
+ include
99
+ Add `submits-batches` class to your view input to initialize batch processing
100
+
101
+ Example:
102
+ ```ruby
103
+ <%= button_to label, edit_batch_edits_path, :method=>:get, :class=>"btn submits-batches", 'data-behavior'=>'batch-edit', :id=>'batch-edit' %>
104
+ ```
105
+
106
+ ### Update you action view to submit changes to the batch
107
+
108
+ Add `updates-batches` class to your
109
+
110
+
111
+ ## Contributing
112
+
113
+ 1. Fork it
114
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
115
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
116
+ 4. Push to the branch (`git push origin my-new-feature`)
117
+ 5. Create new Pull Request
118
+
119
+ ### Setup instructions for Contributors
120
+
121
+ In order to make modifications to the gem code and run the tests, clone the repository then
122
+
123
+ ```
124
+ $ bundle install
125
+ $ git submodule init
126
+ $ git submodule update
127
+ $ rake jetty:config
128
+ $ rake jetty:start
129
+ $ rake clean
130
+ $ rake spec
131
+ ```
132
+
133
+
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ Dir.glob('tasks/*.rake').each { |r| import r }
5
+
6
+ ENV["RAILS_ROOT"] ||= 'spec/internal'
7
+
8
+ desc 'Run CI tests in e.g. Travis environment'
9
+ task :travis => ['clean', 'ci']
10
+
11
+ desc 'Default: run CI'
12
+ task :default => [:travis]
@@ -0,0 +1,41 @@
1
+ $(function () {
2
+
3
+ // add the batch ids to any submit of a batch update
4
+ var batch_ids = null;
5
+ $('input.updates-batches').on('click', function() {
6
+ var form = $(this).closest("form");
7
+ var hash, id;
8
+
9
+ // pull the ids from the url
10
+ if (!batch_ids) {
11
+ batch_ids = [];
12
+ // pull the ids from the url
13
+ var q = document.URL.split('?')[1];
14
+ if(q != undefined){
15
+ q = q.split('&');
16
+ for(var i = 0; i < q.length; i++){
17
+ hash = q[i].split('=');
18
+ if (hash[0] == "batch_document_ids%5B%5D")
19
+ batch_ids.push(unescape(hash[1]));
20
+ }
21
+ }
22
+ }
23
+
24
+ // push the ids in the form
25
+ for(var j = 0; j < batch_ids.length; j++){
26
+ if (form.children("input[value='"+batch_ids[j]+"']").length == 0)
27
+ form.append('<input type="hidden" multiple="multiple" name="batch_document_ids[]" value="'+batch_ids[j]+'" />');
28
+ }
29
+
30
+ });
31
+ $('input.submits-batches').on('click', function() {
32
+ var form = $(this).closest("form");
33
+ $.map( $(".batch_document_selector:checked"), function(document, i) {
34
+ var id = document.id.substring("batch_document_".length);
35
+ form.append('<input type="hidden" multiple="multiple" name="batch_document_ids[]" value="'+id+'" />');
36
+ });
37
+
38
+
39
+ });
40
+
41
+ });
@@ -0,0 +1,12 @@
1
+ $(function () {
2
+
3
+ // change the action based which collection is selected
4
+ $('input.submits-batches').on('click', function() {
5
+
6
+ var form = $(this).closest("form");
7
+ var collection_id = $(".collection-selector:checked")[0].value;
8
+ form[0].action = form[0].action.replace("collection_replace_id",collection_id);
9
+
10
+ });
11
+
12
+ });
@@ -0,0 +1,18 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright © 2012 The Pennsylvania State University
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.
15
+
16
+ class CollectionsController < ApplicationController
17
+ include Hydra::CollectionsControllerBehavior
18
+ end
@@ -0,0 +1,25 @@
1
+ # View Helpers for Hydra Batch Edit functionality
2
+ module BatchSelectHelper
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
+ # 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
10
+ def batch_select_tools
11
+ render :partial=>'/batch_select/tools'
12
+ end
13
+
14
+ # Displays the button to select/deselect items for your batch. Call this in the index partial that's rendered for each search result.
15
+ # @param [Hash] document the Hash (aka Solr hit) for one Solr document
16
+ def button_for_add_to_batch(document)
17
+ render :partial=>'/batch_select/add_button', :locals=>{:document=>document}
18
+ end
19
+
20
+ # 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
21
+ def batch_check_all(label = 'Use all results')
22
+ render :partial=>'/batch_select/check_all', :locals=>{:label=>label}
23
+ end
24
+
25
+ end
@@ -0,0 +1,14 @@
1
+ # View Helpers for Hydra Batch Edit functionality
2
+ module CollectionsHelper
3
+
4
+
5
+ # Displays the Collections create collection button. Put this in your search result page template. We recommend putting it in catalog/_sort_and_per_page.html.erb
6
+ def button_for_create_collection(label = 'Create Collection')
7
+ render :partial=>'/collections/button_create_collection', :locals=>{:label=>label}
8
+ end
9
+
10
+ def button_for_add_batch_to_collection(label = 'Add Selected to a Collection')
11
+ render :partial=>'/collections/button_add_batch_to_collection', :locals=>{:label=>label}
12
+ end
13
+
14
+ end
@@ -0,0 +1,16 @@
1
+ # Copyright © 2013 The Pennsylvania State University
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ class Collection < ActiveFedora::Base
15
+ include Hydra::Collection
16
+ end
@@ -0,0 +1,3 @@
1
+ <div data-behavior="batch-add-button">
2
+ <%= check_box_tag "batch_document_ids[]", document.id, false, class:"batch_document_selector", id: "batch_document_#{document.id}" %>
3
+ </div>
@@ -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(label, :class=>'batch-all-button btn') %>
3
+ <% end %>
4
+
@@ -0,0 +1,10 @@
1
+ <div class="btn-group batch-tools 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="<%= batch_edit_state %>"><a href="#"><i class=""></i> Batch edit</a></li>
8
+ </ul>
9
+ </div>
10
+
@@ -0,0 +1,2 @@
1
+ <%= button_to label, collections.new_collection_path, :method=>:get, :class=>"btn btn-primary collection-add", 'data-behavior'=>'hydra-collections', :id=>'hydra-collection-add' %>
2
+
@@ -0,0 +1,36 @@
1
+ <div class="container">
2
+ <%-# This syntax [collections, @collection] tells form_for to use the routes from the engine named collections %>
3
+ <%= form_for([collections, @collection]) do |f| %>
4
+ <% if @collection.errors.any? %>
5
+ <div id="error_explanation">
6
+ <h2><%= pluralize(@collection.errors.count, "error") %> prohibited this topic from being saved:</h2>
7
+
8
+ <ul>
9
+ <% @collection.errors.full_messages.each do |msg| %>
10
+ <li><%= msg %></li>
11
+ <% end %>
12
+ </ul>
13
+ </div>
14
+ <% end %>
15
+
16
+ <div class="field">
17
+ <%= f.label :title %><br />
18
+ <%= f.text_field :title %>
19
+ </div>
20
+
21
+ <div class="field">
22
+ <%= f.label :description %><br />
23
+ <%= f.text_area :description %>
24
+ </div>
25
+
26
+ <%- unless params[:batch_document_ids].nil? || params[:batch_document_ids].empty? %>
27
+ <%- params[:batch_document_ids].each do |batch_item| %>
28
+ <input type="hidden" name="batch_document_ids[]" value="<%= batch_item %>"/>
29
+ <%- end %>
30
+ <%- end %>
31
+
32
+ <div class="actions">
33
+ <%= f.submit %>
34
+ </div>
35
+ <% end %>
36
+ </div>