From 7ddf65a3b626e77355e97486f213cdaa3ab4a7a8 Mon Sep 17 00:00:00 2001 From: smathis Date: Thu, 23 Jul 2026 17:05:55 +0200 Subject: [PATCH] Made image placement much more flexible and avoid logging errors --- README.md | 42 ++++++++++++++++++++++++----- pages/Beamline_elements.html | 39 +++++++++++++++++---------- pages/beamline_overview_images.json | 2 ++ 3 files changed, 62 insertions(+), 21 deletions(-) create mode 100644 pages/beamline_overview_images.json diff --git a/README.md b/README.md index cec8e75..9b88932 100644 --- a/README.md +++ b/README.md @@ -28,15 +28,43 @@ build step is needed. ## Beamline_elements -To show an image of the beamline next to the table on the Beamline_elements page, -simply have the installation routine place an image called -Beamline_overview_bottom.png or Beamline_overview_right.png next to -Beamline_elements.html (Beamline_overview_bottom.png will be placed on the -bottom of the table, Beamline_overview_right.png will be placed to its right). +It is possible to show an image to the right or to the bottom of the table in +the Beamline_elements page by providing a custom beamline_overview_images.json +manifest file (it is recommended to automate this as part of the +installation routine). The default beamline_overview_images.json looks like +this: + +```json +{ +} +``` +To put an image to the right of the table, the custom file should like this: + +```json +{ + "right": "image_to_the_right", +} +``` + +Similarily, for an image at the bottom: + +```json +{ + "bottom": "image_at_the_bottom", +} +``` + +And for both right and bottom: + +```json +{ + "right": "image_to_the_right", + "bottom": "image_at_the_bottom", +} +``` The [VMS pages repository](https://gitea.psi.ch/lin-midas-pages/vms_pages) -has an example (beamline image in pages/Beamline_overview_bottom.png, which is placed -next to Beamline_elements.html by CMakeLists.txt). +has an example. ## Contact diff --git a/pages/Beamline_elements.html b/pages/Beamline_elements.html index 0cfc5f8..d0d65b8 100644 --- a/pages/Beamline_elements.html +++ b/pages/Beamline_elements.html @@ -940,30 +940,41 @@ } - // Image hooks on the right and on the bottom of the table + // Add an image only if the manifest says it exists + fetch("optional_images.json") + .then(response => response.json()) + .then(images => { + + addOptionalImage( + "beamlineOverviewHookRight", + images.right, + "Beamline overview" + ); + + addOptionalImage( + "beamlineOverviewHookBottom", + images.bottom, + "Beamline overview" + ); + + }) + .catch(() => { + // No optional images configured + }); + + function addOptionalImage(hookId, filename, alt = "") { const hook = document.getElementById(hookId); - if (!hook) return; + if (!hook || !filename) return; const img = new Image(); img.src = filename; img.alt = alt; img.onload = () => hook.appendChild(img); - img.onerror = () => {}; // Optional image not installed + img.onerror = () => {}; // Safety fallback } - addOptionalImage( - "beamlineOverviewHookRight", - "Beamline_overview_right.png", - "Beamline overview" - ); - - addOptionalImage( - "beamlineOverviewHookBottom", - "Beamline_overview_bottom.png", - "Beamline overview" - ); diff --git a/pages/beamline_overview_images.json b/pages/beamline_overview_images.json new file mode 100644 index 0000000..7a73a41 --- /dev/null +++ b/pages/beamline_overview_images.json @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file