Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create collection page #5006

Merged
merged 2 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions app/controllers/admin/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,25 @@ def create
subject: "New collection: #{@collection.name}"
).deliver_later
end
render json: {id: @collection.id}, status: 200
respond_to do |format|
format.html do
redirect_to @collection, notice: 'Collection was successfully created.'
end
format.json do
render json: {id: @collection.id}, status: 200
end
end
else
logger.warn "Failed to create collection #{@collection.name rescue '<unknown>'}: #{@collection.errors.full_messages}"
render json: {errors: ['Failed to create collection:']+@collection.errors.full_messages}, status: 422
respond_to do |format|
format.html do
flash.now[:error] = @collection.errors.full_messages.to_sentence
render action: 'new'
end
format.json do
render json: { errors: ['Failed to create collection:']+@collection.errors.full_messages}, status: 422
end
end
end
end

Expand Down
114 changes: 59 additions & 55 deletions app/views/admin/collections/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,72 +13,76 @@ Unless required by applicable law or agreed to in writing, software distributed
specific language governing permissions and limitations under the License.
--- END LICENSE_HEADER BLOCK ---
%>

<% unless Avalon::ControlledVocabulary.vocabulary[:units] %>
<% raise Avalon::VocabularyNotFound.new "Units vocabulary not found." %>
<% end %>
cjcolvar marked this conversation as resolved.
Show resolved Hide resolved

<% @page_title = t('collections.title', :application_name => application_name) %>

<% unless @collections.empty? %>
<div class="row display-flex page-title-wrapper">
<div class="col-xs-6">
<h1 class="page-title">My Collections</h1>
</div>
<div class="col-xs-6 collection-btn">
<%= button_tag("Create Collection", class: 'btn btn-primary btn-large', data: {toggle:"modal", target:"#new_collection"}) unless cannot? :create, Admin::Collection %>
<div class="row display-flex page-title-wrapper">
<div class="col-xs-6">
<h1 class="page-title">My Collections</h1>
</div>
<div class="col-xs-6 collection-btn">
<%= link_to('<span class="btn btn-primary btn-large">Create Collection</span>'.html_safe, new_admin_collection_path) unless cannot? :create, Admin::Collection %>
</div>
</div>
</div>

<table class='table table-striped table-responsive' id='admin-collections-table'>
<thead>
<tr>
<th>Title</th>
<th>Items</th>
<th>Managers</th>
<th>Description</th>
<th></th>
</tr>
</thead>
<tbody>
<% @collections.to_a.each do |collection| %>
<tr>
<td> <strong><%= link_to collection.name, admin_collection_path(collection.id) %></strong> </td>
<td>
<%= link_to(pluralize(collection.media_object_count, 'item'), search_catalog_path('f[collection_ssim][]' => collection.name)) %>
<% if collection.unpublished_media_object_count > 0 %>
<%=link_to("(#{collection.unpublished_media_object_count} unpublished)", search_catalog_path('f[collection_ssim][]' => collection.name, 'f[workflow_published_sim][]' => "Unpublished")) %>
<% end %>
</td>
<td> <%= pluralize(collection.manager_count, 'manager') %> </td>
<td> <%= collection.description&.truncate(100, separator: ' ') %> </td>
<td class="text-right">
<% if can?(:destroy, collection) %>
<div class="btn-group">
<%= link_to('Delete', remove_admin_collection_path(collection.id), class: 'btn btn-danger btn-sm')%>
</div>
<% else %>
&nbsp;
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
<table class='table table-striped table-responsive' id='admin-collections-table'>
<thead>
<tr>
<th>Title</th>
<th>Items</th>
<th>Managers</th>
<th>Description</th>
<th></th>
</tr>
</thead>
<tbody>
<% @collections.to_a.each do |collection| %>
<tr>
<td> <strong><%= link_to collection.name, admin_collection_path(collection.id) %></strong> </td>
<td>
<%= link_to(pluralize(collection.media_object_count, 'item'), search_catalog_path('f[collection_ssim][]' => collection.name)) %>
<% if collection.unpublished_media_object_count > 0 %>
<%=link_to("(#{collection.unpublished_media_object_count} unpublished)", search_catalog_path('f[collection_ssim][]' => collection.name, 'f[workflow_published_sim][]' => "Unpublished")) %>
<% end %>
</td>
<td> <%= pluralize(collection.manager_count, 'manager') %> </td>
<td> <%= collection.description&.truncate(100, separator: ' ') %> </td>
<td class="text-right">
<% if can?(:destroy, collection) %>
<div class="btn-group">
<%= link_to('Delete', remove_admin_collection_path(collection.id), class: 'btn btn-danger btn-sm')%>
</div>
<% else %>
&nbsp;
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>

<% else %>
<div class="hero-unit">
<h2>You don't have any collections yet</h2>
<div class="hero-unit">
<h2>You don't have any collections yet</h2>

