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

Commit

Permalink
Merge pull request #156 from ualbertalib/collection-form
Browse files Browse the repository at this point in the history
Modified the Collection form to reflect the HN data dictionary
  • Loading branch information
pgwillia committed Mar 30, 2015
2 parents 1fc302b + 5517133 commit c891102
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,6 @@ module CollectionsControllerBehavior
extend ActiveSupport::Concern
include Sufia::CollectionsControllerBehavior

included do
include Blacklight::Catalog::SearchContext
include BlacklightAdvancedSearch::ParseBasicQ
include BlacklightAdvancedSearch::Controller
include Hydranorth::Breadcrumbs

before_filter :filter_docs_with_read_access!, except: :show
before_filter :has_access?, except: :show
before_filter :build_breadcrumbs, only: [:edit, :show]

self.solr_search_params_logic += [:add_access_controls_to_solr_params]

layout "sufia-one-column"
end

def new
super
form
end

def edit
super
form
end

def show
if current_user.group_list == 'admin'
Expand All @@ -39,49 +15,20 @@ def show

protected

def presenter
@presenter ||= presenter_class.new(@collection)
end

def presenter_class
Sufia::CollectionPresenter
Hydranorth::CollectionPresenter
end

def collection_params
params.require(:collection).permit(:title, :description, :members, part_of: [],
contributor: [], creator: [], publisher: [], date_created: [], subject: [],
language: [], rights: [], resource_type: [], identifier: [], based_near: [],
tag: [], related_url: [])
end

def query_collection_members
flash[:notice]=nil if flash[:notice] == "Select something first"
query = params[:cq]

#merge in the user parameters and the attach the collection query
solr_params = (params.symbolize_keys).merge(q: query)

# run the solr query to find the collections
(@response, @member_docs) = get_search_results(solr_params)
end

def after_destroy(id)
respond_to do |format|
format.html { redirect_to sufia.dashboard_collections_path, notice: 'Collection was successfully deleted.' }
format.json { render json: {id: id}, status: :destroyed, location: @collection }
end
end

def form
@form ||= form_class.new(@collection)
params.require(:collection).permit(:title, :description, :license, :members, part_of: [],
creator: [], date_created: [], subject: [],
rights: [], resource_type: [], identifier: [])

end

def form_class
Sufia::Forms::CollectionEditForm
Hydranorth::Forms::CollectionEditForm
end

def _prefixes
@_prefixes ||= super + ['catalog']
end
end
end
16 changes: 16 additions & 0 deletions app/forms/hydranorth/forms/collection_edit_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module Hydranorth
module Forms
class CollectionEditForm
include HydraEditor::Form
self.model_class = ::Collection
self.terms = [:title, :creator, :description, :license]
self.required_fields = [:title, :license ]
# Test to see if the given field is required
# @param [Symbol] key a field
# @return [Boolean] is it required or not
def required?(key)
model_class.validators_on(key).any?{|v| v.kind_of? ActiveModel::Validations::PresenceValidator}
end
end
end
end
1 change: 1 addition & 0 deletions app/models/collection.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
class Collection < Sufia::Collection
include Hydranorth::Collections::Metadata
end
10 changes: 10 additions & 0 deletions app/models/concerns/hydranorth/collections/metadata.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Hydranorth::Collections
module Metadata
extend ActiveSupport::Concern
included do
property :license, predicate: RDF::DC.license, multiple:false do |index|
index.as :stored_searchable
end
end
end
end
40 changes: 40 additions & 0 deletions app/presenters/hydranorth/collection_presenter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module Hydranorth
class CollectionPresenter
include Hydra::Presenter
include ActionView::Helpers::NumberHelper

self.model_class = ::Collection
# Terms is the list of fields displayed by app/views/collections/_show_descriptions.html.erb
self.terms = [:title, :total_items, :size, :description, :creator,
:license, :date_created]

# Depositor and permissions are not displayed in app/views/collections/_show_descriptions.html.erb
# so don't include them in `terms'.
# delegate :depositor, :permissions, to: :model

def terms_with_values
terms.select { |t| self[t].present? }
end

def [](key)
case key
when :size
size
when :total_items
total_items
else
super
end
end

def size
number_to_human_size(model.bytes)
end

def total_items
model.members.count
end

end
end

39 changes: 39 additions & 0 deletions app/views/collections/_license_modal.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<div class="modal-div">
<!-- Modal -->
<div class="modal fade" id="licenseModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
<h2 id="licenseModallLabel"><%= t('sufia.product_name') %> License Descriptions</h2>
</div>
<div class="modal-body">
<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):
</p> <ul>
<li><b>Attribution 4.0 International</b><br/>
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>
<li><b>Attribution-ShareAlike 4.0 International</b> <br/>
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>
<li><b>Attribution-NonCommercial 4.0 International</b><br/>
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>
<li><b>Attribution-NoDerivs 4.0 International</b><br/>
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>
<li><b>Attribution-NonCommercial-NoDerivs 4.0 International</b><br/>
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>
<li><b>Attribution-NonCommercial-ShareAlike 4.0 International</b><br/>
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>
<li><b>Public Domain Mark 1.0 </b><br/>
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>
<li><b>CC0 1.0 Universal </b><br/>
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>
</ul>
</p>
<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>
</div>
<div class="modal-footer">
<button class="btn btn-primary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
3 changes: 3 additions & 0 deletions app/views/records/edit_fields/_license.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<%= f.input :license, as: :select_with_modal_help, collection: Sufia.config.cc_licenses,
input_html: { class: 'form-control', required: true }, include_blank: true %>
<%= render "collections/license_modal" %>
14 changes: 11 additions & 3 deletions config/locales/sufia.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,9 @@ en:
is_version_of: "Citation for previous publication"
source: "Source"
collection:
description: "Abstract or Summary"
description: "Description"
subject: "Subject/Keyword"
date_created: "Date Created"
related_url: "Related URL"
total_items: "Total Items"
size: "Size"

Expand All @@ -204,14 +203,23 @@ en:
source: "Brief information about a physical item from which this item was derived."
is_version_of: "If your item has been previously published, provide a citation"
related_url: "must be a url - example: http://www.ualberta.ca"
collection:
title: "A name for the collection to aid in identifying it. &lt;em&gt;This is a required field&lt;/em&gt;."
description: "Free-text notes about the collection. "
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;."
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."

aria_label:
generic_file:
default: "Usage information for %{title}"
based_near: "Usage information for location"
description: "Usage information for abstract or summary"
tag: "Usage information for keyword"
subject: "Usage information for keyword"
rights: "Usage information for rights"
license: "Usage information for license"
collection:
default: "Usage information for %{title}"
license: "Usage information for license"

hydranorth:
dashboard:
Expand Down
67 changes: 67 additions & 0 deletions spec-views/collection_form_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
require "json"
require "selenium-webdriver"
require "rspec"
require "./spec-views/helper.rb"
require "./spec-views/before.rb"
require "./spec-views/after.rb"
require "./spec-views/user.rb"
include RSpec::Expectations

include Before
include After

describe "Collection Creation Form" do

setup

teardown

it "form is up and new collection is created" do
@driver.get(@base_url + "/")
@driver.find_element(:link, "Login").click
verify { (@driver.current_url).should == @base_url+"/users/sign_in"}
@driver.find_element(:id, "user_email").clear
@driver.find_element(:id, "user_email").send_keys @properties['admin']['name']
@driver.find_element(:id, "user_password").clear
@driver.find_element(:id, "user_password").send_keys @properties['admin']['password']
@driver.find_element(:name, "commit").click
@driver.get(@base_url + "/")

@driver.find_element(:id, "dashboard_link").click
@driver.find_element(:id, "hydra-collection-add").click

verify { @driver.current_url.should == @base_url+"/collections/new" }
verify { @driver.find_element(:xpath, "//label[@for = 'collection_title']/abbr[@title = 'required']").displayed? == true }
title = @driver.find_element(:id, "collection_title")
title.clear
title.send_keys("Test Collection from Selenium")
@driver.find_element(:id, "collection_creator").send_keys @properties['user1']['name']
@driver.find_element(:id, "collection_description").send_keys "Test description for the test collection."

select_license = @driver.find_element(:id, "collection_license")
option = Selenium::WebDriver::Support::Select.new(select_license)
option.select_by(:text, "Public Domain Mark 1.0")
verify { @driver.find_element(:xpath, "//label[@for = 'collection_license']/abbr[@title = 'required']").displayed? == true }
@driver.find_element(:id, "create_submit").click

verify { @driver.current_url.should include @base_url + "/collections/" }
collection_id = @driver.current_url.match(/#{@base_url}\/collections\/(.*)$/)[1]
verify { (@driver.find_element(:class, "alert-success").text).should include "Collection was successfully created."}
verify { @driver.find_element(:css, "h1").text.should == "Test Collection from Selenium" }
verify { @driver.find_element(:class, "collection_description").text.should == "Test description for the test collection." }
verify { @driver.find_element(:xpath, "//span[@itemprop = 'creator']/span/a").text.should == @properties['user1']['name'] }

verify { @driver.find_element(:xpath, "//span[@itemprop = 'total_items']").text.should == "0" }
verify { @driver.find_element(:xpath, "//dt[contains(text(), 'License')]/following-sibling::dd/a").text.should == "Public Domain Mark 1.0" }
@driver.find_element(:link, "My Collections").click
verify { @driver.current_url.should == @base_url + "/dashboard/collections" }
collection = @driver.find_element(:id, "document_"+collection_id)
collection.find_element(:id, "dropdownMenu_"+collection_id).click
delete = "//ul[@aria-labelledby = 'dropdownMenu_"+collection_id+"']//a[@title='Delete Collection']"
collection.find_element(:xpath, delete).click
@driver.switch_to.alert.accept
end

end


0 comments on commit c891102

Please sign in to comment.