Skip to content
This repository has been archived by the owner on May 14, 2022. It is now read-only.

Commit

Permalink
generate thumbnail paths for geo works
Browse files Browse the repository at this point in the history
  • Loading branch information
eliotjordan committed Dec 1, 2016
1 parent 08611d6 commit 73acbcf
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def self.search_config
config.index.title_field = solr_name('title', :stored_searchable)
config.index.display_type_field = solr_name('has_model', :symbol)

# config.index.thumbnail_field = 'thumbnail_path_ss'
config.index.thumbnail_method = :iiif_thumbnail_path
config.index.thumbnail_field = 'thumbnail_path_ss'
config.index.thumbnail_method = :plum_thumbnail_path
# config.index.partials.delete(:thumbnail) # we render this inside _index_default.html.erb
config.index.partials += [:action_menu]

Expand Down
6 changes: 6 additions & 0 deletions app/helpers/geo_concerns_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module GeoConcernsHelper
def geo_concerns_thumbnail_path(document, image_options = {})
url = thumbnail_url(document)
image_tag url, image_options if url.present?
end
end
29 changes: 29 additions & 0 deletions app/helpers/thumbnail_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module ThumbnailHelper
# Generates a thumbnail path for the various work and fileset types.
# @param document [SolrDocument, ShowPresenter] an object's solr document or show presenter
# @param image_options [Hash]
# @return [String] thumbnail tag
def plum_thumbnail_path(document, image_options = {})
value = send(plum_thumbnail_method(document), document, image_options)
link_to_document document, value if value
end

# Gets the correct thumbnail path generation method
# for work or fileset type.
# @param document [SolrDocument, ShowPresenter] an object's solr document or show presenter
# @return [Symbol]
def plum_thumbnail_method(document)
document = document.solr_document if document.respond_to?(:solr_document)
class_name = document.to_model.class_name

if document['geo_mime_type_tesim']
# geo fileset
:geo_concerns_thumbnail_path
elsif ["ImageWork", "RasterWork", "VectorWork"].include?(class_name)
# geo work
:geo_concerns_thumbnail_path
else
:iiif_thumbnail_path
end
end
end
14 changes: 14 additions & 0 deletions spec/factories/vector_works.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FactoryGirl.define do
factory :vector_work do
title ["Test title"]
visibility Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC

transient do
user { FactoryGirl.create(:user) }
end

after(:build) do |work, evaluator|
work.apply_depositor_metadata(evaluator.user.user_key)
end
end
end
61 changes: 61 additions & 0 deletions spec/helpers/thumbnail_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
require 'rails_helper'

describe ThumbnailHelper do
subject { helper }

before do
allow(subject).to receive(:thumbnail_url).and_return('fileset.jpg')
end

context 'when document is a geo FileSet' do
let(:file_set) { FactoryGirl.create(:file_set, geo_mime_type: 'application/vnd.geo+json') }
let(:document) do
FileSetPresenter.new(
SolrDocument.new(
file_set.to_solr
), nil
)
end

it 'returns a path to the thumbnail image' do
expect(subject).to receive(:link_to_document).with(document, /<img src=\"\/images\/fileset.jpg/)
subject.plum_thumbnail_path(document)
end
end

context 'when document is a VectorWork' do
let(:vector_work) { FactoryGirl.create(:vector_work) }
let(:document) do
GeoConcerns::VectorWorkShowPresenter.new(
SolrDocument.new(
vector_work.to_solr
), nil
)
end

it 'returns a path to the thumbnail image' do
expect(subject).to receive(:link_to_document).with(document, /<img src=\"\/images\/vectorwork.jpg/)
subject.plum_thumbnail_path(document)
end
end

context 'when document is a ScannedResource' do
let(:scanned_resource) { FactoryGirl.create(:scanned_resource) }
let(:document) do
ScannedResourceShowPresenter.new(
SolrDocument.new(
scanned_resource.to_solr
), nil
)
end

before do
allow(document).to receive(:thumbnail_id).and_return('abcdefg')
end

it 'returns a path to the iiif thumbnail' do
expect(subject).to receive(:link_to_document).with(document, /ab%2Fcd%2Fef%2Fg-intermediate_file.jp2/)
subject.plum_thumbnail_path(document)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

def build_file_set(id:, to_s:)
i = instance_double(FileSetPresenter, id: id, thumbnail_id: id, to_s: to_s, collection?: false)
allow(i).to receive(:solr_document).and_return(SolrDocument.new(FileSet.new(id: "test").to_solr))
allow(IIIFPath).to receive(:new).with(id).and_return(double(thumbnail: nil))
i
end
Expand Down

0 comments on commit 73acbcf

Please sign in to comment.