hydra-collections 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/app/assets/javascripts/hydra/batch_select.js +2 -1
  4. data/app/assets/javascripts/hydra_collections.js +1 -0
  5. data/app/assets/stylesheets/hydra_collections.css.scss +4 -0
  6. data/app/helpers/collections_helper.rb +28 -3
  7. data/app/models/solr_document.rb +13 -0
  8. data/app/views/collections/_button_create_collection.html.erb +1 -1
  9. data/app/views/collections/_button_for_delete_collection.html.erb +4 -0
  10. data/app/views/collections/_button_for_update_collection.html.erb +4 -0
  11. data/app/views/collections/_button_remove_from_collection.html.erb +6 -0
  12. data/app/views/collections/_document_header.html.erb +12 -0
  13. data/app/views/collections/_document_list.html.erb +1 -0
  14. data/app/views/collections/_form_for_select_collection.html.erb +20 -10
  15. data/app/views/collections/_single_item_action_fields.html.erb +6 -0
  16. data/app/views/collections/show.html.erb +1 -6
  17. data/lib/hydra-collections.rb +1 -0
  18. data/lib/hydra/collection.rb +5 -4
  19. data/lib/hydra/collections.rb +2 -0
  20. data/lib/hydra/collections/selects_collections.rb +49 -0
  21. data/lib/hydra/collections/solr_document_behavior.rb +33 -0
  22. data/lib/hydra/collections/version.rb +1 -1
  23. data/lib/hydra/collections_controller_behavior.rb +86 -18
  24. data/spec/controllers/catalog_controller_spec.rb +44 -0
  25. data/spec/controllers/collections_controller_spec.rb +34 -1
  26. data/spec/controllers/selects_collections_spec.rb +102 -0
  27. data/spec/helpers/collections_helper_spec.rb +25 -6
  28. data/spec/support/app/views/catalog/_index_collection.html.erb +1 -0
  29. data/spec/support/app/views/catalog/_sort_and_per_page.html.erb +1 -8
  30. data/spec/support/lib/generators/test_app_generator.rb +24 -3
  31. metadata +18 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9c5a786d66ac76371de611ba60c82a417cb7bf2e
4
- data.tar.gz: d2aa7e948ff445d78cf8850a42cf3f1eb6c4f0bf
3
+ metadata.gz: d9f1837b7839dd05eb2e4491c0880601f1e9085d
4
+ data.tar.gz: 0ae0566206139f10230859c5eac19a9056ee8f70
5
5
  SHA512:
6
- metadata.gz: df8819b16d5c05fb2bba1c0d8ea75b7cdab1f4222a468c91c0ae72eafbe66ecd5ae06439d85b65241e5a5595d27bc3fb5ba11fe3966108b074724476ede2cf58
7
- data.tar.gz: 0501175dc1e84dd91992945b8ae666355d2577e83bedcc692ba61211c5c738eefa6685ea3bdc87a6d27dff82785537c002247d7e98a6df77c70697608534edce
6
+ metadata.gz: 1798220406600445cf05d2e8fcaf94a3fa68fcc6eea05afebc31f79caddd1c85be19b2c1b81e0a3c1a72b997a98d242199d9ae548b4881900522210b22f1a06e
7
+ data.tar.gz: 3a5c84107f842c2dea9b4ca6cfbd1efee7f7704d35854c6d3bf0b47653e28df81c3402b9f93ac8de82e6fd5026ebf7cdc331d98c070910fa8dff9681ed381660
data/Gemfile CHANGED
@@ -3,6 +3,8 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in hydra-collections.gemspec
4
4
  gemspec
5
5
 
6
+ gem 'blacklight', github:'projectblacklight/blacklight' ,ref:'2eb87e73ee81ee701982ca32e5eca37429e3c199'
7
+
6
8
  group :development, :test do
7
9
  gem 'sqlite3'
8
10
  gem "factory_girl_rails", "~> 4.1.0"
