Files
cacti/include/css
fb354dbf5e feature: add a shared dashboarding Card API (chrome + chart widgets) to core (#8683)
* feature: add a shared dashboarding Card API (chrome + chart widgets) to core (#8680)

* feature: add a shared dashboarding Card API to core

Ship the shared card chrome used by the dashboarding plugins as core assets:
include/js/cards.js (the window.CactiCards controller) and
include/css/cards.css (the themeable .cc* markup contract). Both are loaded by
the common page header (lib/html.php) so any plugin or core page can render a
draggable, reorderable grid of cards without bundling its own copy.

The files are byte-identical to the copies currently vendored in the intropage
and mactrack plugins; those plugins load the core copy on Cacti 1.2.32+ and
fall back to their bundled copy on older cores.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* test(security): refresh the sink inventory baseline

The tracked sink baseline had drifted against the current 1.2.x tree: many
source files changed line numbers (and a few redirect sinks) since it was last
regenerated, so the 'sink and architectural hotspot guard' failed for every PR
branched off current 1.2.x. Regenerate it with
tests/security/build_sink_inventory.sh. No new sinks are introduced by the Card
API (cards.js/cards.css are not PHP and add no tracked sinks); this is a
line-number/ordering resync of pre-existing entries.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix(ui): harden the CactiCards controller per review feedback

- dragReference: resolve the pointer row before comparing horizontal
  centres so dragging over a later card no longer snaps the insertion
  point to the start of the row
- replaceCard: re-resolve the target by card id when the captured node
  was already swapped out, so overlapping refresh/resize responses no
  longer throw on a detached node (and resize still saves layout)
- normalizeState: sync the documented data-expandable/data-expanded
  attributes with the .ccCardExpandable/.ccCardExpanded classes used for
  CSS clipping and serialize(), bridging the cards.css selector mismatch
- dragstart: only enter reorder mode when the card itself is the armed
  drag source, ignoring native drags bubbling from body links/images
- dragend: disarm card.draggable on every drag end since native DnD
  suppresses the mouseup cleanup path

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* feature: add shared card-widget chart primitives to the Card API

Extend the Card API with a small, JS-free chart-primitive library so any plugin
- including third-party panels surfaced inside another plugin such as Intropage
- can draw rich card bodies with no plugin-specific stylesheet or JavaScript:

- include/css/card-widgets.css: the themeable .cc* primitives (semicircular
  gauge, usage/distribution bars, min/avg/max bullet, stacked proportion bar,
  stat tiles), coloured from currentColor and the shared --cc-sev-* properties.
  Loaded by the common page header alongside cards.css.
- lib/html.php: card_gauge(), card_bar(), card_bullet(), card_stackbar() and
  card_stat() render helpers (plus card_severity()) that emit exactly that
  markup. Available wherever global.php is loaded (web and poller).

These consolidate the near-identical gauge/bullet/bar/stack widgets currently
duplicated across the hmib, apcupsd and mactrack dashboards.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: TheWitness <copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Fix typo in comment about DOM behaviour

* fix(ci): number and reorder CHANGELOG entries and inventory cards.js

- Move the two Card API feature entries into the 1.3.0-dev feature block and
  number them (#8683) so .github/scripts/check-changelog.py accepts them
  (security->issue->feature ordering, traceable PR number).
- Register include/js/cards.js in build/legacy-js.json applicationFiles so the
  JavaScript contracts library inventory recognises the new core script.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* test(cards): cover the card helper CSS and PHP for the changed-line gates

- Add Playwright coverage fixtures to develop-theme-correctness.spec.ts that
  render every selector in include/css/cards.css and include/css/card-widgets.css
  (triggering the handle/tool hover and active states), so the develop theme
  correctness changed-CSS-line gate reaches 100 percent.
- Add tests/fixtures/Core/CardWidgetMarkup.php, a changed-line coverage probe
  that loads card_severity/card_gauge/card_bar/card_stat/card_stackbar/card_bullet
  in isolation and exercises every branch; register it in run_pr_change_tests.sh.
- Assign-then-return in card_gauge/card_stat/card_bullet (matching card_bar and
  card_stackbar) so Xdebug attributes the return to a covered line; no output
  change.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix(cards): harden refresh/resize ordering, async remove, and toggle focus

Address review feedback on the CactiCards controller:

- Share a per-card-id request generation between refreshCard and resizeCard
  (startRequest/requestSuperseded) and discard a superseded response before
  replacing markup, so a slow refresh can no longer revert a newer grow/shrink.
- Await onRemoveCard: only drop the live card and persist the layout once the
  host Promise fulfils, leaving the card and saved layout intact on rejection
  (and re-resolving the node by id before removal).
- Transfer keyboard focus to the revealed counterpart when expand/collapse is
  activated from the keyboard, since cards.css hides the activated button.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* feature(ui): add gauge ticks, bullet avg marker and pill severities to card-widgets

Extend the shared Card API chart-widget library with .ccGaugeTick (gauge
min/max ticks), .ccBulletAvgMarker (a dashed historical-average marker on the
min/avg/max bullet) and .ccPill--up/--warn/--down/--none (status-pill severity
colours), all themed from the existing --cc-sev-* custom properties. This lets
converging plugin dashboards draw their richer card bodies from the shared .cc*
contract. Mirrors the 1.2.x change in #8684.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix(cards): skip adding a card id already on the grid

Converge the controller: 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 present to avoid appending a duplicate the
server then dedupes. Brings the develop controller to the shared baseline that
the 1.2.x PR and every plugin bundle now carry.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Darken Card API severity pills to meet WCAG 4.5:1 contrast

The .ccPill--up/--warn/--down fallback backgrounds rendered 11px text at
3.51:1 (warn) to below the 4.5:1 WCAG AA threshold, and .ccPill--none used
currentColor as a background that resolved to white (invisible on light
themes). Mix each severity hue 70% with black for >=4.5:1 contrast with the
white label, and give --none a translucent currentColor wash that inherits
the theme foreground. Render the severity pill variants in the theme-
correctness fixture so the changed .cc* rules satisfy the CSS-line gate.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Preserve live card expand/collapse state across a Card API refresh

replaceCard() now carries the live card's current expand/collapse state onto the
fresh markup at swap time, so expanding or collapsing a card while its refresh
(or resize) response is in flight is no longer reverted. Applies to the per-card
refresh, resize and the plugins' Refresh-all paths, which all swap through
replaceCard(). Adds an e2e test that drives the controller through a refresh
landing mid-toggle, covering the changed line.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Only preserve a live card toggle when the user changed it mid-refresh

Mirror the 1.2.x review fix (#8700): replaceCard() carries the live expand/
collapse state onto fresh markup only when the user toggled during the request
(live differs from the state captured when the request started) and the fresh
card is still expandable; direct callers with no captured state keep host markup
authoritative (normalizeState contract). refreshCard() passes its captured
state; resizeCard() captures it before onResize(). Adds a second e2e case
asserting refreshed markup drives expansion when the user did not toggle.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: TheWitness <copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-11 11:46:03 -05:00
..
2026-01-30 10:32:39 -05:00