mirror of
https://github.com/Cacti/cacti.git
synced 2026-11-30 04:09:20 +09:00
* 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>
299 lines
8.7 KiB
CSS
299 lines
8.7 KiB
CSS
/*
|
|
+-------------------------------------------------------------------------+
|
|
| Copyright (C) 2004-2026 The Cacti Group |
|
|
+-------------------------------------------------------------------------+
|
|
| Cacti: The Complete RRDtool-based Graphing Solution |
|
|
+-------------------------------------------------------------------------+
|
|
*/
|
|
|
|
/*
|
|
* cacti-cards vX.Y - shared "card chrome" (presentation layer).
|
|
*
|
|
* This file is bundled per-plugin (no cross-plugin or core dependency) and is
|
|
* kept byte-identical between the plugins that use it. It styles a grid of
|
|
* cards with a draggable header, per-card tools and optional expand/resize.
|
|
* All colours come from CSS custom properties the host sets, so it inherits
|
|
* the active Cacti theme without baking any palette in.
|
|
*
|
|
* HTML contract (emitted by the host's PHP):
|
|
*
|
|
* <div class="ccGrid" style="--cc-cols:4">
|
|
* <section class="ccCard ccW2 ccH1" data-card="ID"
|
|
* data-severity="none|up|warn|down"
|
|
* data-size-model="expand|steps"
|
|
* data-expandable="0|1" data-expanded="0|1"
|
|
* data-height="1" data-height-max="3"
|
|
* data-maximize="body|details">
|
|
* <header class="ccCardHeader">
|
|
* <button class="ccDrag" ...><i class="fa fa-bars"></i></button>
|
|
* <h2 class="ccTitle">Title</h2>
|
|
* <span class="ccTools">
|
|
* <button class="ccTool" data-tool="expand|collapse|shrink|grow|maximize|refresh|remove">...</button>
|
|
* </span>
|
|
* </header>
|
|
* <div class="ccCardBody">...</div>
|
|
* </section>
|
|
* </div>
|
|
*
|
|
* Host theme variables (all optional, sensible fallbacks provided):
|
|
* --cc-cols grid column count (default 4)
|
|
* --cc-surface page surface behind the cards
|
|
* --cc-card card background
|
|
* --cc-text card foreground
|
|
* --cc-border card / divider border
|
|
* --cc-header-bg header background colour
|
|
* --cc-header-image header background image (gradient themes)
|
|
* --cc-header-fg header foreground
|
|
* --cc-sev-up/-warn/-down/-none severity hues (used as a translucent wash
|
|
* over the header + its bottom border)
|
|
*/
|
|
|
|
.ccGrid {
|
|
display: grid;
|
|
grid-template-columns: repeat(var(--cc-cols, 4), minmax(0, 1fr));
|
|
align-items: start;
|
|
gap: 14px;
|
|
margin: 10px 4px;
|
|
font-variant-numeric: tabular-nums;
|
|
}
|
|
|
|
/* Column span (width). */
|
|
.ccW1 { grid-column: span 1; }
|
|
.ccW2 { grid-column: span 2; }
|
|
.ccW3 { grid-column: span 3; }
|
|
.ccW4 { grid-column: span 4; }
|
|
.ccW5 { grid-column: span 5; }
|
|
.ccW6 { grid-column: span 6; }
|
|
.ccW7 { grid-column: span 7; }
|
|
.ccW8 { grid-column: span 8; }
|
|
|
|
/* Row span (height) for the "steps" size model. */
|
|
.ccH1 { grid-row: span 1; }
|
|
.ccH2 { grid-row: span 2; }
|
|
.ccH3 { grid-row: span 3; }
|
|
|
|
.ccCard {
|
|
box-sizing: border-box;
|
|
min-width: 0;
|
|
display: flex;
|
|
flex-direction: column;
|
|
border: 1px solid var(--cc-border, #cbd8d1);
|
|
/* lift the card off the page surface on both light and dark themes */
|
|
background: color-mix(in srgb, var(--cc-text, #23362f) 4%, var(--cc-card, #fff));
|
|
color: var(--cc-text, #23362f);
|
|
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
|
|
overflow: hidden;
|
|
}
|
|
|
|
.ccCardDragging {
|
|
opacity: 0.5;
|
|
}
|
|
|
|
.ccCardHeader {
|
|
box-sizing: border-box;
|
|
/* fixed row height so a tool/handle hover highlight never reflows the header */
|
|
min-height: 34px;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
padding: 7px 10px;
|
|
border-bottom: 1px solid var(--cc-border, #cbd8d1);
|
|
/* paint like the active theme's native html_start_box title bar */
|
|
background-color: var(--cc-header-bg, #e5ece8);
|
|
background-image: var(--cc-header-image, none);
|
|
background-repeat: repeat-x;
|
|
color: var(--cc-header-fg, var(--cc-text, #23362f));
|
|
}
|
|
|
|
/* Drag handle: lives on the LEFT of the header; grab it to reorder the card. */
|
|
.ccDrag {
|
|
order: -1;
|
|
flex: 0 0 auto;
|
|
box-sizing: border-box;
|
|
padding: 2px 5px;
|
|
/* reserve the border so a hover/focus highlight recolours it instead of resizing the header */
|
|
border: 1px solid transparent;
|
|
border-radius: 4px;
|
|
background: transparent;
|
|
color: color-mix(in srgb, currentColor 50%, transparent);
|
|
font-size: 13px;
|
|
line-height: 1;
|
|
cursor: grab;
|
|
}
|
|
|
|
.ccDrag:hover,
|
|
.ccDrag:focus-visible {
|
|
color: currentColor;
|
|
border-color: transparent;
|
|
background: color-mix(in srgb, currentColor 12%, transparent);
|
|
outline: none;
|
|
}
|
|
|
|
.ccDrag:active {
|
|
cursor: grabbing;
|
|
}
|
|
|
|
/* Host toggle to lock reordering (e.g. a "select text" mode): hide the handles. */
|
|
.ccNoDrag .ccDrag {
|
|
display: none;
|
|
}
|
|
|
|
.ccTitle {
|
|
flex: 1 1 auto;
|
|
min-width: 0;
|
|
margin: 0;
|
|
font-size: 13px;
|
|
font-weight: 600;
|
|
line-height: 1.3;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.ccTools {
|
|
flex: 0 0 auto;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 1px;
|
|
}
|
|
|
|
.ccTool {
|
|
box-sizing: border-box;
|
|
padding: 2px 5px;
|
|
/* reserve the border so a hover/focus highlight recolours it instead of resizing the header */
|
|
border: 1px solid transparent;
|
|
border-radius: 4px;
|
|
background: transparent;
|
|
color: color-mix(in srgb, currentColor 50%, transparent);
|
|
font-size: 12px;
|
|
line-height: 1;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.ccTool:hover,
|
|
.ccTool:focus-visible {
|
|
color: currentColor;
|
|
border-color: transparent;
|
|
background: color-mix(in srgb, currentColor 12%, transparent);
|
|
outline: none;
|
|
}
|
|
|
|
/* Only the control matching the card's current state is shown. */
|
|
.ccCard:not(.ccCardExpanded) .ccTool[data-tool="collapse"],
|
|
.ccCardExpanded .ccTool[data-tool="expand"] {
|
|
display: none;
|
|
}
|
|
|
|
/* Expand/collapse is only meaningful on expandable cards. */
|
|
.ccCard:not([data-expandable="1"]) .ccTool[data-tool="expand"],
|
|
.ccCard:not([data-expandable="1"]) .ccTool[data-tool="collapse"] {
|
|
display: none;
|
|
}
|
|
|
|
/* Resize tools only apply to the "steps" size model, and clamp at the ends. */
|
|
.ccCard:not([data-size-model="steps"]) .ccTool[data-tool="shrink"],
|
|
.ccCard:not([data-size-model="steps"]) .ccTool[data-tool="grow"] {
|
|
display: none;
|
|
}
|
|
|
|
.ccCardBody {
|
|
padding: 4px 12px 10px;
|
|
overflow-x: auto;
|
|
}
|
|
|
|
/* Expandable cards clip to a fixed height until "show more"; a fade hints at the
|
|
clipped content. */
|
|
.ccCardExpandable:not(.ccCardExpanded) .ccCardBody {
|
|
position: relative;
|
|
max-height: 210px;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.ccCardExpandable:not(.ccCardExpanded) .ccCardBody::after {
|
|
content: '';
|
|
position: absolute;
|
|
left: 0;
|
|
right: 0;
|
|
bottom: 0;
|
|
height: 30px;
|
|
pointer-events: none;
|
|
background: linear-gradient(transparent, color-mix(in srgb, var(--cc-text, #23362f) 4%, var(--cc-card, #fff)));
|
|
}
|
|
|
|
/*
|
|
* Severity wash. Every card carries exactly one data-severity. A single
|
|
* translucent colour layer is drawn over the sampled native theme header so the
|
|
* strength stays consistent on solid and gradient themes, light and dark. The
|
|
* hue comes from a host variable so it follows the theme's colour family.
|
|
*/
|
|
.ccCard[data-severity="none"] .ccCardHeader {
|
|
background-image:
|
|
linear-gradient(var(--cc-sev-none, rgba(140, 149, 159, 0.20)), var(--cc-sev-none, rgba(140, 149, 159, 0.20))),
|
|
var(--cc-header-image, none);
|
|
border-bottom-color: color-mix(in srgb, var(--cc-sev-none-border, #8c959f) 45%, transparent);
|
|
}
|
|
|
|
.ccCard[data-severity="up"] .ccCardHeader {
|
|
background-image:
|
|
linear-gradient(var(--cc-sev-up, rgba(148, 179, 107, 0.32)), var(--cc-sev-up, rgba(148, 179, 107, 0.32))),
|
|
var(--cc-header-image, none);
|
|
border-bottom-color: color-mix(in srgb, var(--cc-sev-up-border, #94b36b) 60%, transparent);
|
|
}
|
|
|
|
.ccCard[data-severity="warn"] .ccCardHeader {
|
|
background-image:
|
|
linear-gradient(var(--cc-sev-warn, rgba(255, 143, 30, 0.32)), var(--cc-sev-warn, rgba(255, 143, 30, 0.32))),
|
|
var(--cc-header-image, none);
|
|
border-bottom-color: color-mix(in srgb, var(--cc-sev-warn-border, #ff8f1e) 60%, transparent);
|
|
}
|
|
|
|
.ccCard[data-severity="down"] .ccCardHeader {
|
|
background-image:
|
|
linear-gradient(var(--cc-sev-down, rgba(204, 0, 0, 0.34)), var(--cc-sev-down, rgba(204, 0, 0, 0.34))),
|
|
var(--cc-header-image, none);
|
|
border-bottom-color: color-mix(in srgb, var(--cc-sev-down-border, #cc0000) 60%, transparent);
|
|
}
|
|
|
|
/* "Add card" toolbar above the grid. */
|
|
.ccToolbar {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
align-items: center;
|
|
gap: 8px;
|
|
margin: 10px 4px 0;
|
|
}
|
|
|
|
.ccToolbarLabel {
|
|
font-size: 12px;
|
|
font-weight: 600;
|
|
color: var(--cc-text, #23362f);
|
|
}
|
|
|
|
.ccAdd,
|
|
.ccRefreshInterval {
|
|
box-sizing: border-box;
|
|
padding: 4px 8px;
|
|
border: 1px solid var(--cc-border, #cbd8d1);
|
|
border-radius: 7px;
|
|
background: var(--cc-card, #fff);
|
|
color: var(--cc-text, #23362f);
|
|
font-size: 12px;
|
|
}
|
|
|
|
.ccAdd {
|
|
min-width: 220px;
|
|
}
|
|
|
|
.ccRefresh {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
margin-left: auto;
|
|
}
|
|
|
|
/* Maximize dialog: reuse the card body typography on the themed dialog surface. */
|
|
.ccDialogBody {
|
|
color: var(--cc-text, #23362f);
|
|
font-variant-numeric: tabular-nums;
|
|
}
|