Skip to content
This repository was archived by the owner on Jan 5, 2019. It is now read-only.

Commit c891102

Browse files
committed
Merge pull request #156 from ualbertalib/collection-form
Modified the Collection form to reflect the HN data dictionary
2 parents 1fc302b + 5517133 commit c891102

File tree

9 files changed

+193
-62
lines changed

9 files changed

+193
-62
lines changed

app/controllers/concerns/hydranorth/collections_controller_behavior.rb

+6-59
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,6 @@ module CollectionsControllerBehavior
33
extend ActiveSupport::Concern
44
include Sufia::CollectionsControllerBehavior
55

6-
included do
7-
include Blacklight::Catalog::SearchContext
8-
include BlacklightAdvancedSearch::ParseBasicQ
9-
include BlacklightAdvancedSearch::Controller
10-
include Hydranorth::Breadcrumbs
11-
12-
before_filter :filter_docs_with_read_access!, except: :show
13-
before_filter :has_access?, except: :show
14-
before_filter :build_breadcrumbs, only: [:edit, :show]
15-
16-
self.solr_search_params_logic += [:add_access_controls_to_solr_params]
17-
18-
layout "sufia-one-column"
19-
end
20-
21-
def new
22-
super
23-
form
24-
end
25-
26-
def edit
27-
super
28-
form
29-
end
306

317
def show
328
if current_user.group_list == 'admin'
@@ -39,49 +15,20 @@ def show
3915

4016
protected
4117

42-
def presenter
43-
@presenter ||= presenter_class.new(@collection)
44-
end
45-
4618
def presenter_class
47-
Sufia::CollectionPresenter
19+
Hydranorth::CollectionPresenter
4820
end
4921

5022
def collection_params
51-
params.require(:collection).permit(:title, :description, :members, part_of: [],
52-
contributor: [], creator: [], publisher: [], date_created: [], subject: [],
53-
language: [], rights: [], resource_type: [], identifier: [], based_near: [],
54-
tag: [], related_url: [])
55-
end
56-
57-
def query_collection_members
58-
flash[:notice]=nil if flash[:notice] == "Select something first"
59-
query = params[:cq]
60-
61-
#merge in the user parameters and the attach the collection query
62-
solr_params = (params.symbolize_keys).merge(q: query)
63-
64-
# run the solr query to find the collections
65-
(@response, @member_docs) = get_search_results(solr_params)
66-
end
67-
68-
def after_destroy(id)
69-
respond_to do |format|
70-
format.html { redirect_to sufia.dashboard_collections_path, notice: 'Collection was successfully deleted.' }
71-
format.json { render json: {id: id}, status: :destroyed, location: @collection }
72-
end
73-
end
74-
75-
def form
76-
@form ||= form_class.new(@collection)
23+
params.require(:collection).permit(:title, :description, :license, :members, part_of: [],
24+
creator: [], date_created: [], subject: [],
25+
rights: [], resource_type: [], identifier: [])
26+
7727
end
7828

7929
def form_class
80-
Sufia::Forms::CollectionEditForm
30+
Hydranorth::Forms::CollectionEditForm
8131
end
8232

83-
def _prefixes
84-
@_prefixes ||= super + ['catalog']
85-
end
8633
end
8734
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module Hydranorth
2+
module Forms
3+
class CollectionEditForm
4+
include HydraEditor::Form
5+
self.model_class = ::Collection
6+
self.terms = [:title, :creator, :description, :license]
7+
self.required_fields = [:title, :license ]
8+
# Test to see if the given field is required
9+
# @param [Symbol] key a field
10+
# @return [Boolean] is it required or not
11+
def required?(key)
12+
model_class.validators_on(key).any?{|v| v.kind_of? ActiveModel::Validations::PresenceValidator}
13+
end
14+
end
15+
end
16+
end

