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

Commit da2661c

Browse files
committed
Merge branch 'Sprint43'
2 parents 29c8e22 + 291c86c commit da2661c

27 files changed

+383
-108
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
$(document).ready(function(){
2+
if ($("#descriptions_display").length){
3+
var checkbox = document.getElementById('collection_is_community');
4+
var logo_div = document.getElementById('logo');
5+
var logo = document.getElementById('collection_logo');
6+
7+
if (checkbox.checked) {
8+
logo_div.style['display'] = 'block';
9+
}
10+
11+
checkbox.onchange = function() {
12+
if(this.checked) {
13+
logo_div.style['display'] = 'block';
14+
} else {
15+
logo_div.style['display'] = 'none';
16+
}};
17+
18+
logo.onchange = function() {
19+
validateFiles(logo);
20+
};
21+
22+
function validateFiles(inputFile) {
23+
var maxExceededMessage = "This file exceeds the maximum allowed file size (20 KB)";
24+
var extErrorMessage = "Only image file with extension: .jpg, .jpeg, .gif or .png is allowed";
25+
var allowedExtension = ["jpg", "jpeg", "gif", "png"];
26+
27+
var extName;
28+
var file = inputFile.files[0];
29+
var maxFileSize = $(inputFile).data('max-file-size');
30+
var sizeExceeded = false;
31+
var extError = false;
32+
33+
if (file.size && maxFileSize && file.size > parseInt(maxFileSize)) {sizeExceeded=true;};
34+
extName = file.name.split('.').pop();
35+
if ($.inArray(extName, allowedExtension) == -1) {extError=true;};
36+
37+
if (sizeExceeded) {
38+
window.alert(maxExceededMessage);
39+
$(inputFile).val('');
40+
};
41+
42+
if (extError) {
43+
window.alert(extErrorMessage);
44+
$(inputFile).val('');
45+
};
46+
}
47+
}
48+
});

app/assets/stylesheets/era_custom.css.scss

+5
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,11 @@ i.glyphicon{
976976
background-color: #fff;
977977
}
978978

979+
#community-logo img{
980+
padding-top: 20%;
981+
width: 80%;
982+
}
983+
979984
/* Upload form */
980985
.agreement-text {
981986
height: 180px;

app/controllers/catalog_controller.rb

+5-7
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,13 @@ def set_solr_search_fields
197197
}
198198
end
199199

200-
config.add_search_field('date_created') do |field|
200+
config.add_search_field('date') do |field|
201201
field.label = "Date"
202-
field.solr_parameters = {
203-
:"spellcheck.dictionary" => "date_created"
204-
}
205-
solr_name = Solrizer.solr_name("created", :stored_searchable)
202+
field.solr_parameters = { :"spellcheck.dictionary" => "date_accepted", :"spellcheck.dictionary" => "date_created" }
203+
field_included = [Solrizer.solr_name("date_created", :stored_searchable), Solrizer.solr_name("date_accepted", :stored_searchable)].join(" ")
206204
field.solr_local_parameters = {
207-
qf: solr_name,
208-
pf: solr_name
205+
qf: field_included,
206+
pf: field_included
209207
}
210208
end
211209

app/controllers/concerns/hydranorth/collections/selects_collections.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ def find_communities(access_level = nil)
4747
authenticate_user! unless access_level.blank?
4848

4949
# run the solr query to find the collections
50-
query = collections_search_builder(access_level).with({q: '(is_community_bsi:true OR is_community_tesim:true) AND (is_official_bsi:true OR is_official_tesim:true) '}).query
50+
if access_level.blank?
51+
query = collections_search_builder(access_level).with({q: '(is_community_bsi:true OR is_community_tesim:true) AND (is_official_bsi:true OR is_official_tesim:true) '}).query
52+
else
53+
query = collections_search_builder(access_level).with({q: '(is_community_bsi:true OR is_community_tesim:true) AND (is_official_bsi:true OR is_official_tesim:true) AND is_admin_set_bsi:false'}).query
54+
end
5155
response = repository.search(query)
5256
# return the user's collections (or public collections if no access_level is applied)
5357
# not a fan of sorting this in ruby, but collections search builder doesn't seem to pass on

app/controllers/concerns/hydranorth/collections_controller_behavior.rb

