From 52d0926a73bac39bd003c4a176b6be04510e416c Mon Sep 17 00:00:00 2001 From: TheWitness Date: Mon, 9 Nov 2026 10:24:52 -0500 Subject: [PATCH 01/15] cards: relocate shared card chrome to standard js/ and css/ paths Move the self-contained dashboard card chrome from includes/cards/ to the standard Cacti plugin asset layout (js/cards.js + css/cards.css, with a js/ index.php redirect stub) so every plugin that adopts the card interface uses an identical file layout and the bundle can be promoted to Cacti core unchanged. Update the display.php/setup.php asset includes, the intropage.js comment, the e2e theme spec path and the CHANGELOG. No behaviour change. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- CHANGELOG.md | 3 ++- {includes/cards => css}/cards.css | 0 display.php | 2 +- includes/intropage.js | 2 +- {includes/cards => js}/cards.js | 0 js/index.php | 25 +++++++++++++++++++++++++ setup.php | 2 +- tests/e2e/cacti-theme.spec.cjs | 2 +- 8 files changed, 31 insertions(+), 5 deletions(-) rename {includes/cards => css}/cards.css (100%) rename {includes/cards => js}/cards.js (100%) create mode 100644 js/index.php diff --git a/CHANGELOG.md b/CHANGELOG.md index dbace7b1..5c9bc60f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ --- develop --- * issue#471: Do not return a phantom empty row when tailing newline-terminated log files; return no rows for empty files +* dev: Relocate the shared dashboard card chrome to the standard `js/cards.js` + `css/cards.css` plugin asset paths (from `includes/cards/`) so every plugin that adopts the card interface uses an identical file layout and the bundle can be promoted to Cacti core unchanged * dev: Run the CI poller with the shared runner group so RRD files and structured directories pass permission verification * issue#466: Tolerate a small overshoot over 100% in the busiest Used Space panels so DSSTATS averaging artifacts (e.g. used reading 100.004% of total) no longer log a false "Problem with DSSTAT data" warning; only a meaningful overshoot (over 110%) now warns * issue: Size panel charts correctly on reload without waiting for a window resize. A panel's chart is drawn by an inline bb.generate() script that a strict Content-Security-Policy can run asynchronously, after reload_panel()'s resizeCharts() has already run; resizeCharts() was then a no-op and the chart kept its generated size until an unrelated window resize snapped it back. reload_panel() now watches the panel with a one-shot MutationObserver (and a wall-clock deadline) and resizes only that chart once it has actually rendered, and line/bar charts are sized from the server-rendered markup (configured height, container-fitted width) like pie and treemap instead of a fixed 100x150 @@ -37,7 +38,7 @@ * issue#440: Give Cacti theme severity indicators contrasting colors for dark details titlebars and light table rows * issue: Fix the dashboard page not scrolling with the mouse wheel over chart panels: charts were sized from the whole card (header included) and overflowed the card body, turning it into a nested scroller that captured the wheel; charts now keep their server-sized height (which also stops pie/treemap charts growing on every window resize) and card bodies no longer scroll vertically * issue: Keep long Panel Details content inside the dialog and scrollable, instead of spilling under the Close button pane, on themes (e.g. deepness) that force `.ui-dialog-content` to `overflow: visible`; the dialog height is also capped to the viewport -* issue: Render dashboard panels with a shared, self-contained card chrome (bundled `includes/cards/cards.css` + `cards.js`, no cross-plugin dependency): a left-hand drag handle and unified per-card tools (grow/shrink height, maximize, reload, remove), replacing jQuery UI Sortable with a keyboard-accessible drag; growing/shrinking a panel now resizes it immediately before the persist+reload round-trip +* issue: Render dashboard panels with a shared, self-contained card chrome (bundled `css/cards.css` + `js/cards.js`, no cross-plugin dependency): a left-hand drag handle and unified per-card tools (grow/shrink height, maximize, reload, remove), replacing jQuery UI Sortable with a keyboard-accessible drag; growing/shrinking a panel now resizes it immediately before the persist+reload round-trip * issue: Show the panel "Reload Panel" glyph as a refresh icon (fa-sync-alt) that spins while the panel reloads, instead of the retweet glyph * issue: Tune the panel titlebar severity palette per theme so green (good), orange (warning) and red (bad) read as those colors but with theme-appropriate tone and legible text on every theme (replaces the garish/olive green, pure `yellow` and black-on-mid-green text that were copied across all themes); deepness already had this treatment and is unchanged * issue: Keep the toolbar `Actions`/`Timespan`/`Panels` select2 menus on-screen by shifting the open dropdown left when it would overflow the right edge of the viewport (select2 only flips vertically, and Cacti core's `dropdownAutoWidth` widens the dropdown past the narrow control) diff --git a/includes/cards/cards.css b/css/cards.css similarity index 100% rename from includes/cards/cards.css rename to css/cards.css diff --git a/display.php b/display.php index 123bbc0e..c42b59c1 100644 --- a/display.php +++ b/display.php @@ -572,7 +572,7 @@ function display_information(): bool { element.style.color = 'lightgrey'); - for (const file of [resolve(core, `include/themes/${theme}/jquery-ui.css`), resolve(core, `include/themes/${theme}/main.css`), resolve(core, 'include/fa/css/all.css'), resolve(root, 'includes/cards/cards.css'), resolve(root, 'css/common.css'), resolve(root, `css/${theme}.css`)]) { + for (const file of [resolve(core, `include/themes/${theme}/jquery-ui.css`), resolve(core, `include/themes/${theme}/main.css`), resolve(core, 'include/fa/css/all.css'), resolve(root, 'css/cards.css'), resolve(root, 'css/common.css'), resolve(root, `css/${theme}.css`)]) { await installCss(page, file); } if (palette) await expect(page.locator('body')).toHaveCSS('opacity', '1'); From 8d79e2d60aa395223c22ad7396206edd17be41ee Mon Sep 17 00:00:00 2001 From: TheWitness Date: Mon, 9 Nov 2026 10:58:09 -0500 Subject: [PATCH 02/15] cards: move intropage.js into js/ for a consistent asset layout Relocate includes/intropage.js to js/intropage.js so all of the plugin's JavaScript lives under js/ (alongside the relocated js/cards.js), matching the standard Cacti plugin asset layout. Update the display.php include, the functions.php and unit-test comments, and the chart-resize e2e spec that reads the file. No behaviour change. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- CHANGELOG.md | 2 +- display.php | 2 +- includes/functions.php | 2 +- {includes => js}/intropage.js | 0 tests/Unit/IntropagePanelReloadButtonTest.php | 2 +- tests/e2e/chart-resize.spec.cjs | 4 ++-- 6 files changed, 6 insertions(+), 6 deletions(-) rename {includes => js}/intropage.js (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c9bc60f..b8effc86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ --- develop --- * issue#471: Do not return a phantom empty row when tailing newline-terminated log files; return no rows for empty files -* dev: Relocate the shared dashboard card chrome to the standard `js/cards.js` + `css/cards.css` plugin asset paths (from `includes/cards/`) so every plugin that adopts the card interface uses an identical file layout and the bundle can be promoted to Cacti core unchanged +* dev: Relocate the shared dashboard card chrome to the standard `js/cards.js` + `css/cards.css` plugin asset paths (from `includes/cards/`) and move the plugin's `intropage.js` to `js/intropage.js`, so all JavaScript lives under `js/`, every plugin that adopts the card interface uses an identical file layout, and the bundle can be promoted to Cacti core unchanged * dev: Run the CI poller with the shared runner group so RRD files and structured directories pass permission verification * issue#466: Tolerate a small overshoot over 100% in the busiest Used Space panels so DSSTATS averaging artifacts (e.g. used reading 100.004% of total) no longer log a false "Problem with DSSTAT data" warning; only a meaningful overshoot (over 110%) now warns * issue: Size panel charts correctly on reload without waiting for a window resize. A panel's chart is drawn by an inline bb.generate() script that a strict Content-Security-Policy can run asynchronously, after reload_panel()'s resizeCharts() has already run; resizeCharts() was then a no-op and the chart kept its generated size until an unrelated window resize snapped it back. reload_panel() now watches the panel with a one-shot MutationObserver (and a wall-clock deadline) and resizes only that chart once it has actually rendered, and line/bar charts are sized from the server-rendered markup (configured height, container-fitted width) like pie and treemap instead of a fixed 100x150 diff --git a/display.php b/display.php index c42b59c1..93069b53 100644 --- a/display.php +++ b/display.php @@ -573,7 +573,7 @@ function display_information(): bool { { From 39410b8ead470f3f54cdfe0a7ba833854e16d009 Mon Sep 17 00:00:00 2001 From: TheWitness Date: Mon, 9 Nov 2026 11:01:37 -0500 Subject: [PATCH 03/15] cards: update manifest for the relocated js/ assets The relocation added a top-level js/ directory and moved files out of includes/, which tripped the expected-file-drift manifest validator. Add js/ to manifest.json 'expected', and record the vacated includes/cards/ directory and includes/intropage.js under 'tombstones' so an upgrade prunes the stale copies a previous version left behind. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- manifest.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 9a950c93..83ede1fc 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,9 @@ { "tombstones": [ "include/", - "themes/" + "themes/", + "includes/cards/", + "includes/intropage.js" ], "expected": [ "CHANGELOG.md", @@ -15,6 +17,7 @@ "includes/", "index.php", "intropage.php", + "js/", "locales/", "manifest.json", "panellib/", From 1f46a2a1d2341e5a19c06e8375d249b4c088901b Mon Sep 17 00:00:00 2001 From: TheWitness Date: Mon, 9 Nov 2026 11:13:34 -0500 Subject: [PATCH 04/15] cards: allowlist js/index.php in the patch-coverage gate The new js/ asset directory ships the standard directory-index redirect stub (js/index.php). Like the other entry-point stubs it is not reachable from the isolated unit process, so the changed-line coverage gate cannot measure it; add it to the unmeasured allowlist with a justification. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- tests/bin/patch-coverage.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/bin/patch-coverage.php b/tests/bin/patch-coverage.php index 2acdaef9..9fdee5cc 100644 --- a/tests/bin/patch-coverage.php +++ b/tests/bin/patch-coverage.php @@ -168,6 +168,10 @@ function changed_lines($base_ref) { // isolated unit process. 'display.php', 'poller_intropage.php', + // Directory-index redirect stub (header('Location:...') + top-level + // execution); added with the new js/ asset directory and not reachable from + // the isolated unit process. Matches the other per-directory index.php stubs. + 'js/index.php', ]; $unmeasured = array_values(array_diff(array_keys($changed), array_keys($measured))); $unexpected_unmeasured = array_values(array_diff($unmeasured, $unmeasured_allowlist)); From 7ab9710cbf656809de704eb7422df7c2931d5e43 Mon Sep 17 00:00:00 2001 From: TheWitness Date: Mon, 9 Nov 2026 11:25:51 -0500 Subject: [PATCH 05/15] cards: satisfy SonarCloud reliability rules in the shared controller Clean up the shared card controller so it passes SonarCloud's Clean-as-You-Code gate when a plugin first adds it as new code: - use Number.parseInt instead of the global parseInt (javascript:S7773) - give the fire-and-forget fetch/resize/add promise chains a .catch so an adapter rejection can't become an unhandled rejection (javascript:S9383) No behaviour change; js/cards.js stays byte-identical across the plugins that bundle it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- js/cards.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/js/cards.js b/js/cards.js index 9cff785b..4f3c3891 100644 --- a/js/cards.js +++ b/js/cards.js @@ -10,7 +10,7 @@ * cacti-cards vX.Y - shared "card chrome" controller (interaction layer). * * Bundled per-plugin with no cross-plugin or core dependency and kept - * byte-identical between the plugins that use it. It wires the DOM behaviour + * byte-identical between the plugins that use it. It wires the DOM behaviou * for a .ccGrid of .ccCard elements (see cards.css for the HTML contract): * keyboard-accessible drag/drop reordering, the per-card tool buttons * (expand/collapse, grow/shrink, maximize, refresh, remove), an optional @@ -59,7 +59,7 @@ window.CactiCards = window.CactiCards || (function() { order.push(id); cards[id] = { expanded: card.classList.contains('ccCardExpanded'), - height: parseInt(card.getAttribute('data-height') || '1', 10) + height: Number.parseInt(card.getAttribute('data-height') || '1', 10) }; }); @@ -127,13 +127,13 @@ window.CactiCards = window.CactiCards || (function() { } var state = { expanded: card.classList.contains('ccCardExpanded'), - height: parseInt(card.getAttribute('data-height') || '1', 10) + height: Number.parseInt(card.getAttribute('data-height') || '1', 10) }; Promise.resolve(adapter.fetchCard(id, state)).then(function(html) { if (html != null) { replaceCard(grid, adapter, card, html); } - }); + }).catch(function() { /* fire-and-forget: the host surfaces adapter errors */ }); } function removeCard(grid, adapter, card) { @@ -153,7 +153,7 @@ window.CactiCards = window.CactiCards || (function() { replaceCard(grid, adapter, card, html); } saveLayout(grid, adapter); - }); + }).catch(function() { /* fire-and-forget: the host surfaces adapter errors */ }); } else { saveLayout(grid, adapter); } @@ -318,7 +318,7 @@ window.CactiCards = window.CactiCards || (function() { } saveLayout(grid, adapter); } - }); + }).catch(function() { /* fire-and-forget: the host surfaces adapter errors */ }); } }); } From f47e2a48b5625fb7da853d49442c836dcb855b40 Mon Sep 17 00:00:00 2001 From: TheWitness Date: Mon, 9 Nov 2026 11:41:30 -0500 Subject: [PATCH 06/15] cards: load the shared card chrome from core on Cacti 1.2.32+ Cacti 1.2.32 ships the shared card chrome in core (include/js/cards.js + include/css/cards.css), loaded by the common page header. Guard the plugin's bundled copies behind a version check so they are only enqueued on older cores; on 1.2.32+ the core copy is used. The bundled files remain for backward compatibility until the supported floor rises past 1.2.32. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- CHANGELOG.md | 1 + display.php | 6 +++++- setup.php | 7 +++++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8effc86..9af3c98d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * issue#471: Do not return a phantom empty row when tailing newline-terminated log files; return no rows for empty files * dev: Relocate the shared dashboard card chrome to the standard `js/cards.js` + `css/cards.css` plugin asset paths (from `includes/cards/`) and move the plugin's `intropage.js` to `js/intropage.js`, so all JavaScript lives under `js/`, every plugin that adopts the card interface uses an identical file layout, and the bundle can be promoted to Cacti core unchanged +* dev: Load the shared card chrome from Cacti core on 1.2.32+ (`include/js/cards.js` + `include/css/cards.css`) and only bundle the plugin's own copy on older cores * dev: Run the CI poller with the shared runner group so RRD files and structured directories pass permission verification * issue#466: Tolerate a small overshoot over 100% in the busiest Used Space panels so DSSTATS averaging artifacts (e.g. used reading 100.004% of total) no longer log a false "Problem with DSSTAT data" warning; only a meaningful overshoot (over 110%) now warns * issue: Size panel charts correctly on reload without waiting for a window resize. A panel's chart is drawn by an inline bb.generate() script that a strict Content-Security-Policy can run asynchronously, after reload_panel()'s resizeCharts() has already run; resizeCharts() was then a no-op and the chart kept its generated size until an unrelated window resize snapped it back. reload_panel() now watches the panel with a one-shot MutationObserver (and a wall-clock deadline) and resizes only that chart once it has actually rendered, and line/bar charts are sized from the server-rendered markup (configured height, container-fitted width) like pie and treemap instead of a fixed 100x150 diff --git a/display.php b/display.php index 93069b53..40c9536a 100644 --- a/display.php +++ b/display.php @@ -572,7 +572,11 @@ function display_information(): bool { Date: Mon, 9 Nov 2026 11:56:13 -0500 Subject: [PATCH 07/15] cards: make the core-chrome detection robust (guard CACTI_VERSION, require the core file) Only skip the bundled card chrome when Cacti is fully bootstrapped, is 1.2.32+, AND actually ships include/*/cards.* (the version is bumped before the core Card API lands, and isolated unit tests do not define CACTI_VERSION). This avoids an undefined-constant fatal in the page-head unit test and keeps the bundled copy loaded until a core that provides it is installed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- display.php | 8 +++++--- setup.php | 7 +++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/display.php b/display.php index 40c9536a..732f4218 100644 --- a/display.php +++ b/display.php @@ -572,9 +572,11 @@ function display_information(): bool { Date: Mon, 9 Nov 2026 12:04:50 -0500 Subject: [PATCH 08/15] cards: detect the core chrome by file presence, not Cacti version Switch the conditional to file_exists(include/*/cards.*) instead of a CACTI_VERSION check. It is more robust: the version is bumped to 1.2.32 before the core Card API lands, isolated unit tests do not define CACTI_VERSION, and file presence directly answers whether core actually ships the chrome. The bundled copy is loaded only when core does not provide it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- display.php | 4 +--- setup.php | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/display.php b/display.php index 732f4218..d4812b3b 100644 --- a/display.php +++ b/display.php @@ -574,9 +574,7 @@ function display_information(): bool { Date: Mon, 9 Nov 2026 12:32:49 -0500 Subject: [PATCH 09/15] Fix typo in comment about DOM behaviour --- js/cards.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/cards.js b/js/cards.js index 4f3c3891..fa7da8d8 100644 --- a/js/cards.js +++ b/js/cards.js @@ -10,7 +10,7 @@ * cacti-cards vX.Y - shared "card chrome" controller (interaction layer). * * Bundled per-plugin with no cross-plugin or core dependency and kept - * byte-identical between the plugins that use it. It wires the DOM behaviou + * byte-identical between the plugins that use it. It wires the DOM behaviour * for a .ccGrid of .ccCard elements (see cards.css for the HTML contract): * keyboard-accessible drag/drop reordering, the per-card tool buttons * (expand/collapse, grow/shrink, maximize, refresh, remove), an optional From 3de5d0772dd091df724a2ea8d6ad3b3aad4f8941 Mon Sep 17 00:00:00 2001 From: TheWitness Date: Mon, 9 Nov 2026 13:24:30 -0500 Subject: [PATCH 10/15] cards: sync the shared controller with the hardened canonical copy Adopt the hardened CactiCards controller from the core Card API review (dragReference pointer-row resolution + findCard re-resolution of detached references), keeping js/cards.js byte-identical with Cacti core and the other plugin bundles. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- js/cards.js | 92 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 83 insertions(+), 9 deletions(-) diff --git a/js/cards.js b/js/cards.js index fa7da8d8..0ca94cdd 100644 --- a/js/cards.js +++ b/js/cards.js @@ -46,6 +46,45 @@ window.CactiCards = window.CactiCards || (function() { return card.getAttribute(adapter.idAttr || 'data-card'); } + /* Locate the live card element for an id, used to re-resolve a reference that + * an overlapping replacement may have detached. */ + function findCard(grid, adapter, id) { + var match = null; + if (id == null) { + return null; + } + grid.querySelectorAll(cardSel(adapter)).forEach(function(card) { + if (match === null && cardId(card, adapter) === id) { + match = card; + } + }); + return match; + } + + /* Keep the documented data-* contract (data-expandable / data-expanded) in + * sync with the classes the CSS clipping and serialize() rely on, so a host + * may drive card state through either representation. Called whenever a card + * is (re)bound: initial, added, or refreshed. */ + function normalizeState(card) { + var expandable = card.getAttribute('data-expandable'); + if (expandable === '1' || expandable === 'true') { + card.classList.add('ccCardExpandable'); + } else if (expandable != null) { + card.classList.remove('ccCardExpandable'); + } + if (card.classList.contains('ccCardExpandable')) { + card.setAttribute('data-expandable', '1'); + } + + var expanded = card.getAttribute('data-expanded'); + if (expanded === '1' || expanded === 'true') { + card.classList.add('ccCardExpanded'); + } else if (expanded != null) { + card.classList.remove('ccCardExpanded'); + } + card.setAttribute('data-expanded', card.classList.contains('ccCardExpanded') ? '1' : '0'); + } + /* Collect the current order and per-card state for persistence. */ function serialize(grid, adapter) { var order = []; @@ -80,22 +119,30 @@ window.CactiCards = window.CactiCards || (function() { }, 250); } - /* The card the pointer is currently over, used as the drop insertion point. */ + /* The insertion reference for a drop: the first card that follows the pointer + * in reading order. Resolve the pointer's row before comparing horizontal + * centres so dragging over a later card in a row no longer snaps the + * insertion point back to the start of that row. */ function dragReference(grid, adapter, x, y) { var cards = Array.prototype.slice.call(grid.querySelectorAll(cardSel(adapter) + ':not(.ccCardDragging)')); - var ref = null; + var rowMatch = null; // first card in the pointer's row whose centre is past x + var belowMatch = null; // first card that begins in a row below the pointer cards.forEach(function(card) { var box = card.getBoundingClientRect(); - // Insert before the first card whose centre is past the pointer. - if (y < box.top + box.height / 2 || (y < box.bottom && x < box.left + box.width / 2)) { - if (ref === null) { - ref = card; + if (y >= box.top && y <= box.bottom) { + // Pointer is within this card's row band: compare horizontally. + if (rowMatch === null && x < box.left + box.width / 2) { + rowMatch = card; } + } else if (y < box.top && belowMatch === null) { + // This card starts in a row below the pointer; it ends the + // pointer's row when nothing in that row is past the pointer. + belowMatch = card; } }); - return ref; + return rowMatch || belowMatch; } /* Swap a card's markup in place (after refresh/add) and re-bind it. */ @@ -106,7 +153,19 @@ window.CactiCards = window.CactiCards || (function() { if (!fresh) { return null; } - card.parentNode.replaceChild(fresh, card); + // Overlapping refresh/resize responses may reference a card that an + // earlier response already swapped out, leaving the captured node + // detached. Re-resolve the live element by id so the latest response + // replaces what is currently in the grid instead of throwing on (and + // losing the update to) a detached node. + var target = card; + if (!grid.contains(target)) { + target = findCard(grid, adapter, cardId(card, adapter)); + } + if (!target || !target.parentNode) { + return null; + } + target.parentNode.replaceChild(fresh, target); bindCard(grid, adapter, fresh); if (typeof adapter.applyTheme === 'function') { adapter.applyTheme(grid); @@ -168,6 +227,8 @@ window.CactiCards = window.CactiCards || (function() { } card.__ccBound = true; + normalizeState(card); + var onHandle = function(target) { return target && target.closest && target.closest('.ccDrag'); }; @@ -216,11 +277,24 @@ window.CactiCards = window.CactiCards || (function() { saveLayout(grid, adapter); }); - card.addEventListener('dragstart', function() { + card.addEventListener('dragstart', function(event) { + // Only start a reorder when the card itself is the armed drag source. + // Native drags bubbling up from links or images in the body (or any + // drag while the handle is hidden via .ccNoDrag, which leaves the card + // unarmed) must not enter reorder mode. + if (!card.draggable || event.target !== card) { + return; + } dragging = card; card.classList.add('ccCardDragging'); }); card.addEventListener('dragend', function() { + // Native HTML drag-and-drop suppresses the mouseup that would + // otherwise disarm the card, so disarm here on every drag end. + disarm(); + if (dragging !== card) { + return; + } card.classList.remove('ccCardDragging'); dragging = null; saveLayout(grid, adapter); From 431f863ba564209bb17d054f976adae023061b4c Mon Sep 17 00:00:00 2001 From: TheWitness Date: Mon, 9 Nov 2026 13:32:39 -0500 Subject: [PATCH 11/15] cards: skip an add when that card id is already on the grid Selecting the same "Add" option twice while the first request is still pending could append two cards with the same id, because the option stays selectable until the debounced catalogue sync runs. The server deduplicates saved ids, so the displayed layout then diverged from the restored one. Guard the append in the shared controller with the existing findCard() lookup so a card id already present is never appended a second time. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- js/cards.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/js/cards.js b/js/cards.js index 0ca94cdd..5005c420 100644 --- a/js/cards.js +++ b/js/cards.js @@ -384,7 +384,11 @@ window.CactiCards = window.CactiCards || (function() { var tmp = document.createElement('div'); tmp.innerHTML = String(html).trim(); var fresh = tmp.querySelector(cardSel(adapter)) || tmp.firstElementChild; - if (fresh) { + // A second add of the same card can resolve while the first + // is still pending (the option stays selectable until the + // debounced catalogue sync), so skip ids already on the grid + // to avoid appending a duplicate the server then dedupes. + if (fresh && findCard(grid, adapter, cardId(fresh, adapter)) === null) { grid.appendChild(fresh); bindCard(grid, adapter, fresh); if (typeof adapter.applyTheme === 'function') { From b7eb52638215998186d7b990629e1af61bbf04fc Mon Sep 17 00:00:00 2001 From: TheWitness Date: Mon, 9 Nov 2026 13:56:05 -0500 Subject: [PATCH 12/15] cards: cover the setup.php card stylesheet bundling branch intropage_page_head() now only prints the plugin's own css/cards.css when core does not ship include/css/cards.css. The failing-job Cacti checkouts ship that file, so the bundling branch (setup.php:496) never executed and the changed-line coverage gate dropped to 50%. Add deterministic unit tests that drive intropage_page_head() with base_path pointed at a temporary root both without and with a core cards.css, exercising both sides of the guard. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- tests/Unit/IntropagePageHeadTest.php | 42 ++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/Unit/IntropagePageHeadTest.php b/tests/Unit/IntropagePageHeadTest.php index dfc4d23b..585c0521 100644 --- a/tests/Unit/IntropagePageHeadTest.php +++ b/tests/Unit/IntropagePageHeadTest.php @@ -34,3 +34,45 @@ expect($output)->not->toContain('a-theme-that-does-not-exist.css'); }); + +it('bundles the plugin card stylesheet when core does not ship one', function () { + $base = sys_get_temp_dir() . '/intropage-core-' . uniqid('', true); + mkdir($base, 0777, true); + + $previous = $GLOBALS['config']['base_path']; + $GLOBALS['config']['base_path'] = $base; + + try { + ob_start(); + intropage_page_head(); + $output = ob_get_clean(); + } finally { + $GLOBALS['config']['base_path'] = $previous; + rmdir($base); + } + + expect($output)->toContain('plugins/intropage/css/cards.css'); +}); + +it('does not bundle the plugin card stylesheet when core already ships one', function () { + $base = sys_get_temp_dir() . '/intropage-core-' . uniqid('', true); + mkdir($base . '/include/css', 0777, true); + file_put_contents($base . '/include/css/cards.css', '/* core copy */'); + + $previous = $GLOBALS['config']['base_path']; + $GLOBALS['config']['base_path'] = $base; + + try { + ob_start(); + intropage_page_head(); + $output = ob_get_clean(); + } finally { + $GLOBALS['config']['base_path'] = $previous; + unlink($base . '/include/css/cards.css'); + rmdir($base . '/include/css'); + rmdir($base . '/include'); + rmdir($base); + } + + expect($output)->not->toContain('plugins/intropage/css/cards.css'); +}); From ff8fe3dcc7f32132875c93dd21723f2f75203794 Mon Sep 17 00:00:00 2001 From: TheWitness Date: Tue, 10 Nov 2026 07:40:29 -0500 Subject: [PATCH 13/15] cards: sync bundled cards.js to the converged controller baseline Update js/cards.js to the converged baseline (md5 84876af1) shared by Cacti core (#8684 for 1.2.x, #8683 for develop) and every Card API plugin: the refresh/resize supersede guard, async remove-commit, the duplicate-add guard and expand/collapse keyboard focus. Byte-identical to core. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- js/cards.js | 60 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 56 insertions(+), 4 deletions(-) diff --git a/js/cards.js b/js/cards.js index 5005c420..4e5e480c 100644 --- a/js/cards.js +++ b/js/cards.js @@ -173,6 +173,22 @@ window.CactiCards = window.CactiCards || (function() { return fresh; } + /* A per-card-id request generation shared by refresh and resize so a slow + * response cannot overwrite the markup of a newer request for the same card + * (for example a refresh that lands after a later grow). The most recently + * started request for an id wins; earlier in-flight responses are discarded. */ + function startRequest(grid, id) { + if (!grid.__ccReq) { + grid.__ccReq = {}; + } + grid.__ccReq[id] = (grid.__ccReq[id] || 0) + 1; + return grid.__ccReq[id]; + } + + function requestSuperseded(grid, id, token) { + return !!grid.__ccReq && grid.__ccReq[id] !== token; + } + function refreshCard(grid, adapter, card) { var id = cardId(card, adapter); // Hosts that inject into an inner body (rather than replacing the whole @@ -188,8 +204,11 @@ window.CactiCards = window.CactiCards || (function() { expanded: card.classList.contains('ccCardExpanded'), height: Number.parseInt(card.getAttribute('data-height') || '1', 10) }; + var token = startRequest(grid, id); Promise.resolve(adapter.fetchCard(id, state)).then(function(html) { - if (html != null) { + // A newer refresh/resize for this card superseded us; discard the + // stale markup instead of reverting the card to an older state. + if (html != null && !requestSuperseded(grid, id, token)) { replaceCard(grid, adapter, card, html); } }).catch(function() { /* fire-and-forget: the host surfaces adapter errors */ }); @@ -197,17 +216,35 @@ window.CactiCards = window.CactiCards || (function() { function removeCard(grid, adapter, card) { var id = cardId(card, adapter); + // Only drop the live card and persist the new layout once the host has + // confirmed the deletion. Re-resolve by id so an overlapping refresh that + // swapped the node does not leave a detached reference behind. + var commit = function() { + var target = grid.contains(card) ? card : findCard(grid, adapter, id); + if (target && target.parentNode) { + target.parentNode.removeChild(target); + saveLayout(grid, adapter); + } + }; if (typeof adapter.onRemoveCard === 'function') { - adapter.onRemoveCard(id, card); + Promise.resolve(adapter.onRemoveCard(id, card)).then(commit).catch(function() { + /* rejected: leave the card and its saved layout untouched */ + }); + } else { + commit(); } - card.parentNode.removeChild(card); - saveLayout(grid, adapter); } function resizeCard(grid, adapter, card, dir) { var id = cardId(card, adapter); if (typeof adapter.onResize === 'function') { + var token = startRequest(grid, id); Promise.resolve(adapter.onResize(id, dir, card)).then(function(html) { + // A newer refresh/resize for this card has superseded us; leave + // its markup and layout in place rather than reverting them. + if (requestSuperseded(grid, id, token)) { + return; + } if (typeof html === 'string') { replaceCard(grid, adapter, card, html); } @@ -218,6 +255,19 @@ window.CactiCards = window.CactiCards || (function() { } } + /* After expand/collapse hides the button that was activated (see cards.css), + * move keyboard focus to the now-visible counterpart so the control is not + * lost when the card is toggled from the keyboard. */ + function refocusToolCounterpart(card, tool, counterpart) { + if (document.activeElement !== tool) { + return; + } + var next = card.querySelector('.ccTool[data-tool="' + counterpart + '"]'); + if (next) { + next.focus(); + } + } + /* Wire a single card: its drag handle (mouse + touch + keyboard) and drag * events. Handle interactions are DELEGATED from the persistent card element * so they survive hosts that replace the header markup on refresh/reload. */ @@ -348,11 +398,13 @@ window.CactiCards = window.CactiCards || (function() { case 'expand': card.classList.add('ccCardExpanded'); card.setAttribute('data-expanded', '1'); + refocusToolCounterpart(card, tool, 'collapse'); saveLayout(grid, adapter); break; case 'collapse': card.classList.remove('ccCardExpanded'); card.setAttribute('data-expanded', '0'); + refocusToolCounterpart(card, tool, 'expand'); saveLayout(grid, adapter); break; case 'grow': resizeCard(grid, adapter, card, 'grow'); break; From 734fd95fd3507c0a0780210f05654dbef2a19560 Mon Sep 17 00:00:00 2001 From: TheWitness Date: Tue, 10 Nov 2026 21:32:10 -0500 Subject: [PATCH 14/15] Sync cards.js: preserve live expand/collapse state at swap time Carry the shared Card API controller fix so a card refresh that lands while the user expanded/collapsed it no longer reverts that toggle (replaceCard preserves the live data-expanded at swap time). Byte-identical with core and the other plugins. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- js/cards.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/js/cards.js b/js/cards.js index 4e5e480c..e8d4d1eb 100644 --- a/js/cards.js +++ b/js/cards.js @@ -165,6 +165,12 @@ window.CactiCards = window.CactiCards || (function() { if (!target || !target.parentNode) { return null; } + // The in-flight response carries the expansion state captured when the + // request started, but the user may have expanded/collapsed the live + // card since. Carry the live state onto the fresh markup so the swap + // (refresh, resize or refresh-all) does not undo that toggle; bindCard's + // normalizeState applies the class from this data-expanded value. + fresh.setAttribute('data-expanded', target.classList.contains('ccCardExpanded') ? '1' : '0'); target.parentNode.replaceChild(fresh, target); bindCard(grid, adapter, fresh); if (typeof adapter.applyTheme === 'function') { From 1aca59cbdd0d094e53ba222d8c35c1d63c444015 Mon Sep 17 00:00:00 2001 From: TheWitness Date: Wed, 11 Nov 2026 09:39:45 -0500 Subject: [PATCH 15/15] Sync cards.js: scope refresh toggle preservation to real user toggles Corrected shared controller (review on core #8700): replaceCard() carries the live expand/collapse state onto refreshed markup only when the user toggled during the request and the fresh card is still expandable; host markup stays authoritative otherwise. Byte-identical with core and the other plugins. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- js/cards.js | 45 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/js/cards.js b/js/cards.js index e8d4d1eb..82503b9f 100644 --- a/js/cards.js +++ b/js/cards.js @@ -145,8 +145,32 @@ window.CactiCards = window.CactiCards || (function() { return rowMatch || belowMatch; } - /* Swap a card's markup in place (after refresh/add) and re-bind it. */ - function replaceCard(grid, adapter, card, html) { + /* Decide, mirroring normalizeState(), whether a fresh card will be + * expandable, so a preserved toggle is never forced onto a card that cannot + * expand (which would leave normalizeState() marking it ccCardExpanded and + * persisting expanded:true for a non-expandable card). */ + function willExpand(card) { + var expandable = card.getAttribute('data-expandable'); + if (expandable === '1' || expandable === 'true') { + return true; + } + if (expandable != null) { + return false; + } + return card.classList.contains('ccCardExpandable'); + } + + /* Swap a card's markup in place (after refresh/add) and re-bind it. + * + * capturedExpanded (optional) is the card's expanded state when an internal + * refresh/resize request started. When it is supplied and the live card has + * since been toggled by the user, the incoming markup reflects the stale + * captured state, so the live state is carried onto the fresh markup to avoid + * reverting that toggle - but only when the fresh card is still expandable. + * When it is omitted (direct callers) or the state is unchanged, the host + * markup's own data-expanded stays authoritative (the normalizeState + * contract, so a host may still drive expansion through returned markup). */ + function replaceCard(grid, adapter, card, html, capturedExpanded) { var tmp = document.createElement('div'); tmp.innerHTML = (html || '').trim(); var fresh = tmp.querySelector(cardSel(adapter)) || tmp.firstElementChild; @@ -165,12 +189,12 @@ window.CactiCards = window.CactiCards || (function() { if (!target || !target.parentNode) { return null; } - // The in-flight response carries the expansion state captured when the - // request started, but the user may have expanded/collapsed the live - // card since. Carry the live state onto the fresh markup so the swap - // (refresh, resize or refresh-all) does not undo that toggle; bindCard's - // normalizeState applies the class from this data-expanded value. - fresh.setAttribute('data-expanded', target.classList.contains('ccCardExpanded') ? '1' : '0'); + if (capturedExpanded != null) { + var liveExpanded = target.classList.contains('ccCardExpanded'); + if (liveExpanded !== capturedExpanded && willExpand(fresh)) { + fresh.setAttribute('data-expanded', liveExpanded ? '1' : '0'); + } + } target.parentNode.replaceChild(fresh, target); bindCard(grid, adapter, fresh); if (typeof adapter.applyTheme === 'function') { @@ -215,7 +239,7 @@ window.CactiCards = window.CactiCards || (function() { // A newer refresh/resize for this card superseded us; discard the // stale markup instead of reverting the card to an older state. if (html != null && !requestSuperseded(grid, id, token)) { - replaceCard(grid, adapter, card, html); + replaceCard(grid, adapter, card, html, state.expanded); } }).catch(function() { /* fire-and-forget: the host surfaces adapter errors */ }); } @@ -245,6 +269,7 @@ window.CactiCards = window.CactiCards || (function() { var id = cardId(card, adapter); if (typeof adapter.onResize === 'function') { var token = startRequest(grid, id); + var capturedExpanded = card.classList.contains('ccCardExpanded'); Promise.resolve(adapter.onResize(id, dir, card)).then(function(html) { // A newer refresh/resize for this card has superseded us; leave // its markup and layout in place rather than reverting them. @@ -252,7 +277,7 @@ window.CactiCards = window.CactiCards || (function() { return; } if (typeof html === 'string') { - replaceCard(grid, adapter, card, html); + replaceCard(grid, adapter, card, html, capturedExpanded); } saveLayout(grid, adapter); }).catch(function() { /* fire-and-forget: the host surfaces adapter errors */ });