app/models/collection.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
class Collection < Sufia::Collection
2+
include Hydranorth::Collections::Metadata
23
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module Hydranorth::Collections
2+
module Metadata
3+
extend ActiveSupport::Concern
4+
included do
5+
property :license, predicate: RDF::DC.license, multiple:false do |index|
6+
index.as :stored_searchable
7+
end
8+
end
9+
end
10+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
module Hydranorth
2+
class CollectionPresenter
3+
include Hydra::Presenter
4+
include ActionView::Helpers::NumberHelper
5+
6+
self.model_class = ::Collection
7+
# Terms is the list of fields displayed by app/views/collections/_show_descriptions.html.erb
8+
self.terms = [:title, :total_items, :size, :description, :creator,
9+
:license, :date_created]
10+
11+
# Depositor and permissions are not displayed in app/views/collections/_show_descriptions.html.erb
12+
# so don't include them in `terms'.
13+
# delegate :depositor, :permissions, to: :model
14+
15+
def terms_with_values
16+
terms.select { |t| self[t].present? }
17+
end
18+
19+
def [](key)
20+
case key
21+
when :size
22+
size
23+
when :total_items
24+
total_items
25+
else
26+
super
27+
end
28+
end
29+
30+
def size
31+
number_to_human_size(model.bytes)
32+
end
33+
34+
def total_items
35+
model.members.count
36+
end
37+
38+
end
39+
end
40+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<div class="modal-div">
2+
<!-- Modal -->
3+
<div class="modal fade" id="licenseModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
4+
<div class="modal-dialog">
5+
<div class="modal-content">
6+
<div class="modal-header">
7+
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
8+
<h2 id="licenseModallLabel"><%= t('sufia.product_name') %> License Descriptions</h2>
9+
</div>
10+
<div class="modal-body">
11+
<p>Creative Commons licenses can take the following combinations, which is what a depositor sees on the page where metadata (descriptions) are entered. Via the drop-down menu, the depositor may select any of the following licenses (these are all described at "About the Licenses" on the Creative Commons site):
12+
</p> <ul>
13+
<li><b>Attribution 4.0 International</b><br/>
14+
With this license you allow others to "distribute, remix, tweak, and build" on your deposited content - including for commercial purposes - provided they attribute you as the original creator.<a href="http://creativecommons.org/licenses/by/4.0/" target="_blank">(Link to Attribution 4.0 International)</a></li>
15+
<li><b>Attribution-ShareAlike 4.0 International</b> <br/>
16+
With this license you allow others to "remix, tweak, and build" on your deposited content, including for commercial uses, provided they attribute you as the original creator AND incorporate the same level of licensing for the newly resulting creation. "All new works based on yours will carry the same license, so any derivatives will also allow commercial use."<a href="http://creativecommons.org/licenses/by-sa/4.0/" target="_blank">(Link to Attribution-ShareAlike 4.0 International)</a></li>
17+
<li><b>Attribution-NonCommercial 4.0 International</b><br/>
18+
With this license you allow others to "remix, tweak, and build" on your content in non-commercial ways. While they must credit you as the original creator and while the remixed, tweaked, or expanded upon content must remain non-commercial, they do not have to apply identical license terms on the new content.<a href="http://creativecommons.org/licenses/by-nc/4.0/" target="_blank">(Link to Attribution-NonCommercial 4.0 International)</a></li>
19+
<li><b>Attribution-NoDerivs 4.0 International</b><br/>
20+
With this license you share your work with others and allow them to download your work, provided they attribute you as the creator and refrain from changing the content in any way<a href="http://creativecommons.org/licenses/by-nd/4.0/" target="_blank">(Link to Attribution-NoDerivs 4.0 International)</a> </li>
21+
<li><b>Attribution-NonCommercial-NoDerivs 4.0 International</b><br/>
22+
With this license you share your work with others and allow them to download your work, provided they attribute you as the creator and refrain from changing the content in any way and from using it for commercial means.<a href="http://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank">(Link to Attribution-NonCommercial-NoDerivs 4.0 International)</a></li>
23+
<li><b>Attribution-NonCommercial-ShareAlike 4.0 International</b><br/>
24+
With this license you allow others to "remix, tweak, and build" on your content in non-commercial ways, provided they attribute you as the original creator AND incorporate the same level of licensing for the newly resulting creation. "All new works based on yours will carry the same license, so any derivatives will also allow commercial use.<a href="http://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">(Link to Attribution-NonCommercial-ShareAlike 4.0 International)</a> </li>
25+
<li><b>Public Domain Mark 1.0 </b><br/>
26+
When content is in the public domain, it has no known copyright owner.<a href="http://creativecommons.org/publicdomain/mark/1.0/" target="_blank">(Link to Public Domain Mark 1.0</a> </li>
27+
<li><b>CC0 1.0 Universal </b><br/>
28+
With this license you are waiving your rights as copyright owner to the content you upload. This means your content may be distributed and reused without attribution, without restriction. CC0 is a license that one applies to one's own work; rarely does one apply it to another's work, unless one has the appropriate rights to do so.<a href="https://creativecommons.org/publicdomain/zero/1.0/" target="_blank">(Link to CC0 1.0 Universal)</a></li>
29+
</ul>
30+
</p>
31+
<p> Please note: Another license option that is listed is <b>"All rights reserved."</b> With this license you - as the copyright holder - reserve all rights held under copyright law, such as for distribution and creation of derivative works. This means that no one can use your content in a work - such as a presentation or article - or create derivatives from it without your permission.</p>
32+
</div>
33+
<div class="modal-footer">
34+
<button class="btn btn-primary" data-dismiss="modal">Close</button>
35+
</div>
36+
</div>
37+
</div>
38+
</div>
39+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<%= f.input :license, as: :select_with_modal_help, collection: Sufia.config.cc_licenses,
2+
input_html: { class: 'form-control', required: true }, include_blank: true %>
3+
<%= render "collections/license_modal" %>

config/locales/sufia.en.yml

+11-3
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,9 @@ en:
175175
is_version_of: "Citation for previous publication"
176176
source: "Source"
177177
collection:
178-
description: "Abstract or Summary"
178+
description: "Description"
179179
subject: "Subject/Keyword"
180180
date_created: "Date Created"
181-
related_url: "Related URL"
182181
total_items: "Total Items"
183182
size: "Size"
184183

@@ -204,14 +203,23 @@ en:
204203
source: "Brief information about a physical item from which this item was derived."
205204
is_version_of: "If your item has been previously published, provide a citation"
206205
related_url: "must be a url - example: http://www.ualberta.ca"
206+
collection:
207+
title: "A name for the collection to aid in identifying it. &lt;em&gt;This is a required field&lt;/em&gt;."
208+
description: "Free-text notes about the collection. "
209+
creator_html: "The person or group responsible for the file being uploaded. Usually this is the author of the content. Personal names should be entered with the last name first, e.g. &quot;Smith, John.&quot; &lt;em&gt;This is a required field&lt;/em&gt;."
210+
resource_type_html: "Pre-defined categories to describe the type of file content included in the collection, such as &quot;article&quot; or &quot;dataset.&quot."
207211

208212
aria_label:
209213
generic_file:
210214
default: "Usage information for %{title}"
211215
based_near: "Usage information for location"
212216
description: "Usage information for abstract or summary"
213-
tag: "Usage information for keyword"
217+
subject: "Usage information for keyword"
214218
rights: "Usage information for rights"
219+
license: "Usage information for license"
220+
collection:
221+
default: "Usage information for %{title}"
222+
license: "Usage information for license"
215223

216224
hydranorth:
217225
dashboard:

spec-views/collection_form_spec.rb

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
require "json"
2+
require "selenium-webdriver"
3+
require "rspec"
4+
require "./spec-views/helper.rb"
5+
require "./spec-views/before.rb"
6+
require "./spec-views/after.rb"
7+
require "./spec-views/user.rb"
8+
include RSpec::Expectations
9+
10+
include Before
11+
include After
12+
13+
describe "Collection Creation Form" do
14+
15+
setup
16+
17+
teardown
18+
19+
it "form is up and new collection is created" do
20+
@driver.get(@base_url + "/")
21+
@driver.find_element(:link, "Login").click
22+
verify { (@driver.current_url).should == @base_url+"/users/sign_in"}
23+
@driver.find_element(:id, "user_email").clear
24+
@driver.find_element(:id, "user_email").send_keys @properties['admin']['name']
25+
@driver.find_element(:id, "user_password").clear
26+
@driver.find_element(:id, "user_password").send_keys @properties['admin']['password']
27+
@driver.find_element(:name, "commit").click
28+
@driver.get(@base_url + "/")
29+
30+
@driver.find_element(:id, "dashboard_link").click
31+
@driver.find_element(:id, "hydra-collection-add").click
32+
33+
verify { @driver.current_url.should == @base_url+"/collections/new" }
34+
verify { @driver.find_element(:xpath, "//label[@for = 'collection_title']/abbr[@title = 'required']").displayed? == true }
35+
title = @driver.find_element(:id, "collection_title")
36+
title.clear
37+
title.send_keys("Test Collection from Selenium")
38+
@driver.find_element(:id, "collection_creator").send_keys @properties['user1']['name']
39+
@driver.find_element(:id, "collection_description").send_keys "Test description for the test collection."
40+
41+
select_license = @driver.find_element(:id, "collection_license")
42+
option = Selenium::WebDriver::Support::Select.new(select_license)
43+
option.select_by(:text, "Public Domain Mark 1.0")
44+
verify { @driver.find_element(:xpath, "//label[@for = 'collection_license']/abbr[@title = 'required']").displayed? == true }
45+
@driver.find_element(:id, "create_submit").click
46+
47+
verify { @driver.current_url.should include @base_url + "/collections/" }
48+
collection_id = @driver.current_url.match(/#{@base_url}\/collections\/(.*)$/)[1]
49+
verify { (@driver.find_element(:class, "alert-success").text).should include "Collection was successfully created."}
50+
verify { @driver.find_element(:css, "h1").text.should == "Test Collection from Selenium" }
51+
verify { @driver.find_element(:class, "collection_description").text.should == "Test description for the test collection." }
52+
verify { @driver.find_element(:xpath, "//span[@itemprop = 'creator']/span/a").text.should == @properties['user1']['name'] }
53+
54+
verify { @driver.find_element(:xpath, "//span[@itemprop = 'total_items']").text.should == "0" }
55+
verify { @driver.find_element(:xpath, "//dt[contains(text(), 'License')]/following-sibling::dd/a").text.should == "Public Domain Mark 1.0" }
56+
@driver.find_element(:link, "My Collections").click
57+
verify { @driver.current_url.should == @base_url + "/dashboard/collections" }
58+
collection = @driver.find_element(:id, "document_"+collection_id)
59+
collection.find_element(:id, "dropdownMenu_"+collection_id).click
60+
delete = "//ul[@aria-labelledby = 'dropdownMenu_"+collection_id+"']//a[@title='Delete Collection']"
61+
collection.find_element(:xpath, delete).click
62+
@driver.switch_to.alert.accept
63+
end
64+
65+
end
66+
67+

0 commit comments

Comments
 (0)