Skip to content

Commit

Permalink
Merge pull request #2831 from sul-dlss/mirador-component
Browse files Browse the repository at this point in the history
Extract a component for embedded mirador
  • Loading branch information
dnoneill authored Jan 30, 2025
2 parents a0604ff + 66b4c7f commit 408889f
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 27 deletions.
2 changes: 1 addition & 1 deletion app/components/custom_viewer_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% if document.external_iiif? %>
<%= render partial: "embedded_mirador3", locals: {document: document} %>
<%= render EmbeddedMiradorComponent.new(document:) %>
<% elsif document.uploaded_resource? %>
<%= render Blacklight::Gallery::OpenseadragonEmbedComponent.new(document: document, presenter: presenter, view_config: view_config) %>
<% else %>
Expand Down
11 changes: 11 additions & 0 deletions app/components/embedded_mirador_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<%= content_tag :iframe, '',
src: iframe_src,
allowfullscreen: true,
class: 'mirador-embed-wrapper',
frameborder: 0,
marginwidth: 0,
marginheight: 0,
scrolling: 'no',
width: '100%'
%>
<%= iiif_drag_n_drop(manifest_url, document:) %>
29 changes: 29 additions & 0 deletions app/components/embedded_mirador_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

# Display the embed iframe
class EmbeddedMiradorComponent < ViewComponent::Base
def initialize(document:)
@document = document
super
end

attr_reader :document

delegate :iiif_drag_n_drop, to: :helpers

def render?
document.manifest_url.present?
end

def manifest_url
@manifest_url ||= doc_manifest.starts_with?('/') ? root_url + doc_manifest.slice(1..-1) : doc_manifest
end

def iframe_src
"#{Settings.iiif_embed.url}?#{{ url: manifest_url }.to_query}"
end

def doc_manifest
document.manifest_url
end
end
14 changes: 0 additions & 14 deletions app/views/catalog/_embedded_mirador3.html.erb

This file was deleted.

29 changes: 29 additions & 0 deletions spec/components/custom_viewer_component_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe CustomViewerComponent, type: :component do
let(:component) { described_class.new(document:, presenter:) }
let(:presenter) { double }
let(:exhibit) { create(:exhibit) }
let(:manifest_url) { 'http://example.com/iiif/manifest' }

before do
exhibit.required_viewer.viewer_type = 'mirador3'
exhibit.required_viewer.save
with_request_url "/#{exhibit.slug}/catalog/cf101bh9631" do
render_inline(component)
end
end

context 'with external_iiif resource' do
let(:document) do
SolrDocument.new(id: 'abc', iiif_manifest_url_ssi: manifest_url,
spotlight_resource_type_ssim: ['spotlight/resources/iiif_harvesters'])
end

it 'renders the component' do
expect(page).to have_css "iframe[src='https://embed.stanford.edu/iiif?#{{ url: manifest_url }.to_query}']"
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,17 @@

require 'rails_helper'

describe 'catalog/_embedded_mirador3' do
RSpec.describe EmbeddedMiradorComponent, type: :component do
let(:component) { described_class.new(document:) }
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
render_inline(component)
end

it 'renders an iframe' do
render

expect(rendered).to have_css "iframe[src='https://embed.stanford.edu/iiif?#{{ url: manifest_url }.to_query}']"
expect(page).to have_css "iframe[src='https://embed.stanford.edu/iiif?#{{ url: manifest_url }.to_query}']"
end

context 'with a local IIIF manifest' do
Expand All @@ -26,9 +21,7 @@
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}']"
expect(page).to have_css "iframe[src='https://embed.stanford.edu/iiif?#{{ url: expected_url }.to_query}']"
end
end
end

0 comments on commit 408889f

Please sign in to comment.