Skip to content

Commit

Permalink
Admin set show page for admins
Browse files Browse the repository at this point in the history
Fixes #2502
  • Loading branch information
jcoyne committed Sep 7, 2016
1 parent abec765 commit 9484487
Show file tree
Hide file tree
Showing 13 changed files with 184 additions and 6 deletions.
15 changes: 15 additions & 0 deletions app/assets/stylesheets/sufia/admin.scss
Expand Up @@ -31,18 +31,33 @@ $content-background-color: #f5f5f5 !default;
margin: 0;
margin-bottom: 15px;
padding: 0;

> .fa {
margin-left: 6px;
margin-right: 6px;
}
}
}

.panel {
float: left;
width: 100%;

.panel-heading,
.panel-footer,
.panel-body {
float: left;
width: 100%;
}

.panel-title {
color: $title-text-color;
display: block;
float: left;
font-size: 16px;
font-weight: 400;
line-height: 30px;
}
}

.title-button {
Expand Down
43 changes: 39 additions & 4 deletions app/controllers/sufia/admin/admin_sets_controller.rb
@@ -1,7 +1,42 @@
module Sufia
class Admin::AdminSetsController < ApplicationController
include CurationConcerns::CollectionsControllerBehavior
load_and_authorize_resource
layout 'admin'
self.presenter_class = Sufia::AdminSetPresenter

def show
add_breadcrumb t(:'sufia.controls.home'), root_path
add_breadcrumb t(:'sufia.toolbar.admin.menu'), sufia.admin_path
add_breadcrumb t(:'sufia.admin.sidebar.admin_sets'), sufia.admin_admin_sets_path
add_breadcrumb 'View Set', request.path
super
end

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

# Overriding the way that the search builder is initialized
def collections_search_builder
collections_search_builder_class.new(self, :read)
end

# Used for the show action
def collection_search_builder_class
Sufia::SingleAdminSetSearchBuilder
end

# Used for the index action
def collections_search_builder_class
CurationConcerns::AdminSetSearchBuilder
end

# Used to get the members for the show action
def collection_member_search_builder_class
Sufia::AdminSetMemberSearchBuilder
end

def index
authorize! :manage, AdminSet
Expand Down Expand Up @@ -36,10 +71,10 @@ def create_admin_set
end

def setup_create_form
add_breadcrumb 'Home', root_path
add_breadcrumb 'Repository Dashboard', sufia.admin_path
add_breadcrumb 'Administrative Sets', sufia.admin_admin_sets_path
add_breadcrumb 'New', sufia.new_admin_admin_set_path
add_breadcrumb t(:'sufia.controls.home'), root_path
add_breadcrumb t(:'sufia.toolbar.admin.menu'), sufia.admin_path
add_breadcrumb t(:'sufia.admin.sidebar.admin_sets'), sufia.admin_admin_sets_path
add_breadcrumb t(:'helpers.action.admin_set.new'), sufia.new_admin_admin_set_path
@form = form_class.new(@admin_set)
end

Expand Down
4 changes: 4 additions & 0 deletions app/presenters/sufia/admin_set_presenter.rb
@@ -0,0 +1,4 @@
module Sufia
class AdminSetPresenter < CollectionPresenter
end
end
12 changes: 12 additions & 0 deletions app/search_builders/sufia/admin_set_member_search_builder.rb
@@ -0,0 +1,12 @@
module Sufia
# Builds a query to find the members of an admin set.
class AdminSetMemberSearchBuilder < ::SearchBuilder
self.default_processor_chain += [:in_admin_set]

# include filters into the query to only include the collection memebers
def in_admin_set(solr_parameters)
solr_parameters[:fq] ||= []
solr_parameters[:fq] << "{!term f=isPartOf_ssim}#{blacklight_params.fetch('id')}"
end
end
end
9 changes: 9 additions & 0 deletions app/search_builders/sufia/single_admin_set_search_builder.rb
@@ -0,0 +1,9 @@
module Sufia
class SingleAdminSetSearchBuilder < CurationConcerns::AdminSetSearchBuilder
include CurationConcerns::SingleResult

def initialize(context)
super(context, :read)
end
end
end
5 changes: 5 additions & 0 deletions app/views/sufia/admin/admin_sets/_sort_and_per_page.html.erb
@@ -0,0 +1,5 @@
<% if show_pagination? %>
<div id="sortAndPerPage" class="clearfix">
<%= render partial: "paginate_compact", object: @response %>
</div>
<% end %>
2 changes: 1 addition & 1 deletion app/views/sufia/admin/admin_sets/index.html.erb
Expand Up @@ -2,7 +2,7 @@
<h1><span class="fa fa-sitemap"></span> Administrative Sets</h1>
<div class="pull-right">
<%= link_to sufia.new_admin_admin_set_path, class: 'btn btn-primary' do %>
<span class="fa fa-edit"></span> Create new administrative set
<span class="fa fa-edit"></span> <%= t(:'helpers.action.admin_set.new') %>
<% end %>
</div>
<% end %>
Expand Down
38 changes: 38 additions & 0 deletions app/views/sufia/admin/admin_sets/show.html.erb
@@ -0,0 +1,38 @@
<% content_for :page_header do %>
<h1><span class="fa fa-sitemap"></span> <%= t('.header') %></h1>
<% end %>


<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title display-page"><%= @presenter.to_s %></h2>
<div class="pull-right">
<%= link_to sufia.edit_admin_admin_set_path(@presenter), class: 'btn btn-primary' do %>
<span class="fa fa-edit"></span> Edit
<% end %>
</div>
</div>

<div class="panel-body admin-set row">
<div class="col-md-2">
<span class="fa fa-sitemap collection-icon-search"></span>
</div>
<div class="col-md-10">
<%= render 'collection_description', presenter: @presenter %>
<%= render 'show_descriptions' %>
</div>
</div>

<div class="panel-body">
<h3><%= t '.item_list_header' %></h3>
<%= render 'sort_and_per_page', collection: @presenter %>
<%= render_document_index @member_docs %>
<%= render 'paginate' %>
</div>
</div>
</div>
</div>
6 changes: 6 additions & 0 deletions config/locales/sufia.en.yml
Expand Up @@ -285,6 +285,10 @@ en:
footer:
copyright_html: "<strong>Copyright &copy; 2016 Project Hydra</strong> Licensed under the Apache License, Version 2.0"
admin:
admin_sets:
show:
header: "Administrative Set"
item_list_header: "Works in This Set"
sidebar:
admin_sets: "Administrative Sets"
settings: "Settings"
Expand Down Expand Up @@ -415,6 +419,8 @@ en:

helpers:
action:
admin_set:
new: "Create new administrative set"
cancel: "Cancel"
submit:
admin_set:
Expand Down
16 changes: 16 additions & 0 deletions spec/controllers/sufia/admin/admin_sets_controller_spec.rb
Expand Up @@ -68,5 +68,21 @@
end
end
end

describe "#show" do
context "when it's successful" do
let(:admin_set) { create(:admin_set, edit_users: [user]) }
before do
create(:work, :public, admin_set: admin_set)
end

it 'defines a presenter' do
get :show, params: { id: admin_set }
expect(response).to be_success
expect(assigns[:presenter]).to be_kind_of Sufia::AdminSetPresenter
expect(assigns[:presenter].id).to eq admin_set.id
end
end
end
end
end
4 changes: 3 additions & 1 deletion spec/factories/generic_works.rb
Expand Up @@ -11,7 +11,9 @@
work.apply_depositor_metadata(evaluator.user.user_key)
end

factory :public_generic_work, aliases: [:public_work] do
factory :public_generic_work, aliases: [:public_work], traits: [:public]

trait :public do
visibility Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC
end

Expand Down
24 changes: 24 additions & 0 deletions spec/features/admin_admin_set_spec.rb
@@ -0,0 +1,24 @@
require 'spec_helper'

RSpec.describe "The admin sets, through the admin dashboard" do
let(:user) { create :user }

before do
create(:admin_set, title: ["A completely unique name"],
description: ["A substantial description"])
allow(RoleMapper).to receive(:byname).and_return(user.user_key => ['admin'])
end

scenario do
login_as(user, scope: :user)
visit '/admin'
click_link "Administrative Sets"

expect(page).to have_link "Create new administrative set"

click_link "A completely unique name"

expect(page).to have_content "A substantial description"
expect(page).to have_content "Works in This Set"
end
end
12 changes: 12 additions & 0 deletions spec/search_builder/sufia/single_admin_set_search_builder_spec.rb
@@ -0,0 +1,12 @@
require 'spec_helper'

RSpec.describe Sufia::SingleAdminSetSearchBuilder do
let(:ability) { instance_double(Ability, admin?: true) }
let(:context) { double(blacklight_config: CatalogController.blacklight_config,
current_ability: ability) }
let(:builder) { described_class.new(context) }
describe "#query" do
subject { builder.with(id: '123').query.fetch('fq') }
it { is_expected.to match_array ["", "_query_:\"{!field f=has_model_ssim}AdminSet\"", "_query_:\"{!field f=id}123\""] }
end
end

0 comments on commit 9484487

Please sign in to comment.