From ee76c6ad822ac2d07da3000de13b01c9463376b1 Mon Sep 17 00:00:00 2001 From: Dan Olson Date: Sun, 24 Nov 2024 21:41:14 -0500 Subject: [PATCH] Fix UV iframe embed scenario When we migrated UV to the CDN, we stopped serving UV assets from /public, which ended up breaking the iframe use case. This revives it by routing to a controller and rendering a view template. We're using a route & view rather than a static file in /public because we want to initialize UV with the same config options in both places which we can do with a partial. Additionally, if we were to serve the config as a url via a query parameter on the iframe src, UV ends up loading the attribution pop up before the config loads, which is not the exerience we want. --- app/controllers/uv_controller.rb | 5 ++ app/views/catalog/_show_default.html.erb | 78 +++--------------------- app/views/uv/_viewer_config.js.erb | 71 +++++++++++++++++++++ app/views/uv/iframe.html.erb | 67 ++++++++++++++++++++ config/routes.rb | 5 ++ 5 files changed, 155 insertions(+), 71 deletions(-) create mode 100644 app/controllers/uv_controller.rb create mode 100644 app/views/uv/_viewer_config.js.erb create mode 100644 app/views/uv/iframe.html.erb diff --git a/app/controllers/uv_controller.rb b/app/controllers/uv_controller.rb new file mode 100644 index 00000000..cc6b4ca4 --- /dev/null +++ b/app/controllers/uv_controller.rb @@ -0,0 +1,5 @@ +class UvController < ApplicationController + def iframe + render template: 'uv/iframe', layout: false + end +end diff --git a/app/views/catalog/_show_default.html.erb b/app/views/catalog/_show_default.html.erb index 161cec51..743c20e3 100644 --- a/app/views/catalog/_show_default.html.erb +++ b/app/views/catalog/_show_default.html.erb @@ -107,77 +107,13 @@ urlAdapter.bindTo(uv); uv.on("configure", ({ config, cb }) => { - cb({ - options: { - dropEnabled: true, - footerPanelEnabled: true, - headerPanelEnabled: true, - leftPanelEnabled: true, - limitLocales: false, - overrideFullScreen: false, - pagingEnabled: true, - rightPanelEnabled: true, - termsOfUseEnabled: true, - zoomToSearchResultEnabled: true, - zoomToBoundsEnabled: false - }, - modules: { - downloadDialogue: { - options: { - downloadCurrentViewEnabled: false, - downloadWholeImageHighResEnabled: false - } - }, - headerPanel: { - options: { - localeToggleEnabled: false - } - }, - moreInfoRightPanel: { - options: { - manifestDisplayOrder: "Contributing Organization,Title,Creator,Contributor,Description,Date of Creation,Dimensions,Minnesota Reflections Topic,Item Type,Item Physical Format,Formal Subject Headings,Locally Assigned Subject Headings,Minnesota City or Township,Minnesota County,State or Province,Country,GeoNames URI,Language,Local Identifier,Fiscal Sponsor,Rights Management,Contact Information" - } - }, - openSeadragonCenterPanel: { - options: { - autoHideControls: false, - requiredStatementEnabled: false - } - }, - mediaelementCenterPanel: { - options: { - requiredStatementEnabled: false - } - }, - avCenterPanel: { - options: { - requiredStatementEnabled: false - } - }, - centerPanel: { - options: { - requiredStatementEnabled: false - } - }, - contentLeftPanel: { - options: { - panelOpen: <%= !borealis_doc.assets.first.playlist? %>, - defaultToTreeEnabled: true - } - }, - searchFooterPanel: { - options: { - positionMarkerEnabled: true, - pageModeEnabled: false - } - }, - footerPanel: { - options: { - downloadEnabled: true - } - } - } - }); + cb( + <%= render( + partial: 'uv/viewer_config', + formats: [:js], + locals: { left_panel_open: !borealis_doc.assets.first.playlist? } + ) %> + ); }); <% end %> diff --git a/app/views/uv/_viewer_config.js.erb b/app/views/uv/_viewer_config.js.erb new file mode 100644 index 00000000..233828b1 --- /dev/null +++ b/app/views/uv/_viewer_config.js.erb @@ -0,0 +1,71 @@ +{ + options: { + dropEnabled: true, + footerPanelEnabled: true, + headerPanelEnabled: true, + leftPanelEnabled: true, + limitLocales: false, + overrideFullScreen: false, + pagingEnabled: true, + rightPanelEnabled: true, + termsOfUseEnabled: true, + zoomToSearchResultEnabled: true, + zoomToBoundsEnabled: false + }, + modules: { + downloadDialogue: { + options: { + downloadCurrentViewEnabled: false, + downloadWholeImageHighResEnabled: false + } + }, + headerPanel: { + options: { + localeToggleEnabled: false + } + }, + moreInfoRightPanel: { + options: { + manifestDisplayOrder: "Contributing Organization,Title,Creator,Contributor,Description,Date of Creation,Dimensions,Minnesota Reflections Topic,Item Type,Item Physical Format,Formal Subject Headings,Locally Assigned Subject Headings,Minnesota City or Township,Minnesota County,State or Province,Country,GeoNames URI,Language,Local Identifier,Fiscal Sponsor,Rights Management,Contact Information" + } + }, + openSeadragonCenterPanel: { + options: { + autoHideControls: false, + requiredStatementEnabled: false + } + }, + mediaelementCenterPanel: { + options: { + requiredStatementEnabled: false + } + }, + avCenterPanel: { + options: { + requiredStatementEnabled: false + } + }, + centerPanel: { + options: { + requiredStatementEnabled: false + } + }, + contentLeftPanel: { + options: { + panelOpen: <%= left_panel_open %>, + defaultToTreeEnabled: true + } + }, + searchFooterPanel: { + options: { + positionMarkerEnabled: true, + pageModeEnabled: false + } + }, + footerPanel: { + options: { + downloadEnabled: true + } + } + } +} diff --git a/app/views/uv/iframe.html.erb b/app/views/uv/iframe.html.erb new file mode 100644 index 00000000..aa73f47b --- /dev/null +++ b/app/views/uv/iframe.html.erb @@ -0,0 +1,67 @@ + + + + + + + + + + + + +
+ + + + diff --git a/config/routes.rb b/config/routes.rb index 54be1494..75989cd8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -19,6 +19,11 @@ %w(catalog sidekiq indexing lists).exclude?(request.params[:page]) } + ### + # For embedding UV in an iframe, set the src attribute to + # /uv/uv.html#?manifest=/iiif/:id/manifest.json + get 'uv/uv' => 'uv#iframe' + require 'sidekiq/web' mount Sidekiq::Web => '/sidekiq'