Skip to content

Commit

Permalink
Merge pull request #1208 from sul-dlss/1051-virtual-objects
Browse files Browse the repository at this point in the history
Add virtual object support
  • Loading branch information
Laney McGlohon committed Mar 24, 2016
2 parents 4b15d1d + 07dcaa8 commit 9370a1f
Show file tree
Hide file tree
Showing 30 changed files with 377 additions and 66 deletions.
7 changes: 6 additions & 1 deletion app/assets/stylesheets/modules/access-panel.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@
.access-panel {
.panel-body {
h4 {
font-size: 16px;
color: $cardinal-red;
font-size: 16px;
line-height: 1.4em;
margin-bottom: 5px;

.sul-icon {
color: $sul-text-color;
}
}

.access-panel-subsection {
Expand Down
2 changes: 1 addition & 1 deletion app/models/bookplate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def initialize(bookplate_data)
end

def thumbnail_url
craft_image_url(druid, file_id, :large)
craft_image_url(druid: druid, image_id: file_id, size: :large)
end

def text
Expand Down
4 changes: 3 additions & 1 deletion app/models/concerns/digital_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ def should_display_filmstrip?
end

def number_of_documents_with_image_urls
documents.count(&:image_urls)
documents.count do |doc|
doc.image_urls.present?
end
end

def number_of_documents_without_image_urls
Expand Down
26 changes: 5 additions & 21 deletions app/models/concerns/digital_image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,16 @@ module DigitalImage
# Get stacks urls for a document using file ids
# @return [Array]
def image_urls(size = :default)
return unless image_behavior?
file_ids.map do |image_id| # this should become image_ids.map once we remove #image_behavior?
craft_image_url(druid, image_id, size)
image_ids.map do |image_id|
craft_image_url(image_id: image_id, size: size)
end
end

private

# This method should be removed once the indexing code no longer
# adds display_type to the document. We will instead determine
# image behavior based on the presence of jp2s in the file ids field.
# When we do that we can just let image_urls be blank when there are no image ids.
def image_behavior?
return unless self[:display_type].present?
return unless file_ids.present?

self[:display_type].any? do |display_type|
%w(book image).include?(display_type)
def image_ids
file_ids.select do |file_id|
file_id =~ /\.jp2$/
end
end

# Left commented out for when we remove #image_behavior?
# def image_ids
# return unless image_behavior?
# file_ids.select do |file_id|
# file_id =~ /\.jp2$/
# end
# end
end
38 changes: 38 additions & 0 deletions app/models/concerns/solr_set.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
##
# A mixin to add set member behavior to SolrDocuments.
# Items that are in a set identify their set membership
# by indexing their set's identifier in the set field.
module SolrSet
def set_member?
self[:set].present?
end

def parent_sets
return unless set_member?
@parent_sets ||= set_document_list.map do |doc|
SolrDocument.new(doc)
end
end

# Used for generating simple title links to the parent sets w/o making a Solr request
def index_parent_sets
return unless set_member? && self[:set_with_title].present?
@index_parent_sets ||= self[:set_with_title].map do |set_with_title|
id, title = set_with_title.split('-|-').map(&:strip)
SolrDocument.new(id: id, title_display: title)
end
end

private

def set_document_list
@document_list ||= Blacklight.solr.select(set_solr_params)['response']['docs']
end

def set_solr_params
ids = self['set'].map do |set_id|
"id:#{set_id}"
end.join(' OR ')
{ params: { fq: ids } }
end
end
12 changes: 9 additions & 3 deletions app/models/concerns/stacks_images.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ module StacksImages
# @param [String] image_id
# @param [Symbol] size
# @return [String]
def craft_image_url(druid, image_id, size)
image_id = image_id.gsub(/\.jp2$/, '')
"#{Settings.STACKS_URL}/iiif/#{druid}%2F#{image_id}/#{image_dimensions[size]}"
def craft_image_url(opts = {})
druid = opts[:druid]
image_id = opts[:image_id].gsub(/\.jp2$/, '')
size = image_dimensions[opts[:size]] || image_dimensions[:default]
if druid
"#{Settings.STACKS_URL}/iiif/#{druid}%2F#{image_id}/#{size}"
else
"#{Settings.STACKS_URL}/iiif/#{image_id}/#{size}"
end
end

# Size definitions for stacks IIIF urls
Expand Down
1 change: 1 addition & 0 deletions app/models/solr_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class SolrDocument
include DigitalImage
include OpenSeadragon
include SolrHoldings
include SolrSet
include MarcInstrumentation
include MarcBoundWithNote
include SolrBookplates
Expand Down
9 changes: 9 additions & 0 deletions app/views/catalog/_index_mods.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@
<% end %>
</dd>
<% end %>

<% if document.index_parent_sets.present? %>
<dt>Appears in</dt>
<dd>
<% document.index_parent_sets.each do |set| %>
<%= link_to(presenter(set).document_heading, catalog_path(set))%>
<% end %>
</dd>
<% end %>
</dl>

<%= render :partial => "catalog/search_results_accordion_sections", :locals => { :document => document } %>
4 changes: 2 additions & 2 deletions app/views/catalog/_managed_purl_embed.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<% @document.marc_links.managed_purls.each_with_index do |purl, i| %>
<li data-embed-target = '<%= "#{Settings.PURL_EMBED_RESOURCE}#{purl.druid}" %>' data-embed-provider = '<%= Settings.PURL_EMBED_PROVIDER %>'>
<% if purl.file_id %>
<img src="<%= @document.craft_image_url(purl.druid, purl.file_id, :thumbnail) %>">
<img src="<%= @document.craft_image_url(druid: purl.druid, image_id: purl.file_id, size: :thumbnail) %>">
<% end %>
<%= button_tag "part #{i + 1}" %>
</li>
Expand All @@ -22,4 +22,4 @@
<div class='managed-purl-embed'>
</div>
</div>
</div>
</div>
17 changes: 17 additions & 0 deletions app/views/catalog/access_panels/_appears_in.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<% document ||= @document %>
<% if document.set_member? && document.parent_sets.present? %>
<div class="panel panel-default access-panel panel-appears-in">
<div class="access-panel-heading panel-heading">
<h3>Appears in</h3>
</div>

<div class="panel-body">
<% @document.parent_sets.each do |parent_set| %>
<h4>
<%= render_resource_icon parent_set[parent_set.format_key] %>
<%= link_to_document(parent_set, get_main_title(parent_set)) %>
</h4>
<% end %>
</div>
</div>
<% end %>
1 change: 1 addition & 0 deletions app/views/catalog/record/_metadata_panels.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<%= render "catalog/access_panels/online" %>
<%= render "catalog/access_panels/course_reserve" %>
<%= render "catalog/access_panels/location" %>
<%= render "catalog/access_panels/appears_in" %>
<%= render "catalog/access_panels/in_collection" %>
<%= render "catalog/access_panels/collection_details" %>
<%= render "catalog/access_panels/related" %>
Expand Down
5 changes: 4 additions & 1 deletion config/solr_configs/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,17 @@
<field name="modsxml" type="string" indexed="false" stored="true" />
<!-- collection (facet and display): "sirsi" or, for DOR items, the id of their parent coll -->
<field name="collection" type="string" indexed="true" stored="true" multiValued="true" omitNorms="true" />
<!-- set: the id (druid or ckey) of the set the item is in -->
<field name="set" type="string" indexed="true" stored="true" multiValued="true" omitNorms="true" />
<!-- collection_search: allow searching within collections for aggr. colls -->
<field name="collection_search" type="string_punct_stop" indexed="true" stored="false" multiValued="true" omitNorms="true" />
<!-- display_type is used by UI code, e.g. for Hydrus objects -->
<field name="display_type" type="string" indexed="true" stored="true" multiValued="true" omitNorms="true" />
<!-- used to determine when something is a digital collection -->
<field name="collection_type" type="string" indexed="true" stored="true" multiValued="true" />
<!-- easy way to indicate collection's parent in UI (may be deprecated in future) -->
<!-- easy way to indicate collection's parent and set in UI (may be deprecated in future) -->
<field name="collection_with_title" type="string" indexed="false" stored="true" multiValued="true" />
<field name="set_with_title" type="string" indexed="false" stored="true" multiValued="true" />
<field name="img_info" type="string" indexed="false" stored="true" multiValued="true"/>
<field name="file_id" type="string" indexed="false" stored="true" multiValued="true"/>
<!-- *************** dynamic field types ****************** -->
Expand Down
4 changes: 2 additions & 2 deletions spec/fixtures/solr_documents/35.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
:imprint_display: 2012
:druid: mf774fs2413
:img_info:
- "W784_000001_300.jp2"
- "W784_000002_300.jp2"
- "mf774fs2413%2FW784_000001_300.jp2"
- "mf774fs2413%2FW784_000002_300.jp2"
2 changes: 1 addition & 1 deletion spec/fixtures/solr_documents/36.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
:imprint_display: 2012
:druid: mf774fs2413
:img_info:
- "W784_000002_300.jp2"
- "mf774fs2413%2FW784_000002_300.jp2"
2 changes: 1 addition & 1 deletion spec/fixtures/solr_documents/37.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
:imprint_display: 2012
:druid: ch281vj9735
:file_id:
- "ch281vj9735_00_0001.jp2"
- "ch281vj9735%2Fch281vj9735_00_0001.jp2"
5 changes: 5 additions & 0 deletions spec/fixtures/solr_documents/47.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
:id: 47
:title_display: A Collection of Virtual Objects
:format_main_ssim: "Archive/Manuscript"
:modsxml: <%= mods_everything %>
:collection_type: Digital Collection
14 changes: 14 additions & 0 deletions spec/fixtures/solr_documents/48.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
:id: 48
:title_display: A Virtual Object
:format_main_ssim: Map
:marcxml: <%= metadata2 %>
:marcbib_xml: <%= metadata2 %>
:display_type:
- image
:file_id:
- cg767mn6478%2F2542A.jp2
:druid: hj097bm8879
:collection:
- '47'
:collection_with_title:
- '47 -|- A Collection of Virtual Objects'
14 changes: 14 additions & 0 deletions spec/fixtures/solr_documents/49.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
:id: 49
:title_display: Another Virtual Object
:format_main_ssim: Map
:marcxml: <%= contributed_works_fixture %>
:marcbib_xml: <%= contributed_works_fixture %>
:display_type:
- image
:file_id:
- jw923xn5254%2F2542B.jp2
:druid: hj097bm8879
:collection:
- '47'
:collection_with_title:
- '47 -|- A Collection of Virtual Objects'
17 changes: 17 additions & 0 deletions spec/fixtures/solr_documents/50.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
:id: 50
:title_display: An item in a virtual object
:format_main_ssim: Map
:modsxml: <%= mods_everything %>
:display_type:
- image
:file_id:
- wn461xh4882%2F2542001.jp2
:druid: wn461xh4882
:collection:
- '47'
:collection_with_title:
- '47 -|- A Collection of Virtual Objects'
:set:
- '48'
:set_with_title:
- '48 -|- A Virtual Object'
18 changes: 18 additions & 0 deletions spec/fixtures/solr_documents/51.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
:id: 51
:title_display: Another item in a virtual object
:format_main_ssim: Map
:marcxml: <%= metadata1 %>
:marcbib_xml: <%= metadata1 %>
:display_type:
- image
:file_id:
- fh193nf4583%2F2542002.jp2
:druid: fh193nf4583
:collection:
- '47'
:collection_with_title:
- '47 -|- A Collection of Virtual Objects'
:set:
- '48'
:set_with_title:
- '48 -|- A Virtual Object'
18 changes: 18 additions & 0 deletions spec/fixtures/solr_documents/52.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
:id: 52
:title_display: An item in a another virtual object
:format_main_ssim: Map
:marcxml: <%= metadata1 %>
:marcbib_xml: <%= metadata1 %>
:display_type:
- image
:file_id:
- zm141bz6672%2F2542003.jp2
:druid: zm141bz6672
:collection:
- '47'
:collection_with_title:
- '47 -|- A Collection of Virtual Objects'
:set:
- '49'
:set_with_title:
- '49 -|- Another Virtual Object'
18 changes: 18 additions & 0 deletions spec/fixtures/solr_documents/53.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
:id: 53
:title_display: Another item in a another virtual object
:format_main_ssim: Map
:marcxml: <%= marc_382_instrumentation %>
:marcbib_xml: <%= marc_382_instrumentation %>
:display_type:
- image
:file_id:
- ty335fg4673%2F2542004.jp2
:druid: ty335fg4673
:collection:
- '47'
:collection_with_title:
- '47 -|- A Collection of Virtual Objects'
:set:
- '49'
:set_with_title:
- '49 -|- Another Virtual Object'
4 changes: 2 additions & 2 deletions spec/fixtures/solr_documents/mf774fs2413.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
:imprint_display: 1990
:druid: mf774fs2413
:img_info:
- "W784_000001_300.jp2"
- "W784_000002_300.jp2"
- "mf774fs2413%2FW784_000001_300.jp2"
- "mf774fs2413%wFW784_000002_300.jp2"
Loading

0 comments on commit 9370a1f

Please sign in to comment.