From 5c217266c45d0cd441d42a57c80330aa7bb1016e Mon Sep 17 00:00:00 2001 From: Ross Date: Tue, 28 Apr 2026 14:56:43 +0100 Subject: [PATCH] feat: Add safe mounting for display set viewers to enhance viewer initialization Co-authored-by: Copilot --- .../atlas/partials/_case_displaysets.html | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/atlas/templates/atlas/partials/_case_displaysets.html b/atlas/templates/atlas/partials/_case_displaysets.html index 9fb75b10..3029f8f5 100644 --- a/atlas/templates/atlas/partials/_case_displaysets.html +++ b/atlas/templates/atlas/partials/_case_displaysets.html @@ -96,6 +96,33 @@ if (!window.__displaysetPartialInitDone) { window.__displaysetPartialInitDone = true; + if (typeof window.mountDisplaysetViewersSafely !== 'function') { + window.mountDisplaysetViewersSafely = async function () { + try { + await new Promise(function (resolve) { + requestAnimationFrame(function () { + requestAnimationFrame(resolve); + }); + }); + + if (typeof window.mountDicomViewersSafely === 'function') { + await window.mountDicomViewersSafely(); + } else if (typeof window.mountDicomViewers === 'function') { + window.mountDicomViewers(); + } + + requestAnimationFrame(function () { + try { window.dispatchEvent(new Event('resize')); } catch (e) {} + if (typeof window.resizeDicomViewers === 'function') { + try { window.resizeDicomViewers(); } catch (e) {} + } + }); + } catch (e) { + console.warn('displayset viewer mount failed', e); + } + }; + } + if (typeof window.loadDisplaysetModal !== 'function') { window.loadDisplaysetModal = async function (url, dsId) { if (!url && dsId) url = '/atlas/' + dsId + '/display_sets/modal'; @@ -118,6 +145,7 @@ } bootstrap.Modal.getOrCreateInstance(modalEl).show(); + await window.mountDisplaysetViewersSafely(); } catch (error) { console.error('Error loading display set details:', error); modalBody.innerHTML = '

Failed to load display set.

'; @@ -164,6 +192,7 @@ rightEl.innerHTML = tmp.innerHTML; bootstrap.Modal.getOrCreateInstance(fullModalEl).show(); + await window.mountDisplaysetViewersSafely(); } catch (error) { console.error('Error loading fullscreen display set:', error); leftEl.innerHTML = '

Failed to load viewer

';