+22
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,24 @@ def show
1313
presenter
1414
end
1515

16+
def update
17+
if params[:collection][:logo]
18+
mime_type = params[:collection][:logo].content_type
19+
original_filename = params[:collection][:logo].original_filename
20+
@collection.add_file(params[:collection][:logo].tempfile, path: 'logo', original_name: original_filename, mine_type: mime_type)
21+
end
22+
super
23+
end
24+
25+
def create
26+
if params[:collection][:logo]
27+
mime_type = params[:collection][:logo].content_type
28+
original_filename = params[:collection][:logo].original_filename
29+
@collection.add_file(params[:collection][:logo].tempfile, path: 'logo', original_name: original_filename, mine_type: mime_type)
30+
end
31+
super
32+
end
33+
1634
protected
1735

1836
# override Sufia::CollectionsControllerBehavior#presenter to establish
@@ -40,6 +58,10 @@ def form_class
4058

4159
protected
4260

61+
def logo
62+
send_data(collection.logo, filename: "image", type: "text/xml", disposition: "inline")
63+
end
64+
4365
# these methods enhacnce hydra-collection's collections_controller_behaviour
4466

4567
def add_members_to_collection collection = nil

app/controllers/concerns/hydranorth/communities_controller_behavior.rb

+6
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,11 @@ module CommunitiesControllerBehavior
1313

1414
def index
1515
end
16+
17+
def logo
18+
@community = Collection.find(params[:id])
19+
send_data @community.logo.content, disposition: 'inline'
20+
end
21+
1622
end
1723
end

app/controllers/concerns/hydranorth/files_controller_behavior.rb

+1-29
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@ module FilesControllerBehavior
1111
include Hydranorth::Breadcrumbs
1212

1313

14-
included do
15-
self.edit_form_class = Hydranorth::Forms::GenericFileEditForm
16-
self.presenter_class = Hydranorth::GenericFilePresenter
17-
end
18-
19-
2014
protected
2115

2216
def actor
@@ -27,38 +21,16 @@ def attributes
2721
attributes = params
2822
end
2923

30-
def presenter
31-
if @generic_file[:resource_type].include? Sufia.config.special_types['cstr']
32-
Hydranorth::CstrPresenter.new(@generic_file)
33-
elsif @generic_file[:resource_type].include? Sufia.config.special_types['ser']
34-
Hydranorth::SerPresenter.new(@generic_file)
35-
elsif @generic_file[:remote_resource] == "dataverse"
36-
Hydranorth::DataversePresenter.new(@generic_file)
37-
elsif @generic_file[:resource_type].include? Sufia.config.special_types['thesis']
38-
Hydranorth::ThesisPresenter.new(@generic_file)
39-
else
40-
Hydranorth::GenericFilePresenter.new(@generic_file)
41-
end
42-
end
4324

4425
def edit_form
4526
find_collections_with_read_access
4627
find_communities_with_read_access
4728

4829
@community_collections = collections_for_community(@generic_file.belongsToCommunity.first)
4930

50-
if @generic_file[:resource_type].include? Sufia.config.special_types['cstr']
51-
Hydranorth::Forms::CstrEditForm.new(@generic_file)
52-
elsif @generic_file[:resource_type].include? Sufia.config.special_types['ser']
53-
Hydranorth::Forms::SerEditForm.new(@generic_file)
54-
elsif @generic_file[:resource_type].include? Sufia.config.special_types['thesis']
55-
Hydranorth::Forms::ThesisEditForm.new(@generic_file)
56-
else
57-
Hydranorth::Forms::GenericFileEditForm.new(@generic_file)
58-
end
31+
super
5932
end
6033

61-
6234
def process_file(file)
6335
Batch.find_or_create(params[:batch_id])
6436

app/controllers/generic_files_controller.rb

+32
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,37 @@ def update_collections
2121
end
2222
end
2323

