Skip to content

Commit

Permalink
Add access point and masthead for bookplates.
Browse files Browse the repository at this point in the history
  • Loading branch information
jkeck committed Oct 29, 2015
1 parent 2a784a6 commit d57c6cf
Show file tree
Hide file tree
Showing 8 changed files with 231 additions and 43 deletions.
7 changes: 7 additions & 0 deletions app/assets/stylesheets/modules/bookplates.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,10 @@ $bookplate-top-margin: 10px;
max-width: 150px;
}
}

.bookplate-fund-masthead {
img {
max-width: 200px;
width: 100%;
}
}
2 changes: 1 addition & 1 deletion app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class CatalogController < ApplicationController
config.add_facet_field "access_facet", :label => "Access", limit: 10
config.add_facet_field "collection", label: "Collection", show: false, helper_method: :collection_breadcrumb_value
config.add_facet_field "collection_type", :label => "Collection type", :show => false
config.add_facet_field 'fund_facet', label: 'Bookplate', show: false
config.add_facet_field 'fund_facet', label: 'Bookplate', show: false, helper_method: :bookplate_breadcrumb_value
config.add_facet_field "format_main_ssim", :label => "Resource type", partial: "resource_type_facet", limit: 100, sort: :index
config.add_facet_field "format_physical_ssim", :label => "Media type", limit: 20
config.add_facet_field "pub_year_tisim", :label => "Date", :range => {
Expand Down
33 changes: 25 additions & 8 deletions app/helpers/masthead_helper.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
###
# Helper module for contents rendered in mastheads
###
module MastheadHelper
def render_masthead_partial
if page_location.access_point?
begin
render "catalog/mastheads/#{page_location.access_point}"
rescue ActionView::MissingTemplate
end
return '' unless page_location.access_point?
begin
render "catalog/mastheads/#{page_location.access_point}"
rescue ActionView::MissingTemplate
return ''
end
end

def facets_prefix_options
["0-9", ("A".."Z").to_a].flatten
['0-9', ('A'..'Z').to_a].flatten
end
def digital_collections_params_for(format=nil)
facet_params = {f: {building_facet: ["Stanford Digital Repository"]}}

def digital_collections_params_for(format = nil)
facet_params = { f: { building_facet: ['Stanford Digital Repository'] } }
facet_params[:f][:format_main_ssim] = [format] if format
catalog_index_path(facet_params)
end

def bookplate_from_document_list(response = @response)
return unless params[:f] && params[:f][:fund_facet].present? && response.docs.present?
SolrDocument.new(response.docs.first).bookplates.find do |bookplate|
bookplate.linking_value == params[:f][:fund_facet].first
end
end

def bookplate_breadcrumb_value(druid, response = @response)
return druid unless response.docs.present?
bookplate_from_document_list.try(:text) || druid
end
end
24 changes: 24 additions & 0 deletions app/views/catalog/mastheads/_bookplate_fund.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<% bookplate = bookplate_from_document_list %>
<% if bookplate.present? %>
<div id="masthead-container">
<div id="masthead" class="bookplate-fund-masthead row">
<div class='col-md-2 col-sm-3'>
<%= image_tag(bookplate.thumbnail_url, alt: bookplate.text) %>
</div>
<div class='col-md-10 col-sm-9'>
<h1><%= bookplate.text %></h1>
<p>
Bookplates honor donors who have created and sustained acquisition
funds, often over many years and sometimes several generations, as
well as those who have given the Libraries extraordinary collections.
</p>
<% if Settings.BOOKPLATES_EXHIBIT_URL.present? %>
<p>
Find out more at the <%= link_to('Digital Bookplates Exhibit', Settings.BOOKPLATES_EXHIBIT_URL) %>
<i class='external-link-icon'></i>
</p>
<% end %>
</div>
</div>
</div>
<% end %>
68 changes: 36 additions & 32 deletions lib/page_location.rb
Original file line number Diff line number Diff line change
@@ -1,54 +1,55 @@
module SearchWorks
class PageLocation
def initialize(params={})
def initialize(params = {})
@params = params
end

def access_point
@access_point ||= AccessPoints.new(@params)
end

def access_point?
access_point.to_s.present?
end
private

class AccessPoints
def initialize(params={})
delegate :to_s, to: :point
def initialize(params = {})
@params = params
end

def point
self.send(:"#{@params[:controller]}_#{@params[:action]}_access_points")
send(:"#{@params[:controller]}_#{@params[:action]}_access_points")
end

def name
to_s.gsub(/_/, ' ').capitalize.pluralize
end
def to_s
point.to_s
end

def catalog_index_access_points
if @params[:f]
if format_includes_databases?
return :databases
end
if course_reserve_parameters?
return :course_reserve
end
if collection_parameters?
return :collection
end
if digital_collections_parameters?
return :digital_collections
end
if sdr_parameters?
return :sdr
end
if dissertation_theses_parameters?
return :dissertation_theses
end
return unless @params[:f]
case
when format_includes_databases?
:databases
when course_reserve_parameters?
:course_reserve
when collection_parameters?
:collection
when digital_collections_parameters?
:digital_collections
when sdr_parameters?
:sdr
when dissertation_theses_parameters?
:dissertation_theses
when bookplate_fund_parameters?
:bookplate_fund
end
end

def format_parameter
@params[:f][:format] || @params[:f][:format_main_ssim]
end

def format_includes_databases?
format_parameter.include?('Database') if format_parameter
end
Expand All @@ -58,21 +59,25 @@ def course_reserve_parameters?
end

def collection_parameters?
@params[:f][:collection].present? && !@params[:f][:collection].include?("sirsi")
@params[:f][:collection].present? && !@params[:f][:collection].include?('sirsi')
end

def digital_collections_parameters?
@params[:f][:collection_type].present? && @params[:f][:collection_type].include?("Digital Collection")
@params[:f][:collection_type].present? && @params[:f][:collection_type].include?('Digital Collection')
end

def sdr_parameters?
@params[:f][:building_facet].present? && @params[:f][:building_facet].include?("Stanford Digital Repository")
@params[:f][:building_facet].present? && @params[:f][:building_facet].include?('Stanford Digital Repository')
end

def dissertation_theses_parameters?
@params[:f][:genre_ssim].present? && @params[:f][:genre_ssim].include?('Thesis/Dissertation')
end

def bookplate_fund_parameters?
@params[:f][:fund_facet].present?
end

def course_reserves_index_access_points
:course_reserves
end
Expand All @@ -82,9 +87,8 @@ def selected_databases_index_access_points
end

def browse_index_access_points
if @params[:start]
return :callnumber_browse
end
return unless @params[:start]
:callnumber_browse
end

def method_missing(method_name, *args, &block)
Expand Down
68 changes: 68 additions & 0 deletions spec/features/bookplates_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
require 'spec_helper'

describe 'Bookplates' do
describe 'on the record view' do
it 'displays bookplate data when present' do
visit catalog_path('45')

expect(page).to have_css('h2', text: 'Bookplate')
expect(page).to have_css('.bookplate', count: 2)

within(first('.bookplate')) do
expect(page).to have_css('.media-left img')
expect(page).to have_css('.media-body a', text: 'Susan and Ruth Sharp Fund')
end

within(all('.bookplate').last) do
expect(page).to have_css('.media-left img')
expect(page).to have_css('.media-body a', text: 'The Edgar Amos Boyles Centennial Book Fund')
end
end

it 'does not include the section when there is no bookplate data' do
visit catalog_path('44')

expect(page).not_to have_css('h2', text: 'Bookplate')
expect(page).not_to have_css('.bookplate')
end
end

describe 'search results' do
let(:masthead_text) { 'Bookplates honor donors who have created and sustained acquisition funds' }
it 'displays a masthead with the bookplate data for each individual fund (with correct breadcrumb)' do
visit catalog_path('45')

click_link 'Susan and Ruth Sharp Fund'

within('.bookplate-fund-masthead') do
expect(page).to have_css('img')
expect(page).to have_css('h1', text: 'Susan and Ruth Sharp Fund')
expect(page).to have_content masthead_text
end

within('.constraint') do
expect(page).to have_css('.filterName', text: 'Bookplate')
expect(page).to have_css('.filterValue', text: 'Susan and Ruth Sharp Fund')
end

expect(page).to have_css('h2', text: '1 result')

visit catalog_path('45')

click_link 'The Edgar Amos Boyles Centennial Book Fund'

within('.bookplate-fund-masthead') do
expect(page).to have_css('img')
expect(page).to have_css('h1', text: 'The Edgar Amos Boyles Centennial Book Fund')
expect(page).to have_content masthead_text
end

within('.constraint') do
expect(page).to have_css('.filterName', text: 'Bookplate')
expect(page).to have_css('.filterValue', text: 'The Edgar Amos Boyles Centennial Book Fund')
end

expect(page).to have_css('h2', text: '1 result')
end
end
end
60 changes: 58 additions & 2 deletions spec/helpers/masthead_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
expect(helper).to receive(:render).with("catalog/mastheads/databases", {}).and_return('databases-partial')
expect(render_masthead_partial).to eq "databases-partial"
end
it "should return nil for access points that don't have mastheads" do
it "is empty for access points that don't have mastheads" do
page_location.stub(:access_point).and_return("not_an_access_point")
expect(render_masthead_partial).to be_nil
expect(render_masthead_partial).to eq ''
end
end
describe "#facets_prefix_options" do
Expand All @@ -35,4 +35,60 @@
expect(digital_collections_params_for('something')).to match /format_main_ssim.*something/
end
end

describe 'bookplate_from_document_list' do
it 'is nil when the correct facet field is not present' do
expect(helper).to receive(:params).at_least(:once).and_return({})
expect(helper.bookplate_from_document_list).to be_nil
end

it 'is nil when there is no bookplate in the first solr document' do
response = double('SolrResponse', docs: [SolrDocument.new])
expect(helper).to receive(:params).at_least(:once).and_return(
f: { fund_facet: ['ABC123'] }
)

expect(helper.bookplate_from_document_list(response)).to be_nil
end

it 'returns the bookplate that matches the value in the fund_facet' do
response = double('SolrResponse', docs: [
SolrDocument.new(
bookplates_display: [
'FUND321 -|- druid:xyz321',
'FUND123 -|- druid:abc123'
]
)
])
expect(helper).to receive(:params).at_least(:once).and_return(
f: { fund_facet: ['abc123'] }
)

bookplate = helper.bookplate_from_document_list(response)
expect(bookplate).to be_a Bookplate
expect(bookplate.send(:fund_name)).to eq 'FUND123'
expect(bookplate.send(:druid)).to eq 'abc123'
end
end

describe 'bookplate_breadcrumb_value' do
it 'returns the given fund name if there are no documents' do
response = double('SolrResponse', docs: [])
expect(bookplate_breadcrumb_value('ABC123', response)).to eq 'ABC123'
end

it 'returns the given fund name if there is no matching bookplate' do
response = double('SolrResponse', docs: [SolrDocument.new])
expect(helper).to receive(:bookplate_from_document_list).and_return(nil)
expect(helper.bookplate_breadcrumb_value('ABC123', response)).to eq 'ABC123'
end

it 'returns the bookplate text when a matching bookplate is available' do
response = double('SolrResponse', docs: [SolrDocument.new])
expect(helper).to receive(:bookplate_from_document_list).and_return(
double('Bookplate', text: 'Bookplate-text')
)
expect(helper.bookplate_breadcrumb_value('ABC123', response)).to eq 'Bookplate-text'
end
end
end
12 changes: 12 additions & 0 deletions spec/lib/page_location_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,18 @@
expect(SearchWorks::PageLocation::AccessPoints.new(base_params).point).to be_nil
end
end

describe 'bookplate_fund' do
before { base_params[:f] = { fund_facet: ['ABC123'] } }
it 'is defined when the fund_facet is present' do
expect(SearchWorks::PageLocation::AccessPoints.new(base_params).point).to eq :bookplate_fund
end

it 'is defined when the fund_facet is empty' do
base_params[:f] = { fund_facet: [] }
expect(SearchWorks::PageLocation::AccessPoints.new(base_params).point).to be_nil
end
end
end
end
describe 'for CourseReservesController#index' do
Expand Down

0 comments on commit d57c6cf

Please sign in to comment.