Skip to content

Commit

Permalink
Display an admin set from the user perspective
Browse files Browse the repository at this point in the history
Fixes #2650
  • Loading branch information
jcoyne committed Sep 12, 2016
1 parent 49cf16d commit 69fb40d
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 24 deletions.
2 changes: 1 addition & 1 deletion app/assets/stylesheets/sufia/_work-show.scss
Expand Up @@ -8,7 +8,7 @@
padding: $panel-body-padding;
}

header > h1 > .label {
header > h1 .label {
font-size: $font-size-base;
vertical-align: middle;
}
Expand Down
22 changes: 15 additions & 7 deletions app/controllers/sufia/admin_sets_controller.rb
@@ -1,18 +1,26 @@
module Sufia
class AdminSetsController < ApplicationController
include CurationConcerns::CollectionsControllerBehavior
include Sufia::CollectionsControllerBehavior
layout "sufia-one-column"

self.presenter_class = Sufia::AdminSetPresenter

self.list_search_builder_class = CurationConcerns::AdminSetSearchBuilder
# Used for the show action
self.single_item_search_builder_class = Sufia::SingleAdminSetSearchBuilder
# Used to get the members for the show action
self.member_search_builder_class = Sufia::AdminSetMemberSearchBuilder

# Override the default prefixes so that we use the collection partals.
def _prefixes
@_prefixes ||= ["sufia/admin_sets", "collections", 'catalog']
def self.local_prefixes
["sufia/admin_sets", "collections", 'catalog']
end

# Overriding the way that the search builder is initialized
def list_search_builder
list_search_builder_class.new(self, :read)
end
private

# Overriding the way that the search builder is initialized
def list_search_builder
list_search_builder_class.new(self, :read)
end
end
end
44 changes: 30 additions & 14 deletions app/views/sufia/admin_sets/_document_list.html.erb
@@ -1,14 +1,30 @@
<% # container for all documents in index list view -%>
<table class="documents-<%= document_index_view_type %> table table-striped">
<thead>
<tr>
<th colspan="2">Title</th>
<th>Date created</th>
<th>Language</th>
<th>Works</th>
</tr>
</thead>
<tbody>
<%= render documents, as: :document %>
</tbody>
</table>
<% # container for all documents in index list view and the members in the show view -%>
<% if action_name == 'index' %>
<table class="documents-<%= document_index_view_type %> table table-striped">
<thead>
<tr>
<th colspan="2">Title</th>
<th>Date created</th>
<th>Language</th>
<th>Works</th>
</tr>
</thead>
<tbody>
<%= render documents, as: :document %>
</tbody>
</table>
<% else %>
<% # This is for the member list # %>
<table class="documents-<%= document_index_view_type %> table table-striped">
<thead>
<tr>
<th>Title</th>
<th>Date created</th>
<th>Creator</th>
</tr>
</thead>
<tbody>
<%= render partial: 'member_document', collection: documents %>
</tbody>
</table>
<% end %>
16 changes: 16 additions & 0 deletions app/views/sufia/admin_sets/_member_document.html.erb
@@ -0,0 +1,16 @@
<tr>
<td class="row">
<div class="col-sm-2">
<%= render_thumbnail_tag member_document %>
</div>
<div class="col-sm-10">
<%= link_to member_document.to_s, member_document %>
</div>
</td>
<td>
<%= member_document.create_date %>
</td>
<td>
<%= member_document.creator.join(', ') %>
</td>
</tr>
12 changes: 12 additions & 0 deletions app/views/sufia/admin_sets/_search_form.html.erb
@@ -0,0 +1,12 @@
<%= form_for [sufia, presenter], method: :get, class: "well form-search" do |f| %>
<label class="sr-only"><%= t('curation_concerns.collections.search_form.label', title: presenter.to_s) %></label>
<div class="input-group">
<%= text_field_tag :cq, params[:cq], class: "collection-query form-control", placeholder: t('curation_concerns.collections.search_form.placeholder'), size: '30', type: "search", id: "collection_search" %>
<div class="input-group-btn">
<button type="submit" class="btn btn-primary" id="collection_submit"><i class="glyphicon glyphicon-search"></i> Go</button>
</div>
</div>
<%= hidden_field_tag :sort, params[:sort], id: 'collection_sort' %>
<%= render_hash_as_hidden_fields(search_state.params_for_search.except(:cq, :sort, :qt, :page)) %>
<% end %>

27 changes: 27 additions & 0 deletions app/views/sufia/admin_sets/show.html.erb
@@ -0,0 +1,27 @@
<% provide :page_title, construct_page_title(@presenter.title) %>

<div itemscope itemtype="http://schema.org/CollectionPage" class="row">
<div class="col-sm-10 pull-right">
<header>
<h1><%= @presenter %>
<%= link_to sufia.admin_sets_path do %>
<span class="label label-info">Administrative Collection</span>
<% end %>
</h1>
</header>
<%= render 'collection_description', presenter: @presenter %>
<%= render 'collections/show_descriptions' %>
</div>
<div class="col-sm-2">
<span class="fa fa-sitemap collection-icon-search"></span>
</div>
</div>

<h2>Works in this Collection</h2>

<%= render 'sort_and_per_page', collection: @presenter %>
<%= render_document_index @member_docs %>
<%= render 'paginate' %>

14 changes: 12 additions & 2 deletions spec/controllers/sufia/admin_sets_controller_spec.rb
Expand Up @@ -2,10 +2,8 @@

RSpec.describe Sufia::AdminSetsController do
describe "#index" do
let(:user) { create(:user) }
let!(:admin_set) { create(:admin_set, :public) }
before do
sign_in user
create(:collection, :public) # This should not be returned
end

Expand All @@ -15,4 +13,16 @@
expect(assigns[:document_list].map(&:id)).to match_array [admin_set.id]
end
end

describe "#show" do
let(:admin_set) { create(:admin_set, :public) }
let!(:work) { create(:work, :public, admin_set: admin_set) }

it "returns a presenter and members" do
get :show, params: { id: admin_set }
expect(response).to be_success
expect(assigns[:presenter].id).to eq admin_set.id
expect(assigns[:member_docs].map(&:id)).to eq [work.id]
end
end
end
21 changes: 21 additions & 0 deletions spec/features/user_admin_set_spec.rb
@@ -0,0 +1,21 @@
require 'spec_helper'

RSpec.describe "The public view of admin sets" do
let(:admin_set) do
create(:admin_set, :public, title: ["A completely unique name"],
description: ["A substantial description"])
end

before do
create(:work, :public, admin_set: admin_set, title: ["My member work"])
end

scenario do
visit root_path
click_link "View all administrative collections"
click_link "A completely unique name"
expect(page).to have_content "A substantial description"
expect(page).to have_content "Works in this Collection"
expect(page).to have_link "My member work"
end
end

0 comments on commit 69fb40d

Please sign in to comment.