24+
def cstr_resource?
25+
@generic_file[:resource_type].include? Sufia.config.special_types['cstr']
26+
end
27+
28+
def ser_resource?
29+
@generic_file[:resource_type].include? Sufia.config.special_types['ser']
30+
end
31+
32+
def dataverse_resource?
33+
@generic_file[:remote_resource] == "dataverse"
34+
end
35+
36+
def thesis_resource?
37+
@generic_file[:resource_type].include? Sufia.config.special_types['thesis']
38+
end
39+
40+
def presenter_class
41+
super unless @generic_file
42+
return Hydranorth::CstrPresenter if cstr_resource?
43+
return Hydranorth::SerPresenter if ser_resource?
44+
return Hydranorth::DataversePresenter if dataverse_resource?
45+
return Hydranorth::ThesisPresenter if thesis_resource?
46+
Hydranorth::GenericFilePresenter
47+
end
48+
49+
def edit_form_class
50+
super unless @generic_file
51+
return Hydranorth::Forms::CstrEditForm if cstr_resource?
52+
return Hydranorth::Forms::SerEditForm if ser_resource?
53+
return Hydranorth::Forms::ThesisEditForm if thesis_resource?
54+
Hydranorth::Forms::GenericFileEditForm
55+
end
2456

2557
end

app/models/ability.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def custom_permissions
1818
end
1919
cannot :create, ::Collection
2020
cannot :destroy, ::Collection unless admin?
21-
cannot :manage, ::Collection do |obj|
21+
cannot [:edit, :update], ::Collection do |obj|
2222
obj.is_admin_set?
2323
end unless admin?
2424
can :manage, :all if admin?

app/models/concerns/hydranorth/collection_behavior.rb

+9-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ module CollectionBehavior
99
include Hydra::Collections::Collectible
1010
include Hydra::AccessControls::Permissions
1111
include Hydra::Collections::Metadata
12+
include Hydranorth::Collections::Logo
1213

1314
included do
14-
before_save :remove_self_from_members, :update_permissions
15+
before_save :remove_self_from_members, :update_permissions, :check_logo_size
1516
validates :title, presence: true
1617
end
1718

@@ -31,6 +32,13 @@ def find_or_create_with_type(resource_type)
3132
end
3233
end
3334
end
35+
36+
def check_logo_size
37+
size = logo.size
38+
if size.to_i > 200.kilobytes
39+
raise "Collection logo larger than 200KB"
40+
end
41+
end
3442

3543
def update_permissions
3644
self.visibility = "open"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module Hydranorth
2+
module Collections
3+
module Logo
4+
extend ActiveSupport::Concern
5+
included do
6+
contains "logo", class_name: 'LogoDatastream'
7+
end
8+
9+
end
10+
end
11+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class LogoDatastream < ActiveFedora::File
2+
include Sufia::FileContent::Versions
3+
end

app/views/collections/_form.html.erb

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1+
<%= javascript_include_tag 'modules/community-logo' %>
12
<%= simple_form_for [collections, @form], html: {class: 'form-horizontal editor'} do |f| %>
23
<div id="descriptions_display">
3-
4+
45
<div class="well">
5-
<p><small><span class="error">*</span> indicates required fields</small></p>
6+
<p><small><span class="error">*</span> indicates required fields</small></p>
7+
68
<% f.object.terms.each do |term| %>
79
<%= render_edit_field_partial term, f: f %>
810
<% end %>
11+
<br/><br/>
12+
<div id="logo" style="display:none">
13+
<span style="font-weight:bold">Logo</span>
14+
<%= f.label :logo do %>
15+
<%= f.file_field :logo, :onchange =>"validateFiles(this);", :data => {:max_file_size => 20.kilobytes} %>
16+
<% end %>
17+
</div>
918
</div><!-- /well -->
1019
</div>
1120
<%= hidden_field_tag :type, params[:type] %>

app/views/collections/edit.html.erb

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<% @page_title = "Edit Collection #{display_title(@collection)} - #{application_name}" %>
2+
<%= render_breadcrumbs builder: Sufia::BootstrapBreadcrumbsBuilder %>
3+
<h1>Edit Collection: <%= display_title(@collection) %></h1>
4+
5+
<% unless has_collection_search_parameters? %>
6+
<div class="row">
7+
<div class="col-xs-12 col-sm-10 pull-right">
8+
<%= render 'collections/form' %>
9+
</div>
10+
<div class="col-xs-12 col-sm-2">
11+
<div id="community-logo">
12+
<%= image_tag url_for(:controller => 'communities', action: 'logo', id: @collection.id), alt: "No logo" %>
13+
</div>
14+
<%= render 'collections/edit_actions' %>
15+
</div>
16+
</div>
17+
<% end %>
18+
19+
<h2>Manage Items in this Collection</h2>
20+
<%= render 'search_collection_dashboard_form'%>
21+
<%= render 'my/did_you_mean' %>
22+
<%= render 'my/facet_selected' %>
23+
<%= render 'collections/sort_and_per_page' %>
24+
<%= render 'document_list', documents: @member_docs, document_list_format: "dashboard" %>
25+
<%= render 'paginate' %>