@@ -32,7 +32,8 @@ $(function () {
32
32
  var form = $(this).closest("form");
33
33
  $.map( $(".batch_document_selector:checked"), function(document, i) {
34
34
  var id = document.id.substring("batch_document_".length);
35
- form.append('<input type="hidden" multiple="multiple" name="batch_document_ids[]" value="'+id+'" />');
35
+ if (form.children("input[value='"+id+"']").length == 0)
36
+ form.append('<input type="hidden" multiple="multiple" name="batch_document_ids[]" value="'+id+'" />');
36
37
  });
37
38
 
38
39
 
@@ -6,6 +6,7 @@ $(function () {
6
6
  var form = $(this).closest("form");
7
7
  var collection_id = $(".collection-selector:checked")[0].value;
8
8
  form[0].action = form[0].action.replace("collection_replace_id",collection_id);
9
+ form.append('<input type="hidden" value="add" name="collection[members]"></input>');
9
10
 
10
11
  });
11
12
 
@@ -0,0 +1,4 @@
1
+ .collection-list {
2
+ max-height: 200px;
3
+ overflow-y: scroll;
4
+ }
@@ -4,11 +4,36 @@ module CollectionsHelper
4
4
 
5
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
6
  def button_for_create_collection(label = 'Create Collection')
7
- render :partial=>'/collections/button_create_collection', :locals=>{:label=>label}
7
+ render partial:'/collections/button_create_collection', locals:{label:label}
8
+ end
9
+
10
+ # Displays the Collections update collection button. Put this in your search result page template. We recommend putting it in catalog/_sort_and_per_page.html.erb
11
+ def button_for_update_collection(label = 'Update Collection', collection_id = 'collection_replace_id' )
12
+ render partial:'/collections/button_for_update_collection', locals:{label:label, collection_id:collection_id}
13
+ end
14
+
15
+ # Displays the Collections delete collection button. Put this in your search result page for each collection found.
16
+ def button_for_delete_collection(collection, label = 'Delete Collection', confirm = 'Are you sure?')
17
+ render partial:'/collections/button_for_delete_collection', locals:{collection:collection,label:label, confirm:confirm}
18
+ end
19
+
20
+ def button_for_remove_from_collection(document, label = 'Remove From Collection')
21
+ render partial:'/collections/button_remove_from_collection', locals:{label:label, document:document}
22
+ end
23
+
24
+ # add hidden fields to a form for removing a single document from a collection
25
+ def single_item_action_remove_form_fields(form, document)
26
+ single_item_action_form_fields(form, document, "remove")
8
27
  end
9
28
 
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}
29
+ # add hidden fields to a form for adding a single document to a collection
30
+ def single_item_action_add_form_fields(form, document)
31
+ single_item_action_form_fields(form, document, "add")
32
+ end
33
+
34
+ # add hidden fields to a form for performing an action on a single document on a collection
35
+ def single_item_action_form_fields(form, document, action)
36
+ render partial:'/collections/single_item_action_fields', locals:{form:form, document:document, action: action}
12
37
  end
13
38
 
14
39
  end
@@ -0,0 +1,13 @@
1
+ # -*- encoding : utf-8 -*-
2
+ class SolrDocument
3
+ # Add Blacklight behaviors to the SolrDocument
4
+ include Blacklight::Solr::Document
5
+ # Adds Collection behaviors to the SolrDocument.
6
+ include Hydra::Collections::SolrDocumentBehavior
7
+
8
+ # Method to return the ActiveFedora model
9
+ def hydra_model
10
+ Array(self[Solrizer.solr_name('active_fedora_model', Solrizer::Descriptor.new(:string, :stored, :indexed))]).first
11
+ end
12
+
13
+ end
@@ -1,2 +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' %>
1
+ <%= button_to label, collections.new_collection_path, :method=>:get, :class=>"btn btn-primary collection-add submits-batches", 'data-behavior'=>'hydra-collections', :id=>'hydra-collection-add' %>
2
2
 
@@ -0,0 +1,4 @@
1
+ <%# button for deleting a collections %>
2
+ <%# collection -- collection to be deleted %>
3
+ <%= button_to label, collections.collection_path(collection.id), :confirm => confirm, :method=>:delete, :class=>"btn btn-primary collection-delete", 'data-behavior'=>'hydra-collections', :id=>'hydra-collection-add' %>
4
+
@@ -0,0 +1,4 @@
1
+ <%# button for updating a collections %>
2
+ <%# collection_id -- collection to be updated (use 'collection_replace_id' if you wish the form to be updated by a form value) %>
3
+ <%# label -- button label %>
4
+ <%= button_to label, collections.collection_path(collection_id), :method=>:put, :class=>"btn btn-primary updates-collection submits-batches collection-update", 'data-behavior'=>'hydra-collections', :id=>'hydra-collection-update' %>
@@ -0,0 +1,6 @@
1
+ <%#= button_to label, , :class=>"btn btn-primary collection-remove", 'data-behavior'=>'hydra-collections-remove', members:"delete", batch_document_ids:[document.id] %>
2
+
3
+ <%= form_for @collection, url:collections.collection_path(@collection.id), :method=>:put do |f| %>
4
+ <%= single_item_action_remove_form_fields(f,document) %>
5
+ <%= f.submit label, :class => "btn btn-primary collection-remove" %>
6
+ <% end %>
@@ -0,0 +1,12 @@
1
+
2
+ <% # header bar for doc items in index view -%>
3
+ <div class="documentHeader clearfix">
4
+
5
+ <% # main title container for doc partial view -%>
6
+ <h5 class="index_title"><%= t('blacklight.search.documents.counter', :counter => (document_counter + 1 + @response.params[:start].to_i)) %><%= link_to_document document, :label=>document_show_link_field(document), :counter => (document_counter + 1 + @response.params[:start].to_i) %></h5>
7
+
8
+ <div class="documentFunctions span2">
9
+ <%= button_for_remove_from_collection(document) %>
10
+ </div>
11
+ </div>
12
+
@@ -0,0 +1 @@
1
+ <%= render partial:'catalog/document_list', locals:{documents: documents} %>
@@ -1,13 +1,23 @@
1
- Please Select your colection to add you files to:
2
1
  <% thing = Collection.new %>
3
- <%= form_tag(collections.collection_path('collection_replace_id'), :method => "put") do %>
4
- <%#= form_for thing, :url => , :html => {:multipart => true, :class => 'form-horizontal'}, :method => :put do |f| %>
5
- <input type="hidden" name="test" value="val" />
6
- <%= hash_as_hidden_fields({:collection =>{members:"add"}}) %>
7
- <ul>
8
- <% user_collections.each do |collection| %>
9
- <li> <%= radio_button_tag(:id, collection.id, false, :class => "collection-selector") %><%= label_tag(:collection, collection.title) %> </li>
2
+ <% if user_collections.nil?%>
3
+ <b> Make sure you have included Hydra::Collections::SelectsCollections in your controller for this page and
4
+ added a before filter with one of the find_collections variations depending on your access level: find_collections, find_collections_with_read_access, find_collections_with_edit_access
5
+ </b>
6
+ <% elsif user_collections.blank? %>
7
+ <b> You do not have access to any existing collections please create a collection. </b>
8
+ <% else %>
9
+ Please Select your collection to add you files to:
10
+ <%= form_tag(collections.collection_path('collection_replace_id'), :method => "put") do %>
11
+ <%#= form_for thing, :url => , :html => {:multipart => true, :class => 'form-horizontal'}, :method => :put do |f| %>
12
+ <input type="hidden" name="test" value="val" />
13
+ <%= hash_as_hidden_fields({:collection =>{members:"add"}}) %>
14
+ <div class="collection-list">
15
+ <ul>
16
+ <% user_collections.each do |collection| %>
17
+ <li> <%= radio_button_tag(:id, collection.id, false, :class => "collection-selector") %><%= label_tag(:collection, collection.title) %> </li>
18
+ <% end %>
19
+ </ul>
20
+ </div>
21
+ <%= button_to "Update Collection", collections.collections_path, :method=>:put, :class=>"btn btn-primary collection-update submits-batches", 'data-behavior'=>'hydra-collections', :id=>'hydra-collection-add' %>
10
22
  <% end %>
11
- </ul>
12
- <%= button_to "Update Collection", collections.collections_path, :method=>:put, :class=>"btn btn-primary collection-update submits-batches", 'data-behavior'=>'hydra-collections', :id=>'hydra-collection-add' %>
13
23
  <% end %>
@@ -0,0 +1,6 @@
1
+ <%# this includes the fields in a form necissary for manipulating a single item in a collection %>
2
+ <%# form - form these fields will reside in %>
3
+ <%# action - collection action: add or remove %>
4
+ <%# document - current document %>
5
+ <%= form.hidden_field :members, :value => action %>
6
+ <%= hidden_field :batch_document_ids, '',{value:document.id, multiple:true} %>
@@ -1,9 +1,4 @@
1
1
  <h1><%=@collection.title%><h1>
2
2
  <h3><%=@collection.description%> </h3>
3
3
  <h3> <u>Contained Files </u></h3>
4
- <table>
5
- <tr> <th> File id </th> </tr>
6
- <% @collection.members.each_with_index do |document,counter| %>
7
- <tr><td><%=document.pid%></tr>
8
- <% end %>
9
- </table>
4
+ <%= render partial:'document_list', locals:{documents: @member_docs} %>
@@ -5,3 +5,4 @@ require "bundler/setup"
5
5
  require "blacklight"
6
6
  require "hydra/head"
7
7
  require "active_fedora"
8
+ require "hydra/collections/selects_collections"
@@ -6,9 +6,10 @@ module Hydra
6
6
  extend ActiveSupport::Concern
7
7
  extend ActiveSupport::Autoload
8
8
  autoload :Permissions
9
- include Hydra::ModelMethods # for access to apply_depositor_metadata
10
-
11
- included do
9
+ include Hydra::ModelMethods # for access to apply_depositor_metadata
10
+ include Hydra::ModelMixins::RightsMetadata
11
+
12
+ included do
12
13
  has_metadata :name => "descMetadata", :type => CollectionRdfDatastream
13
14
  has_metadata :name => "properties", :type => Hydra::Datastream::Properties
14
15
  has_metadata :name => "rightsMetadata", :type => Hydra::Datastream::RightsMetadata
@@ -16,7 +17,7 @@ module Hydra
16
17
  has_and_belongs_to_many :members, :property => :has_collection_member, :class_name => "ActiveFedora::Base"
17
18
 
18
19
  delegate_to :properties, [:depositor], :unique => true
19
- delegate_to :descMetadata, [:date_uploaded, :date_modified, :related_url,
20
+ delegate_to :descMetadata, [:date_uploaded, :date_modified,
20
21
  :title, :description], :unique => true
21
22
 
22
23
  before_create :set_date_uploaded
@@ -5,6 +5,8 @@ module Hydra
5
5
  autoload :Collectible
6
6
  autoload :SearchService
7
7
  autoload :AcceptsBatches
8
+ autoload :SelectsCollections
9
+ autoload :SolrDocumentBehavior
8
10
  class Engine < ::Rails::Engine
9
11
  engine_name "collections"
10
12
  end
@@ -0,0 +1,49 @@
1
+ require 'blacklight/catalog'
2
+
3
+ module Hydra::Collections::SelectsCollections
4
+
5
+ extend ActiveSupport::Autoload
6
+ extend ActiveSupport::Concern
7
+
8
+ def access_levels
9
+ {read:[:read,:edit],edit:[:edit]}
10
+ end
11
+
12
+ # add one of the following methods as a before filter on any page that shows the form_for_select_collection
13
+ def find_collections_with_read_access
14
+ find_collections(:read)
15
+ end
16
+
17
+ def find_collections_with_edit_access
18
+ find_collections(:edit)
19
+ end
20
+
21
+ def find_collections (access_level='')
22
+ # need to know the user if there is an access level applied otherwise we are just doing public collections
23
+ authenticate_user! unless access_level.blank?
24
+
25
+ # update the permission filters for the query of need be
26
+ original_permissions = discovery_permissions
27
+ self.class.send(:define_method, "discovery_permissions") { access_levels[access_level] } unless access_level.blank?
28
+
29
+ # add the collection filter to the solr logic for this query
30
+ orig_solr_search_params_logic = self.class.solr_search_params_logic
31
+ self.class.solr_search_params_logic += [:add_collection_filter]
32
+
33
+ # run the solr query to find the collections
34
+ (resp, doc_list) = get_search_results(:q => '', :rows=>100)
35
+
36
+ #reset to original solr logic
37
+ self.class.send(:define_method, "discovery_permissions") { original_permissions } unless access_level.blank?
38
+ self.class.solr_search_params_logic = orig_solr_search_params_logic
39
+
40
+ # return the user's collections (or public collections if no access_level is applied)
41
+ @user_collections = doc_list
42
+ end
43
+
44
+ def add_collection_filter(solr_parameters, user_parameters)
45
+ solr_parameters[:fq] ||= []
46
+ solr_parameters[:fq] << "#{Solrizer.solr_name("has_model", :symbol)}:\"info:fedora/afmodel:Collection\""
47
+ end
48
+
49
+ end
@@ -0,0 +1,33 @@
1
+ # Copyright © 2012 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
+
15
+ # -*- encoding : utf-8 -*-
16
+ module Hydra
17
+ module Collections
18
+ module SolrDocumentBehavior
19
+ def title_or_label
20
+ title || label
21
+ end
22
+
23
+ def title
24
+ Array(self[Solrizer.solr_name('desc_metadata__title')]).first
25
+ end
26
+
27
+ def description
28
+ Array(self[Solrizer.solr_name('desc_metadata__description')]).first
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -1,5 +1,5 @@
1
1
  module Hydra
2
2
  module Collections
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -1,3 +1,5 @@
1
+ require 'blacklight'
2
+
1
3
  # -*- coding: utf-8 -*-
2
4
  # Copyright © 2012 The Pennsylvania State University
3
5
  #
@@ -12,6 +14,7 @@
12
14
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
15
  # See the License for the specific language governing permissions and
14
16
  # limitations under the License.
17
+ include Blacklight::SolrHelper
15
18
 
16
19
  module Hydra
17
20
  module CollectionsControllerBehavior
@@ -20,6 +23,7 @@ module Hydra
20
23
  included do
21
24
  include Hydra::Controller::ControllerBehavior
22
25
  include Blacklight::Configurable # comply with BL 3.7
26
+ include Blacklight::Controller
23
27
  include Hydra::Collections::AcceptsBatches
24
28
 
25
29
  # This is needed as of BL 3.7
@@ -28,7 +32,7 @@ module Hydra
28
32
  # Catch permission errors
29
33
  rescue_from Hydra::AccessDenied, CanCan::AccessDenied do |exception|
30
34
  if (exception.action == :edit)
31
- redirect_to(sufia.url_for({:action=>'show'}), :alert => "You do not have sufficient privileges to edit this document")
35
+ redirect_to(collections.url_for({:action=>'show'}), :alert => "You do not have sufficient privileges to edit this document")
32
36
  elsif current_user and current_user.persisted?
33
37
  redirect_to root_url, :alert => exception.message
34
38
  else
@@ -45,24 +49,64 @@ module Hydra
45
49
  def new
46
50
  #@collection = ::Collection.new
47
51
  end
48
-
52
+
53
+ def show
54
+ logger.warn "Got to show"
55
+
56
+ if @collection.member_ids.length > 0
57
+ query = @collection.member_ids.join " OR "
58
+
59
+ # run the solr query to find the collections
60
+ (@response, @member_docs) = get_search_results(:q => query, :rows=>100)
61
+ else
62
+ #pretend we ran a solr query to get the colelctions since we do not need to really do it since there should be no results
63
+ @member_docs = []
64
+ @response = Blacklight::SolrResponse.new({'responseHeader'=>{'status'=>0,'QTime'=>5,'params'=>{'wt'=>'ruby','q'=>'xxzxas'}},'response'=>{'numFound'=>0,'start'=>0,'maxScore'=>0.0,'docs'=>[]},'facet_counts'=>{'facet_queries'=>{},'facet_fields'=>{'active_fedora_model_ssi'=>[],'object_type_si'=>[]},'facet_dates'=>{},'facet_ranges'=>{}},'spellcheck'=>{'suggestions'=>['correctlySpelled',false]}},"")
65
+ end
66
+
67
+ end
68
+
49
69
  def edit
50
70
  end
71
+
72
+ def after_create
73
+ respond_to do |format|
74
+ format.html { redirect_to collections.collection_path(@collection), notice: 'Collection was successfully created.' }
75
+ format.json { render json: @collection, status: :created, location: @collection }
76
+ end
77
+ end
51
78
 
79
+ def after_create_error
80
+ respond_to do |format|
81
+ format.html { render action: "new" }
82
+ format.json { render json: @collection.errors, status: :unprocessable_entity }
83
+ end
84
+ end
85
+
52
86
  def create
53
87
  @collection.apply_depositor_metadata(current_user.user_key)
54
88
  unless batch.empty?
55
89
  params[:collection][:members]="add"
56
90
  process_member_changes
57
91
  end
92
+ if @collection.save
93
+ after_create
94
+ else
95
+ after_create_error
96
+ end
97
+ end
98
+
99
+ def after_update
58
100
  respond_to do |format|
59
- if @collection.save
60
- format.html { redirect_to collections.collection_path(@collection), notice: 'Collection was successfully created.' }
61
- format.json { render json: @collection, status: :created, location: @collection }
62
- else
63
- format.html { render action: "new" }
64
- format.json { render json: @collection.errors, status: :unprocessable_entity }
65
- end
101
+ format.html { redirect_to collections.collection_path(@collection), notice: 'Collection was successfully updated.' }
102
+ format.json { render json: @collection, status: :updated, location: @collection }
103
+ end
104
+ end
105
+
106
+ def after_update_error
107
+ respond_to do |format|
108
+ format.html { render action: collections.edit_collection_path(@collection) }
109
+ format.json { render json: @collection.errors, status: :unprocessable_entity }
66
110
  end
67
111
  end
68
112
 
@@ -70,17 +114,37 @@ module Hydra
70
114
  @collection = ::Collection.find(params[:id])
71
115
  process_member_changes
72
116
  @collection.update_attributes(params[:collection].except(:members))
73
- respond_to do |format|
74
- if @collection.save
75
- format.html { redirect_to collections.collection_path(@collection), notice: 'Collection was successfully created.' }
76
- format.json { render json: @collection, status: :updated, location: @collection }
77
- else
78
- format.html { render action: collections.edit_collection_path(@collection) }
79
- format.json { render json: @collection.errors, status: :unprocessable_entity }
80
- end
117
+ if @collection.save
118
+ after_update
119
+ else
120
+ after_update_error
81
121
  end
82
122
  end
83
123
 
124
+
125
+ def after_destroy (id)
126
+ respond_to do |format|
127
+ format.html { redirect_to catalog_index_path, notice: 'Collection was successfully deleted.' }
128
+ format.json { render json: {id:id}, status: :destroyed, location: @collection }
129
+ end
130
+ end
131
+
132
+ def after_destroy_error (id)
133
+ respond_to do |format|
134
+ format.html { redirect_to catalog_index_path, notice: 'Collection could not be deleted.' }
135
+ format.json { render json: {id:id}, status: :destroy_error, location: @collection }
136
+ end
137
+ end
138
+
139
+ def destroy
140
+ @collection = ::Collection.find(params[:id])
141
+ if @collection.destroy
142
+ after_destroy(params[:id])
143
+ else
144
+ after_destroy_error(params[:id])
145
+ end
146
+ end
147
+
84
148
  protected
85
149
 
86
150
  def process_member_changes
@@ -103,6 +167,10 @@ module Hydra
103
167
  end
104
168
  end
105
169
 
106
-
170
+ # this is only needed until the version of balcklight that we are using this include it in it's solr helper
171
+ def blacklight_solr
172
+ Blacklight.solr
173
+ end
174
+
107
175
  end # module CollectionsControllerBehavior
108
176
  end # module Hydra
@@ -0,0 +1,44 @@
1
+ # Copyright © 2012 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
+
15
+ require 'spec_helper'
16
+
17
+ include Rails.application.routes.url_helpers
18
+
19
+ describe CatalogController do
20
+ before do
21
+ controller.stub(:has_access?).and_return(true)
22
+ @user = FactoryGirl.find_or_create(:user)
23
+ @collection = Collection.new title:"Test"
24
+ @collection.apply_depositor_metadata(@user.user_key)
25
+ @collection.read_groups = ["public"]
26
+ @collection.save
27
+ end
28
+
29
+ after do
30
+ @user.delete
31
+ @collection.delete
32
+ end
33
+
34
+
35
+ describe '#index' do
36
+ it 'should assign @user_collections' do
37
+ @routes = Rails.application.routes
38
+ get :index
39
+ expect(assigns(:user_collections)).to be_kind_of(Array)
40
+ assigns(:user_collections).index{|d| d.id == @collection.id}.should_not be_nil
41
+ end
42
+ end
43
+
44
+ end
@@ -52,6 +52,10 @@ describe CollectionsController do
52
52
  post :create, batch_document_ids: [@asset1, @asset2], collection: {title: "My Secong Collection ", description: "The Description\r\n\r\nand more"}
53
53
  assigns[:collection].members.should == [@asset1, @asset2]
54
54
  end
55
+ it "should call after_create" do
56
+ controller.should_receive(:after_create).and_call_original
57
+ post :create, collection: {title: "My First Collection ", description: "The Description\r\n\r\nand more"}
58
+ end
55
59
  end
56
60
 
57
61
  describe "#update" do
@@ -70,12 +74,17 @@ describe CollectionsController do
70
74
  assigns[:collection].title.should == "New Title"
71
75
  assigns[:collection].description.should == "New Description"
72
76
  end
77
+
78
+ it "should call after_update" do
79
+ controller.should_receive(:after_update).and_call_original
80
+ put :update, id: @collection.id, collection: {title: "New Title", description: "New Description"}
81
+ end
73
82
  it "should support adding batches of members" do
74
83
  @collection.members << @asset1
75
84
  @collection.save
76
85
  put :update, id: @collection.id, collection: {members:"add"}, batch_document_ids:[@asset2, @asset3]
77
86
  response.should redirect_to Hydra::Collections::Engine.routes.url_helpers.collection_path(@collection.id)
78
- assigns[:collection].members.should == [@asset2, @asset3, @asset1]
87
+ assigns[:collection].members.sort! { |a,b| a.pid <=> b.pid }.should == [@asset2, @asset3, @asset1].sort! { |a,b| a.pid <=> b.pid }
79
88
  end
80
89
  it "should support removing batches of members" do
81
90
  @collection.members = [@asset1, @asset2, @asset3]
@@ -90,4 +99,28 @@ describe CollectionsController do
90
99
  assigns[:collection].members.should == [@asset1,@asset2, @asset3]
91
100
  end
92
101
  end
102
+
103
+ describe "#destroy" do
104
+ describe "valid collection" do
105
+ before do
106
+ @collection = Collection.new
107
+ @collection.apply_depositor_metadata(@user.user_key)
108
+ @collection.save
109
+ controller.should_receive(:authorize!).and_return(true)
110
+ end
111
+ it "should delete collection" do
112
+ delete :destroy, id: @collection.id
113
+ response.should redirect_to Rails.application.routes.url_helpers.catalog_index_path
114
+ flash[:notice].should == "Collection was successfully deleted."
115
+ end
116
+ it "should call after_destroy" do
117
+ controller.should_receive(:after_destroy).and_call_original
118
+ delete :destroy, id: @collection.id
119
+ end
120
+ end
121
+ it "should not delete an invalid collection" do
122
+ expect {delete :destroy, id: 'zz:-1'}.to raise_error
123
+ end
124
+ end
125
+
93
126
  end
@@ -0,0 +1,102 @@
1
+ require "spec_helper"
2
+
3
+ class SelectsCollectionsController < ApplicationController
4
+ include Blacklight::Catalog
5
+ include Hydra::Controller::ControllerBehavior
6
+ include Hydra::Collections::SelectsCollections
7
+
8
+ SelectsCollectionsController.solr_search_params_logic += [:add_access_controls_to_solr_params]
9
+ # This filters out objects that you want to exclude from search results, like FileAssets
10
+ SelectsCollectionsController.solr_search_params_logic += [:exclude_unwanted_models]
11
+
12
+ end
13
+
14
+
15
+ describe SelectsCollectionsController do
16
+
17
+ describe "Select Collections" do
18
+ before (:all) do
19
+ @user = FactoryGirl.find_or_create(:user)
20
+ @collection = Collection.new title:"Test Public"
21
+ @collection.apply_depositor_metadata(@user.user_key)
22
+ @collection.read_groups = ["public"]
23
+ @collection.save
24
+ @collection2 = Collection.new title:"Test Read"
25
+ @collection2.apply_depositor_metadata('abc123@test.com')
26
+ @collection2.read_users = [@user.user_key]
27
+ @collection2.save
28
+ @collection3 = Collection.new title:"Test Edit"
29
+ @collection3.apply_depositor_metadata('abc123@test.com')
30
+ @collection3.edit_users = [@user.user_key]
31
+ @collection3.save
32
+ @collection4 = Collection.new title:"Test No Access"
33
+ @collection4.apply_depositor_metadata('abc123@test.com')
34
+ @collection4.save
35
+ end
36
+ after (:all) do
37
+ Collection.find(:all).map(&:delete)
38
+ end
39
+ describe "Public Access" do
40
+ before (:each) do
41
+ subject.find_collections
42
+ @user_collections = subject.instance_variable_get (:@user_collections)
43
+ expect(@user_collections).to be_kind_of(Array)
44
+ end
45
+ it "should return public collections" do
46
+ @user_collections.index{|d| d.id == @collection.id}.should_not be_nil
47
+ end
48
+ it "should not return non public collections" do
49
+ @user_collections.index{|d| d.id == @collection2.id}.should be_nil
50
+ @user_collections.index{|d| d.id == @collection3.id}.should be_nil
51
+ @user_collections.index{|d| d.id == @collection4.id}.should be_nil
52
+ end
53
+ end
54
+ describe "Read Access" do
55
+ describe "not signed in" do
56
+ it "should error if the user is not signed in" do
57
+ expect { subject.find_collections_with_read_access }.to raise_error
58
+ end
59
+ end
60
+ describe "signed in" do
61
+ before (:each) do
62
+ sign_in @user
63
+ subject.find_collections_with_read_access
64
+ @user_collections = subject.instance_variable_get (:@user_collections)
65
+ expect(@user_collections).to be_kind_of(Array)
66
+ end
67
+ it "should return public and read access (edit access implies read) collections" do
68
+ @user_collections.index{|d| d.id == @collection.id}.should_not be_nil
69
+ @user_collections.index{|d| d.id == @collection2.id}.should_not be_nil
70
+ @user_collections.index{|d| d.id == @collection3.id}.should_not be_nil
71
+ end
72
+ it "should not return non public collections" do
73
+ @user_collections.index{|d| d.id == @collection4.id}.should be_nil
74
+ end
75
+ end
76
+ end
77
+ describe "Edit Access" do
78
+ describe "not signed in" do
79
+ it "should error if the user is not signed in" do
80
+ expect { subject.find_collections_with_edit_access }.to raise_error
81
+ end
82
+ end
83
+ describe "signed in" do
84
+ before (:each) do
85
+ sign_in @user
86
+ subject.find_collections_with_edit_access
87
+ @user_collections = subject.instance_variable_get (:@user_collections)
88
+ expect(@user_collections).to be_kind_of(Array)
89
+ end
90
+ it "should return public or editable collections" do
91
+ @user_collections.index{|d| d.id == @collection.id}.should_not be_nil
92
+ @user_collections.index{|d| d.id == @collection3.id}.should_not be_nil
93
+ end
94
+ it "should not return non public or editable collections" do
95
+ @user_collections.index{|d| d.id == @collection2.id}.should be_nil
96
+ @user_collections.index{|d| d.id == @collection4.id}.should be_nil
97
+ end
98
+ end
99
+ end
100
+ end
101
+
102
+ end
@@ -17,13 +17,32 @@ require 'spec_helper'
17
17
  include Hydra::Collections::Engine.routes.url_helpers
18
18
 
19
19
  describe CollectionsHelper do
20
- it "button_for_create_collection should create a button to the collections new path" do
21
- html = button_for_create_collection
22
- html.should have_selector("form[action='#{collections.new_collection_path}']")
20
+ describe "button_for_create_collection" do
21
+ it " should create a button to the collections new path" do
22
+ html = button_for_create_collection
23
+ html.should have_selector("form[action='#{collections.new_collection_path}']")
24
+ html.should have_selector("input[type='submit']")
25
+ end
26
+ it "should create a button with my text" do
27
+ html = button_for_create_collection "Create My Button"
28
+ html.should have_selector("input[value='Create My Button']")
29
+ end
30
+ end
31
+ describe "button_for_delete_collection" do
32
+ before (:all) do
33
+ @collection = Collection.create title:"Test Public"
34
+ end
35
+ after (:all) do
36
+ @collection.delete
37
+ end
38
+ it " should create a button to the collections delete path" do
39
+ html = button_for_delete_collection @collection
40
+ html.should have_selector("form[action='#{collections.collection_path(@collection.pid)}']")
23
41
  html.should have_selector("input[type='submit']")
24
42
  end
25
- it "button_for_create_collection should create a button with my text" do
26
- html = button_for_create_collection "Create My Button"
27
- html.should have_selector("input[value='Create My Button']")
43
+ it "should create a button with my text" do
44
+ html = button_for_delete_collection @collection, "Delete My Button"
45
+ html.should have_selector("input[value='Delete My Button']")
28
46
  end
29
47
  end
48
+ end
@@ -0,0 +1 @@
1
+ <%= button_for_delete_collection(document, "Delete") %>
@@ -8,13 +8,6 @@
8
8
 
9
9
  <%= button_for_create_collection %>
10
10
 
11
-
12
- <% c1 = Collection.new(title:"title1") %>
13
- <% c1.apply_depositor_metadata("cam156@psu.edu") %>
14
- <% c1.save %>
15
- <% c2 = Collection.new(title:"title2") %>
16
- <% c2.apply_depositor_metadata("cam156@psu.edu") %>
17
- <% c2.save %>
18
- <%= render partial: 'collections/form_for_select_collection', locals: {user_collections: [c1,c2]} %>
11
+ <%= render partial: 'collections/form_for_select_collection', locals: {user_collections: @user_collections} %>
19
12
 
20
13
  </div>
@@ -44,10 +44,31 @@ class TestAppGenerator < Rails::Generators::Base
44
44
  directory("app/views/catalog")
45
45
  end
46
46
 
47
- # Inject call to Hydra::Collections.add_routes in config/routes.rb
47
+ # Inject javascript into application.js
48
48
  def inject_javascript
49
- insert_into_file "app/assets/javascripts/application.js", :after => '/= require_tree .' do
50
- "\n #include javascript for batches and collections\n//= require hydra/batch_select\n//= require hydra_collections"
49
+ insert_into_file "app/assets/javascripts/application.js", :after => '//= require_tree .' do
50
+ "\n //include javascript for batches and collections\n//= require hydra/batch_select\n//= require hydra_collections"
51
+ end
52
+ end
53
+
54
+ # Inject javascript into application.js
55
+ def inject_css
56
+ insert_into_file "app/assets/stylesheets/application.css", :after => '*= require_tree .' do
57
+ "\n *= require hydra_collections"
58
+ end
59
+ end
60
+
61
+ # Inject collections call into balacklight catalog
62
+ def inject_collections
63
+ insert_into_file "app/controllers/catalog_controller.rb", :after => 'Hydra::Controller::ControllerBehavior' do
64
+ "\n include Hydra::Collections::SelectsCollections\n before_filter :find_collections, :only=>:index"
65
+ end
66
+ end
67
+
68
+ # Inject collections SolrDocumentBehavior into balacklight SolrDocument
69
+ def inject_solr_doc
70
+ insert_into_file "app/models/solr_document.rb", :after => 'include Blacklight::Solr::Document' do
71
+ "\n # Adds Collection behaviors to the SolrDocument.\n include Hydra::Collections::SolrDocumentBehavior"
51
72
  end
52
73
  end
53
74
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hydra-collections
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carolyn Cole
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-06 00:00:00.000000000 Z
11
+ date: 2013-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: blacklight
@@ -98,16 +98,24 @@ files:
98
98
  - Rakefile
99
99
  - app/assets/javascripts/hydra/batch_select.js
100
100
  - app/assets/javascripts/hydra_collections.js
101
+ - app/assets/stylesheets/hydra_collections.css.scss
101
102
  - app/controllers/collections_controller.rb
102
103
  - app/helpers/batch_select_helper.rb
103
104
  - app/helpers/collections_helper.rb
104
105
  - app/models/collection.rb
106
+ - app/models/solr_document.rb
105
107
  - app/views/batch_select/_add_button.html.erb
106
108
  - app/views/batch_select/_check_all.html.erb
107
109
  - app/views/batch_select/_tools.html.erb
108
110
  - app/views/collections/_button_create_collection.html.erb
111
+ - app/views/collections/_button_for_delete_collection.html.erb
112
+ - app/views/collections/_button_for_update_collection.html.erb
113
+ - app/views/collections/_button_remove_from_collection.html.erb
114
+ - app/views/collections/_document_header.html.erb
115
+ - app/views/collections/_document_list.html.erb
109
116
  - app/views/collections/_form.html.erb
110
117
  - app/views/collections/_form_for_select_collection.html.erb
118
+ - app/views/collections/_single_item_action_fields.html.erb
111
119
  - app/views/collections/new.html.erb
112
120
  - app/views/collections/show.html.erb
113
121
  - config/jetty.yml
@@ -121,6 +129,8 @@ files:
121
129
  - lib/hydra/collections/accepts_batches.rb
122
130
  - lib/hydra/collections/collectible.rb
123
131
  - lib/hydra/collections/search_service.rb
132
+ - lib/hydra/collections/selects_collections.rb
133
+ - lib/hydra/collections/solr_document_behavior.rb
124
134
  - lib/hydra/collections/version.rb
125
135
  - lib/hydra/collections_controller_behavior.rb
126
136
  - lib/hydra/datastreams/collection_rdf_datastream.rb
@@ -128,7 +138,9 @@ files:
128
138
  - solr_conf/conf/solrconfig.xml
129
139
  - solr_conf/solr.xml
130
140
  - spec/controllers/accepts_batches_spec.rb
141
+ - spec/controllers/catalog_controller_spec.rb
131
142
  - spec/controllers/collections_controller_spec.rb
143
+ - spec/controllers/selects_collections_spec.rb
132
144
  - spec/factories.rb
133
145
  - spec/factories/.gitkeep
134
146
  - spec/factories/users.rb
@@ -141,6 +153,7 @@ files:
141
153
  - spec/support/app/models/sample.rb
142
154
  - spec/support/app/models/solr_document.rb
143
155
  - spec/support/app/views/catalog/_document_header.html.erb
156
+ - spec/support/app/views/catalog/_index_collection.html.erb
144
157
  - spec/support/app/views/catalog/_sort_and_per_page.html.erb
145
158
  - spec/support/config/initializers/hydra_config.rb
146
159
  - spec/support/db/migrate/20111101221803_create_searches.rb
@@ -174,7 +187,9 @@ specification_version: 4
174
187
  summary: A rails engine for managing Hydra Collections
175
188
  test_files:
176
189
  - spec/controllers/accepts_batches_spec.rb
190
+ - spec/controllers/catalog_controller_spec.rb
177
191
  - spec/controllers/collections_controller_spec.rb
192
+ - spec/controllers/selects_collections_spec.rb
178
193
  - spec/factories.rb
179
194
  - spec/factories/.gitkeep
180
195
  - spec/factories/users.rb
@@ -187,6 +202,7 @@ test_files:
187
202
  - spec/support/app/models/sample.rb
188
203
  - spec/support/app/models/solr_document.rb
189
204
  - spec/support/app/views/catalog/_document_header.html.erb
205
+ - spec/support/app/views/catalog/_index_collection.html.erb
190
206
  - spec/support/app/views/catalog/_sort_and_per_page.html.erb
191
207
  - spec/support/config/initializers/hydra_config.rb
192
208
  - spec/support/db/migrate/20111101221803_create_searches.rb