<% if can? :create, Admin::Collection %>
<p>Would you like to create one?</p>
<div class="whitespace"></div>
<p>
<%= button_tag("Create Collection", class: 'btn btn-primary btn-large', data: {toggle:"modal", target:"#new_collection"}) %>
</p>
<% else %>
<p>You'll need to be assigned to one</p>
<% end %>
<% if can? :create, Admin::Collection %>
<p>Would you like to create one?</p>
<div class="whitespace"></div>
<p>
<%= link_to('<span class="btn btn-primary btn-large">Create Collection</span>'.html_safe, new_admin_collection_path) %>
</p>
<% else %>
<p>You'll need to be assigned to one</p>
<% end %>

</div>
</div>
<% end %>



<% @collection = Admin::Collection.new %>
<%= render "form", modal_title: "Create Collection" %>
16 changes: 15 additions & 1 deletion app/views/admin/collections/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,18 @@ Unless required by applicable law or agreed to in writing, software distributed
specific language governing permissions and limitations under the License.
--- END LICENSE_HEADER BLOCK ---
%>
<%= render :partial => 'form', locals: { modal_title: 'Create Collection' } %>
<div class="page-title-wrapper">
<h1 class="page-title">New collection</h1>
</div>
<%= bootstrap_form_for @collection, action: 'create' do |f| %>
<%= f.text_field :name %>
<% if @collection.new_record? || can?(:update_unit, @collection)%>
<%= f.select(:unit, Admin::Collection.units, {}, {:class => 'form-control'}) %>
<% end %>
<%= f.text_area :description, rows: 3 %>
<%= f.text_field :contact_email %>
<%= f.text_field :website_url %>
<%= f.text_field :website_label %>
<a href="/admin/collections" aria-hidden="true" class="btn btn-outline">Cancel</a>
<%= f.submit class: 'btn btn-primary' %>
<% end %>
80 changes: 80 additions & 0 deletions spec/features/capybara_admin_collection_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Copyright 2011-2022, The Trustees of Indiana University and Northwestern
# University. Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
#
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
# --- END LICENSE_HEADER BLOCK ---

require 'rails_helper'

describe 'Admin Collection' do
after { Warden.test_reset! }
it 'checks navigation when create new collection is accessed' do
user = FactoryBot.create(:administrator)
login_as user, scope: :user
visit '/'
click_link('Manage Content')
expect(page).to have_current_path('/admin/collections')
expect(page).to have_link('Create Collection')
click_link('Create Collection')
expect(page).to have_current_path('/admin/collections/new')
expect(page).to have_content('Name')
expect(page).to have_content('Description')
expect(page).to have_content('Unit')
expect(page).to have_content('Default Unit')
expect(page).to have_link('Cancel')
end
it 'is able to create a new collection' do
user = FactoryBot.create(:administrator)
login_as user, scope: :user
visit '/admin/collections/'
click_link('Create Collection')
fill_in('admin_collection_name', with: 'Test Collection')
select('Default Unit', from: 'admin_collection_unit')
click_on('Create Collection')
visit '/admin/collections'
expect(page).to have_content('Test Collection')
expect(page).to have_content('Title')
expect(page).to have_content('Items')
expect(page).to have_content('Managers')
expect(page).to have_content('Description')
expect(page).to have_link('Delete')
end
it 'is able to view collection by clicking on collection name' do
user = FactoryBot.create(:administrator)
login_as user, scope: :user
visit '/admin/collections'
click_link('Create Collection')
fill_in('admin_collection_name', with: 'Test Collection')
select('Default Unit', from: 'admin_collection_unit')
click_on('Create Collection')
visit '/admin/collections'
click_on('Test Collection')
expect(page).to have_content('Test Collection')
expect(page).to have_link('Create An Item')
expect(page).to have_link('List All Items')
expect(page).to have_button('Edit Collection Info')
expect(page).to have_content('Default Unit')
end
it 'is able to delete a collection' do
user = FactoryBot.create(:administrator)
login_as user, scope: :user
visit '/admin/collections'
click_link('Create Collection')
fill_in('admin_collection_name', with: 'Test Collection')
select('Default Unit', from: 'admin_collection_unit')
click_on('Create Collection')
visit '/admin/collections'
click_link('Delete')
expect(page).to have_content('Are you certain you want to remove the collection Test Collection?')
expect(page).to have_button('Yes, I am sure')
expect(page).to have_link('No, go back')
end
end
7 changes: 1 addition & 6 deletions spec/features/capybara_navigation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@
expect(page).to have_current_path('/admin/collections')
expect(page).to have_content('Skip to main content')
expect(page).to have_link('Selected Items (0)')
expect(page).to have_button('Create Collection')
expect(page).to have_content('Name')
expect(page).to have_content('Description')
expect(page).to have_content('Unit')
expect(page).to have_content('Default Unit')
expect(page).to have_link('Cancel')
expect(page).to have_link('Create Collection')
end
it 'checks naviagtion to Manage Groups' do
user = FactoryBot.create(:administrator)
Expand Down