app/views/collections/show.html.erb

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
</header>
1111
</div>
1212
<div class="col-sm-2">
13-
<%= render partial: 'collections/media_display', locals: { generic_file: @collection } %>
13+
<div id="community-logo">
14+
<%= image_tag url_for(:controller => 'communities', action: 'logo', id: @collection.id), alt: "No logo" %>
15+
</div>
1416
<% if !current_user.nil? %>
1517
<% if current_user.admin? %>
1618
<%= render partial: 'collections/show_actions' %>
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
<%= f.input :description, as: :single_text_with_help, input_html: { rows: '14', type: 'textarea', value: f.object.description.first}, required: false %>
1+
<%# GenericFile and Collection both use this file because hydra-editor %>
2+
<%# GenericFile description is expecting multivalued but we only display one for editing %>
3+
<% if f.object.class.multiple? key %>
4+
<%= f.input :description, as: :single_text_with_help, input_html: { rows: '14', type: 'textarea', name: 'generic_file[description][]', value: f.object.description.first } %>
5+
<% else %>
6+
<%= f.input :description, as: :single_text_with_help, input_html: { rows: '14', type: 'textarea' } %>
7+
<% end %>
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
<%= f.input key, as: :single_field, input_html: { class: 'form-control', value: f.object.title}, required: f.object.required?(key) %>
1+
<%# GenericFile and Collection both use this file because hydra-editor %>
2+
<%# GenericFile title is expecting multivalued but we only display one for editing %>
3+
<% if f.object.class.multiple? key %>
4+
<%= f.input key, as: :single_field, input_html: { class: 'form-control', name: 'generic_file[title][]', value: f.object.title }, required: f.object.required?(key) %>
5+
<% else %>
6+
<%= f.input key, as: :single_field, input_html: { class: 'form-control', value: f.object.title}, required: f.object.required?(key) %>
7+
<% end %>
8+

app/views/users/_vitals.html.erb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<i class="glyphicon glyphicon-time"></i> Joined on <%= @user.created_at.to_date.strftime("%b %d, %Y") %> <br />
2+
<i class="glyphicon glyphicon-folder-open"></i> Deposited Files
3+
<%= link_to number_of_deposits(@user), add_facet_params(Solrizer.solr_name("depositor", :symbol), @user.to_s).merge!(controller: "catalog", action: "index") %> <br />

config/routes.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@
7171
get 'batches/:id/update_collections' => 'batch#update_collections', as: 'update_collections'
7272
get 'files/:id/update_collections' => 'generic_files#update_collections'
7373
get 'communities', controller: 'communities', action: :index
74+
get 'communities/logo', controller: 'communities', action: :logo
7475
get 'collections/:id/:sort', controller: 'collections', action: :show
7576
get 'collections/:id/:per_page', controller: 'collections', action: :show
7677
get 'collections/:id/edit', controller: 'collections', action: :edit
7778
get 'recent', controller: 'recent', action: :index
7879

79-
8080
# This must be the very last route in the file because it has a catch-all route for 404 errors.
8181
# This behavior seems to show up only in production mode.
8282
mount Sufia::Engine => '/'

spec/controllers/collections_controller_spec.rb

+7
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,13 @@
153153
@child_collection.member_ids = [@file2.id]
154154
@child_collection.save
155155

156+
@logo_file = fixture_file_upload('logo.jpg', 'image/jpg')
157+
158+
end
159+
160+
it "should add logo" do
161+
put :update, id: community, collection: {logo: @logo_file}
162+
expect(response).to redirect_to routes.url_helpers.collection_path(community)
156163
end
157164

158165
it "should set belongsToCommunity on member file" do

0 commit comments

Comments
 (0)