diff --git a/app/controllers/catalog_controller.rb b/app/controllers/catalog_controller.rb index 6310e6a24..820899233 100644 --- a/app/controllers/catalog_controller.rb +++ b/app/controllers/catalog_controller.rb @@ -9,6 +9,10 @@ class CatalogController < ApplicationController include Blacklight::Catalog + before_action only: :manifest do + response.headers['Access-Control-Allow-Origin'] = '*' + end + before_action only: :admin do blacklight_config.view.admin_table.thumbnail_field = :thumbnail_square_url_ssm end diff --git a/app/models/concerns/manifest_concern.rb b/app/models/concerns/manifest_concern.rb index ad4e55c02..d1a107fa6 100644 --- a/app/models/concerns/manifest_concern.rb +++ b/app/models/concerns/manifest_concern.rb @@ -5,12 +5,15 @@ # convenient accessors for IIIF manifests embeded in a SolrDocument module ManifestConcern def manifest - manifest_url = fetch('iiif_manifest_url_ssi', nil) return if manifest_url.blank? || !manifest_available? manifest_url end + def manifest_url + fetch('iiif_manifest_url_ssi', nil) + end + def exhibit_specific_manifest(custom_manifest_pattern) return manifest if custom_manifest_pattern.blank? # Return early if there is not a manifest pattern (a heuristic for a non-image thing) diff --git a/app/views/catalog/_embedded_mirador3.html.erb b/app/views/catalog/_embedded_mirador3.html.erb new file mode 100644 index 000000000..e2e678219 --- /dev/null +++ b/app/views/catalog/_embedded_mirador3.html.erb @@ -0,0 +1,14 @@ +<% if document.manifest_url.present? %> + <% manifest_url = document.manifest_url.starts_with?('/') ? root_url + document.manifest_url.slice(1..-1) : document.manifest_url %> + <%= content_tag :iframe, '', + src: "#{Settings.iiif_embed.url}?#{{ url: manifest_url }.to_query}", + allowfullscreen: true, + class: 'mirador-embed-wrapper', + frameborder: 0, + marginwidth: 0, + marginheight: 0, + scrolling: 'no', + width: '100%' + %> + <%= iiif_drag_n_drop(manifest_url) %> +<% end %> diff --git a/app/views/catalog/_viewer_default.html.erb b/app/views/catalog/_viewer_default.html.erb index 7926ddf9b..c5ddf1ce7 100644 --- a/app/views/catalog/_viewer_default.html.erb +++ b/app/views/catalog/_viewer_default.html.erb @@ -1,5 +1,5 @@ <% if document.uploaded_resource? || document.external_iiif? %> - <%= render partial: "openseadragon_default", locals: {document: document} %> + <%= render partial: "embedded_mirador3", locals: {document: document} %> <% else %> <% # block comes from a local passed in from Spotlight %> <% # https://github.com/projectblacklight/spotlight/blob/37f6a4c266db9aa9d2a59529340a634d1796fefc/app/views/spotlight/sir_trevor/blocks/_solr_documents_embed_block.html.erb#L10 %> diff --git a/config/settings.yml b/config/settings.yml index 80f40fc68..9fa00445d 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -22,6 +22,8 @@ feature_flags: uat_embed: false traject: processing_thread_pool: 1 +iiif_embed: + url: https://embed.stanford.edu/iiif iiif_dnd_base_url: https://library.stanford.edu/projects/international-image-interoperability-framework/viewers?%{query} action_mailer: default_options: diff --git a/spec/controllers/spotlight/catalog_controller_spec.rb b/spec/controllers/spotlight/catalog_controller_spec.rb new file mode 100644 index 000000000..8ea2b74f4 --- /dev/null +++ b/spec/controllers/spotlight/catalog_controller_spec.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe Spotlight::CatalogController do + routes { Spotlight::Engine.routes } + + let(:exhibit) { create(:exhibit) } + let(:user) { create(:exhibit_admin, exhibit: exhibit) } + + before do + sign_in user + end + + describe '#manifest' do + it 'sets appropriate CORS headers' do + get :manifest, params: { id: 1, exhibit_id: exhibit.id, locale: 'en' } + + expect(response.headers.to_h).to include 'Access-Control-Allow-Origin' => '*' + end + end +end diff --git a/spec/models/solr_document_spec.rb b/spec/models/solr_document_spec.rb index 5e0daeba6..4f6be4536 100644 --- a/spec/models/solr_document_spec.rb +++ b/spec/models/solr_document_spec.rb @@ -19,6 +19,19 @@ end end + describe '#manifest_url' do + subject do + described_class.new( + id: 'abc123', + 'iiif_manifest_url_ssi' => 'http://www.example.com/default/' + ) + end + + it 'pulls data from the solr document' do + expect(subject.manifest_url).to eq 'http://www.example.com/default/' + end + end + describe '#exhibit_specific_manifest' do subject do described_class.new( diff --git a/spec/views/catalog/_embedded_mirador3.html.erb_spec.rb b/spec/views/catalog/_embedded_mirador3.html.erb_spec.rb new file mode 100644 index 000000000..ec8ca99fc --- /dev/null +++ b/spec/views/catalog/_embedded_mirador3.html.erb_spec.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe 'catalog/_embedded_mirador3', type: :view do + let(:document) { SolrDocument.new(id: 'abc', iiif_manifest_url_ssi: manifest_url) } + let(:manifest_url) { 'http://example.com/iiif/manifest' } + + before do + without_partial_double_verification do + allow(view).to receive_messages( + document: document + ) + end + end + + it 'renders an iframe' do + render + + expect(rendered).to have_css "iframe[src='https://embed.stanford.edu/iiif?#{{ url: manifest_url }.to_query}']" + end + + context 'with a local IIIF manifest' do + let(:manifest_url) { '/iiif/manifest' } + + it 'uses the full url to the manifest' do + expected_url = 'http://test.host/iiif/manifest' + + render + + expect(rendered).to have_css "iframe[src='https://embed.stanford.edu/iiif?#{{ url: expected_url }.to_query}']" + end + end +end