-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #834 from sul-dlss/profile-view
Adds base functionality for Profiling
- Loading branch information
Showing
16 changed files
with
236 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.table-fixed-layout { | ||
table-layout: fixed; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
## | ||
# Used for the profile view but just inherits from CatalogController | ||
class ProfileController < CatalogController | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module ProfileHelper | ||
include Blacklight::CatalogHelperBehavior | ||
## | ||
# Kind of a hacky override, but better than overriding additional partials | ||
# Don't show pagination for ProfileController requests | ||
def show_pagination?(*) | ||
return false if params['controller'] == 'profile' | ||
super | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Argo | ||
## | ||
# Part of the Blacklight SearchBuilder, but only used for ProfileController to | ||
# add additional parameters to the Solr request. | ||
module ProfileQueries | ||
extend ActiveSupport::Concern | ||
|
||
def add_profile_queries(solr_parameters) | ||
return solr_parameters unless blacklight_params['controller'] == 'profile' | ||
solr_parameters['facet.field'] ||= [] | ||
solr_parameters['facet.field'] << SolrDocument::FIELD_APO_TITLE.to_s | ||
solr_parameters['facet.field'] << SolrDocument::SolrDocument::FIELD_COLLECTION_TITLE.to_s | ||
solr_parameters['stats'] = true | ||
solr_parameters['stats.field'] ||= [] | ||
# Use this paradigm to compute needed statistics | ||
# solr_parameters['stats.field'] << 'published_dttsim' | ||
solr_parameters | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
## | ||
# Used in the Profile view to provide convenience to the | ||
# Blacklight::Solr::Response for easy view magic | ||
class ProfilePresenter | ||
delegate :aggregations, to: :response | ||
|
||
attr_reader :response | ||
|
||
## | ||
# @param [Blacklight::Solr::Response] response | ||
def initialize(response) | ||
@response = response | ||
end | ||
|
||
def apo_titles | ||
aggregations[SolrDocument::FIELD_APO_TITLE.to_s].items | ||
end | ||
|
||
def collection_titles | ||
aggregations[SolrDocument::FIELD_COLLECTION_TITLE.to_s].items | ||
end | ||
|
||
def rights_descriptions | ||
aggregations['rights_descriptions_ssim'].items | ||
end | ||
|
||
def content_type | ||
aggregations['content_type_ssim'].items | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<% @presenter = ProfilePresenter.new(@response) %> | ||
|
||
<h3>Profile</h3> | ||
|
||
<div id="admin-policies"> | ||
<h4>Admin Policies</h4> | ||
<table class='table table-fixed-layout'> | ||
<%= render partial: 'table_row', collection: @presenter.apo_titles, as: :item %> | ||
</table> | ||
</div> | ||
|
||
<div id="collection"> | ||
<h4>Collection</h4> | ||
<table class='table table-fixed-layout'> | ||
<%= render partial: 'table_row', collection: @presenter.collection_titles, as: :item %> | ||
</table> | ||
</div> | ||
|
||
<div id='rights'> | ||
<h4>Rights</h4> | ||
<table class='table table-fixed-layout'> | ||
<%= render partial: 'table_row', collection: @presenter.rights_descriptions, as: :item %> | ||
</table> | ||
</div> | ||
|
||
<div id='contents'> | ||
<h4>Contents</h4> | ||
<table class='table table-fixed-layout'> | ||
<%= render partial: 'table_row', collection: @presenter.content_type, as: :item %> | ||
</table> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<%= render 'constraints' %> | ||
<%= render 'catalog/report_view_toggle' %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<tr> | ||
<td> | ||
<%= item.value %> | ||
</td> | ||
<td> | ||
<%= item.hits %> | ||
</td> | ||
</tr> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'spec_helper' | ||
|
||
describe ProfileController do | ||
it 'is a subclass of CatalogController' do | ||
expect(described_class.superclass).to eq CatalogController | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
require 'spec_helper' | ||
|
||
describe 'Profile' do | ||
let(:current_user) do | ||
mock_user(is_admin?: true) | ||
end | ||
before do | ||
expect_any_instance_of(ProfileController).to receive(:current_user) | ||
.at_least(1).times.and_return(current_user) | ||
end | ||
describe 'Admin Policies' do | ||
it 'lists admin policies and counts' do | ||
visit profile_index_path f: { objectType_ssim: ['item'] } | ||
within '#admin-policies' do | ||
expect(page).to have_css 'h4', text: 'Admin Policies' | ||
expect(page).to have_css 'td:nth-child(1)', text: 'Stanford University Libraries - Special Collections' | ||
expect(page).to have_css 'td:nth-child(2)', text: '4' | ||
end | ||
end | ||
end | ||
describe 'Collection' do | ||
it 'lists collections and counts' do | ||
visit profile_index_path f: { objectType_ssim: ['item'] } | ||
within '#collection' do | ||
expect(page).to have_css 'h4', text: 'Collection' | ||
expect(page).to have_css 'td:nth-child(1)', text: 'druid:pb873ty1662' | ||
expect(page).to have_css 'td:nth-child(2)', text: '1' | ||
end | ||
end | ||
end | ||
describe 'Rights' do | ||
it 'lists rights and counts' do | ||
visit profile_index_path f: { objectType_ssim: ['item'] } | ||
within '#rights' do | ||
expect(page).to have_css 'h4', text: 'Rights' | ||
expect(page).to have_css 'td:nth-child(1)', text: 'dark' | ||
expect(page).to have_css 'td:nth-child(2)', text: '2' | ||
end | ||
end | ||
end | ||
describe 'Contents' do | ||
it 'lists content type and counts' do | ||
visit profile_index_path f: { objectType_ssim: ['item'] } | ||
within '#contents' do | ||
expect(page).to have_css 'h4', text: 'Contents' | ||
expect(page).to have_css 'td:nth-child(1)', text: 'image' | ||
expect(page).to have_css 'td:nth-child(2)', text: '3' | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require 'spec_helper' | ||
|
||
describe ProfileHelper, type: :helper do | ||
describe '#show_pagination?' do | ||
context 'when using ProfileController' do | ||
it 'returns false' do | ||
allow(helper).to receive_messages(params: { 'controller' => 'profile'}) | ||
expect(helper.show_pagination?).to eq false | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require 'spec_helper' | ||
|
||
class TestClass | ||
include Argo::ProfileQueries | ||
end | ||
|
||
describe Argo::ProfileQueries do | ||
subject { TestClass.new } | ||
# let(:blacklight_params) { { controller: 'profile' } } | ||
before do | ||
allow(subject).to receive(:blacklight_params).and_return(blacklight_params) | ||
end | ||
context 'in ProfileController' do | ||
let(:blacklight_params) { { 'controller' => 'profile' } } | ||
it 'adds in required facet fields' do | ||
catalog_config = CatalogController.blacklight_config.deep_copy | ||
solr_parameters = subject.add_profile_queries(catalog_config) | ||
facet_fields = solr_parameters.facet_fields.map{ |f| f[0] } + solr_parameters['facet.field'] | ||
required_fields = [SolrDocument::FIELD_APO_TITLE.to_s, SolrDocument::SolrDocument::FIELD_COLLECTION_TITLE.to_s, 'rights_descriptions_ssim', 'content_type_ssim'] | ||
expect(facet_fields).to include(*required_fields) | ||
end | ||
it 'adds in requred stats fields' do | ||
catalog_config = CatalogController.blacklight_config.deep_copy | ||
solr_parameters = subject.add_profile_queries(catalog_config) | ||
expect(solr_parameters['stats']).to be true | ||
end | ||
end | ||
context 'in another Controller' do | ||
let(:blacklight_params) { { 'controller' => 'catalog' } } | ||
it 'does not modify solr_params' do | ||
expect(subject.add_profile_queries(CatalogController.blacklight_config.deep_copy)).to eq CatalogController.blacklight_config.deep_copy | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters