Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IIIF viewer choice #3360

Merged
merged 3 commits into from
Oct 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/helpers/hyrax/hyrax_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module HyraxHelperBehavior
include Hyrax::CollectionsHelper
include Hyrax::ChartsHelper
include Hyrax::DashboardHelperBehavior
include Hyrax::IiifHelper

# Which translations are available for the user to select
# @return [Hash<String,String>] locale abbreviations as keys and flags as values
Expand Down
12 changes: 12 additions & 0 deletions app/helpers/hyrax/iiif_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Hyrax
module IiifHelper
def iiif_viewer_display(work_presenter, locals = {})
render iiif_viewer_display_partial(work_presenter),
locals.merge(presenter: work_presenter)
end

def iiif_viewer_display_partial(work_presenter)
'hyrax/base/iiif_viewers/' + work_presenter.iiif_viewer.to_s
end
end
end
24 changes: 22 additions & 2 deletions app/presenters/hyrax/work_show_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,35 @@ def download_url
Hyrax::Engine.routes.url_helpers.download_url(representative_presenter, host: request.host)
end

# @return [Boolean] render the UniversalViewer
def universal_viewer?
# @return [Boolean] render a IIIF viewer
def iiif_viewer?
representative_id.present? &&
representative_presenter.present? &&
representative_presenter.image? &&
Hyrax.config.iiif_image_server? &&
members_include_viewable_image?
end

alias universal_viewer? iiif_viewer?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 nice work!

deprecation_deprecate universal_viewer?: "use iiif_viewer? instead"

# @return [Symbol] the name of the IIIF viewer partial to render
# @example A work presenter with a custom iiif viewer
# module Hyrax
# class GenericWorkPresenter < Hyrax::WorkShowPresenter
# def iiif_viewer
# :my_iiif_viewer
# end
# end
# end
#
# Custom iiif viewer partial at app/views/hyrax/base/iiif_viewers/_my_iiif_viewer.html.erb
# <h3>My IIIF Viewer!</h3>
# <a href=<%= main_app.polymorphic_url([main_app, :manifest, presenter], { locale: nil }) %>>Manifest</a>
def iiif_viewer
:universal_viewer
end

# @return FileSetPresenter presenter for the representative FileSets
def representative_presenter
return nil if representative_id.blank?
Expand Down
5 changes: 1 addition & 4 deletions app/views/hyrax/base/_representative_media.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<% if presenter.representative_id.present? && presenter.representative_presenter.present? %>
<% if defined?(viewer) && viewer %>
<%= PulUvRails::UniversalViewer.script_tag %>
<div class="viewer-wrapper">
<div class="uv viewer" data-uri="<%= main_app.polymorphic_url [main_app, :manifest, presenter], { locale: nil } %>"></div>
</div>
<%= iiif_viewer_display presenter %>
<% else %>
<%= media_display presenter.representative_presenter %>
<% end %>
Expand Down
4 changes: 4 additions & 0 deletions app/views/hyrax/base/iiif_viewers/_universal_viewer.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<%= PulUvRails::UniversalViewer.script_tag %>
<div class="viewer-wrapper">
<div class="uv viewer" data-uri="<%= main_app.polymorphic_url [main_app, :manifest, presenter], { locale: nil } %>"></div>
</div>
4 changes: 2 additions & 2 deletions app/views/hyrax/base/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
<div class="panel-body">
<div class="row">
<%= render 'workflow_actions_widget', presenter: @presenter %>
<% if @presenter.universal_viewer? %>
<% if @presenter.iiif_viewer? %>
<div class="col-sm-12">
<%= render 'representative_media', presenter: @presenter, viewer: true %>
</div>
<% end %>
<div class="col-sm-3 text-center">
<%= render 'representative_media', presenter: @presenter, viewer: false unless @presenter.universal_viewer? %>
<%= render 'representative_media', presenter: @presenter, viewer: false unless @presenter.iiif_viewer? %>
<%= render 'citations', presenter: @presenter %>
<%= render 'social_media' %>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
# config.show_work_item_rows = 10

# Enable IIIF image service. This is required to use the
# UniversalViewer-ified show page
# IIIF viewer enabled show page
#
# If you have run the riiif generator, an embedded riiif service
# will be used to deliver images via IIIF. If you have not, you will
Expand Down
2 changes: 1 addition & 1 deletion lib/hyrax/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def cache_path
end

# Enable IIIF image service. This is required to use the
# UniversalViewer-enabled show page
# IIIF viewer enabled show page
#
# If you have run the hyrax:riiif generator, an embedded riiif service
# will be used to deliver images via IIIF. If you have not, you will
Expand Down
44 changes: 44 additions & 0 deletions spec/helpers/hyrax/iiif_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
RSpec.describe Hyrax::IiifHelper, type: :helper do
let(:solr_document) { SolrDocument.new }
let(:request) { double }
let(:ability) { nil }
let(:presenter) { Hyrax::WorkShowPresenter.new(solr_document, ability, request) }
let(:uv_partial_path) { 'hyrax/base/iiif_viewers/universal_viewer' }

describe '#iiif_viewer_display' do
before do
allow(helper).to receive(:iiif_viewer_display_partial).with(presenter)
.and_return(uv_partial_path)
end

it "renders a partial" do
expect(helper).to receive(:render)
.with(uv_partial_path, presenter: presenter)
helper.iiif_viewer_display(presenter)
end

it "takes options" do
expect(helper).to receive(:render)
.with(uv_partial_path, presenter: presenter, transcript_id: '123')
helper.iiif_viewer_display(presenter, transcript_id: '123')
end
end

describe '#iiif_viewer_display_partial' do
subject { helper.iiif_viewer_display_partial(presenter) }

it 'defaults to universal viewer' do
expect(subject).to eq uv_partial_path
end

context "with #iiif_viewer override" do
let(:iiif_viewer) { :mirador }

before do
allow(presenter).to receive(:iiif_viewer).and_return(iiif_viewer)
end

it { is_expected.to eq 'hyrax/base/iiif_viewers/mirador' }
end
end
end
12 changes: 10 additions & 2 deletions spec/presenters/hyrax/work_show_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
it { is_expected.to eq 'http://example.org/concern/generic_works/888888/manifest' }
end

describe '#universal_viewer?' do
describe '#iiif_viewer?' do
let(:id_present) { false }
let(:representative_presenter) { double('representative', present?: false) }
let(:image_boolean) { false }
Expand All @@ -64,7 +64,7 @@
allow(Hyrax.config).to receive(:iiif_image_server?).and_return(iiif_enabled)
end

subject { presenter.universal_viewer? }
subject { presenter.iiif_viewer? }

context 'with no representative_id' do
it { is_expected.to be false }
Expand Down Expand Up @@ -569,4 +569,12 @@
end
end
end

describe '#iiif_viewer' do
subject { presenter.iiif_viewer }

it 'defaults to universal viewer' do
expect(subject).to be :universal_viewer
end
end
end
4 changes: 2 additions & 2 deletions spec/views/hyrax/base/show.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@
expect(page).to have_content 'Foobar'
end

describe 'UniversalViewer integration' do
describe 'IIIF viewer integration' do
before do
allow(presenter).to receive(:universal_viewer?).and_return(viewer_enabled)
allow(presenter).to receive(:iiif_viewer?).and_return(viewer_enabled)
render template: 'hyrax/base/show.html.erb'
end

Expand Down