feat(viewer): Refactor truncate viewer API integration and update modal handling
This commit is contained in:
@@ -249,7 +249,7 @@
|
|||||||
<div class="card h-100">
|
<div class="card h-100">
|
||||||
<div class="card-header fw-semibold">Viewer / Compare Preview</div>
|
<div class="card-header fw-semibold">Viewer / Compare Preview</div>
|
||||||
<div class="card-body p-2 d-flex flex-column gap-2">
|
<div class="card-body p-2 d-flex flex-column gap-2">
|
||||||
<div id="truncate-modal-viewer" class="dicom-viewer-root w-100"
|
<div id="truncate_viewer" class="dicom-viewer-root w-100"
|
||||||
style="height: 320px; background: #222;"
|
style="height: 320px; background: #222;"
|
||||||
data-images="{{ image_url_array_and_count.0 }}"
|
data-images="{{ image_url_array_and_count.0 }}"
|
||||||
data-auto-cache-stack="false">
|
data-auto-cache-stack="false">
|
||||||
@@ -381,6 +381,7 @@
|
|||||||
<script>
|
<script>
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
const apiKey = "root"
|
const apiKey = "root"
|
||||||
|
const truncateApiKey = "truncate_viewer";
|
||||||
const seriesPk = {{ series.pk }};
|
const seriesPk = {{ series.pk }};
|
||||||
const totalImages = {{ image_url_array_and_count.1 }};
|
const totalImages = {{ image_url_array_and_count.1 }};
|
||||||
const viewerHeightKey = `series_viewer_height_${seriesPk}`;
|
const viewerHeightKey = `series_viewer_height_${seriesPk}`;
|
||||||
@@ -455,30 +456,14 @@
|
|||||||
}, 200);
|
}, 200);
|
||||||
});
|
});
|
||||||
|
|
||||||
function resolveViewerApi(baseName) {
|
function getTruncateViewerApi(baseName) {
|
||||||
const candidates = [
|
const fn = window[`${baseName}_${truncateApiKey}`];
|
||||||
`${baseName}_${apiKey}`,
|
return typeof fn === 'function' ? fn : null;
|
||||||
`${baseName}_root`,
|
|
||||||
`${baseName}_truncate_modal_viewer`,
|
|
||||||
`${baseName}_truncate-modal-viewer`,
|
|
||||||
];
|
|
||||||
|
|
||||||
for (const name of candidates) {
|
|
||||||
if (typeof window[name] === 'function') {
|
|
||||||
return window[name];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fallback: first matching function name from global scope.
|
|
||||||
const dyn = Object.keys(window).find(
|
|
||||||
(k) => k.startsWith(`${baseName}_`) && typeof window[k] === 'function'
|
|
||||||
);
|
|
||||||
return dyn ? window[dyn] : null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById('truncate-set-lower-btn')?.addEventListener('click', (e) => {
|
document.getElementById('truncate-set-lower-btn')?.addEventListener('click', (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const getStackPosition = resolveViewerApi('getCurrentStackPosition');
|
const getStackPosition = getTruncateViewerApi('getCurrentStackPosition');
|
||||||
if (getStackPosition) {
|
if (getStackPosition) {
|
||||||
const current = getStackPosition(0);
|
const current = getStackPosition(0);
|
||||||
const pos = Number.isFinite(current) ? current + 1 : 1;
|
const pos = Number.isFinite(current) ? current + 1 : 1;
|
||||||
@@ -489,7 +474,7 @@
|
|||||||
|
|
||||||
document.getElementById('truncate-set-upper-btn')?.addEventListener('click', (e) => {
|
document.getElementById('truncate-set-upper-btn')?.addEventListener('click', (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const getStackPosition = resolveViewerApi('getCurrentStackPosition');
|
const getStackPosition = getTruncateViewerApi('getCurrentStackPosition');
|
||||||
if (getStackPosition) {
|
if (getStackPosition) {
|
||||||
const current = getStackPosition(0);
|
const current = getStackPosition(0);
|
||||||
const pos = Number.isFinite(current) ? current + 1 : 1;
|
const pos = Number.isFinite(current) ? current + 1 : 1;
|
||||||
@@ -511,13 +496,16 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const truncateFn = resolveViewerApi('truncateStack');
|
const truncateFn = getTruncateViewerApi('truncateStack');
|
||||||
if (truncateFn) {
|
if (truncateFn) {
|
||||||
const ok = truncateFn(lower, upper);
|
const ok = truncateFn(lower, upper);
|
||||||
if (ok) {
|
if (ok) {
|
||||||
document.getElementById('truncate-modal-output').innerHTML = `Preview shows images ${lower + 1} to ${upper + 1} (${upper - lower + 1} total).`;
|
document.getElementById('truncate-modal-output').innerHTML = `Preview shows images ${lower + 1} to ${upper + 1} (${upper - lower + 1} total).`;
|
||||||
document.getElementById('truncate-modal-output').classList.remove('d-none');
|
document.getElementById('truncate-modal-output').classList.remove('d-none');
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
document.getElementById('truncate-modal-output').innerHTML = 'Truncate viewer API not ready yet. Reopen the modal and try again.';
|
||||||
|
document.getElementById('truncate-modal-output').classList.remove('d-none');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user