Skip to content

cards: adopt the shared Card API (chrome + chart widgets) for the UPS dashboards - #68

Merged
TheWitness merged 7 commits into
developfrom
feature/standard-cards-bundle
Nov 11, 2026
Merged

TheWitness merged 7 commits into
developfrom
feature/standard-cards-bundle

Conversation

@TheWitness

@TheWitness TheWitness commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Converges apcupsd's per-UPS and Fleet dashboards on the shared Card API, matching mactrack/hmib/intropage/syslog/topx.

What

  • Bundle the canonical js/cards.js + css/cards.css + css/card-widgets.css, loaded only when core does not already ship them (file_exists gates), so on Cacti 1.2.32+ the core copies are used.
  • Thin adapter over window.CactiCards: drag/keyboard reorder, per-card tools, the add-card catalogue and the debounced layout save now come from core. The adapter keeps apcupsd's extras — the UPS picker, Cacti's timespan selector, the sortable card tables and the maximize dialog.
  • .cc* chrome contract (data-expandable / data-expanded / data-severity) with card bodies drawn from the shared .cc* chart primitives: ccGauge (incl. min/max ticks), ccBullet (incl. the average marker), ccPill severities and ccEmpty.
  • Auto-refresh standardized on Cacti's page-refresh timer + reload-on-change, like the other Card API dashboards.

Review fixes (addressing the Copilot comments on this PR)

  • Responsive grid: migrated the breakpoint overrides from the retired .apcupsdDashGrid / .apcupsdDashSpan* classes to #apcupsd_dashboard.ccGrid + .ccW*, clamping wide spans so narrow screens stack instead of creating implicit columns.
  • Sort header a11y: dropped role="button" from the <th> headers so the native columnheader role (and aria-sort announcement) is preserved.
  • Sort arrows: the direction arrows now key off aria-sort="ascending|descending" instead of the no-longer-set apcupsdDashSortAsc/Desc classes.
  • Keyboard sorting after refresh: the adapter re-enhances sort headers (tabindex/aria-sort) after every swap via the controller's post-swap hook, so refreshed/re-added cards stay keyboard-operable.
  • Layout-save errors: a server-rejected layout (e.g. the 4096-char cap) is surfaced in the .apcupsdDashSaveStatus live region instead of silently reverting.
  • Select2 Add card (1.2.x): the adapter bridges Select2's jQuery change to a native event (guarding re-entry) so choosing a card restores it on both bundled and core controllers.
  • Shared controller refresh race: cards.js now preserves the live card's expand/collapse state at swap time, so toggling a card while its refresh is in flight is no longer undone (synced byte-identical with core and the other plugins).

Depends on

  • Cacti core #8684 (1.2.x) / #8683 (develop) add .ccGaugeTick, .ccBulletAvgMarker and .ccPill--* to the shared card-widgets.css. The bundled copy here is byte-identical to those PRs, so the richer primitives render on older cores too.

Notes

  • cards.js / cards.css / card-widgets.css are byte-identical to the core PRs and the other plugin PRs.
  • includes/dashboard.php and upses.php remain in the patch-coverage allowlist (UI render modules); no measured PHP changed. Dashboard unit tests cover the new markup and refresh model.

TheWitness and others added 4 commits November 9, 2026 16:37
… dashboards

Converge apcupsd's per-UPS and Fleet dashboards on the shared Card API:

- Bundle the canonical js/cards.js + css/cards.css + css/card-widgets.css and
  load them only when core does not already ship them (file_exists gates), so
  on Cacti 1.2.32+ the core copies are used.
- Replace the plugin's own card controller with a thin adapter over the shared
  window.CactiCards engine (drag/keyboard reorder, per-card tools, add-card
  catalogue and debounced layout save now come from core); the adapter keeps
  apcupsd's extras - the UPS picker, Cacti's timespan selector, the sortable
  card tables and the maximize dialog.
- Re-vocabulary the card chrome to the .cc* contract (data-expandable /
  data-expanded / data-severity) and draw the card bodies from the shared .cc*
  chart primitives (ccGauge incl. ticks, ccBullet incl. avg marker, ccPill
  severities, ccEmpty), which the companion core change #8684 adds.
- Standardize auto-refresh on Cacti's set_page_refresh() and reload-on-change,
  matching the other Card API dashboards.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The Fleet-table sort tests asserted the old controller source (hardcoded
namespaces, per-card header prep); update them to the thin adapter which
parameterises the sort namespace and binds the maximize dialog through
apcupsdDashBindSort(dialog, ...).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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>
Sync the shared card-widgets.css so the .ccPill severity backgrounds meet
WCAG 4.5:1 contrast (mix each hue 70% with black; give --none a translucent
currentColor wash). Use Number.parseFloat and Number.isNaN instead of the
global parseFloat/isNaN in the dashboard adapter.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@TheWitness
TheWitness marked this pull request as ready for review November 11, 2026 00:23
Copilot AI balanced review requested due to automatic review settings November 11, 2026 00:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved regressions prevent restoring removed cards, make refreshed sort controls inaccessible to keyboard users, and leave narrow-screen cards too small for their content.

7 open issues
What changed in this PR

Migrates the per-UPS and Fleet dashboards to Cacti’s shared Card API, replacing plugin-specific card interactions and markup while retaining UPS-specific controls.

Changes:

  • Bundles shared card scripts and styles as fallbacks when core does not provide them.
  • Introduces a dashboard adapter and shared gauge, bullet, status-pill, and card markup.
  • Switches auto-refresh to set_page_refresh() with reload-on-change and updates related tests.
File Description
tests/​Unit/​EstimatedWattsTest.php Updates sortable-table handler assertions.
tests/​Unit/​DashboardRrdStatsTest.php Checks shared bullet-scale markup.
tests/​Unit/​DashboardRefreshTest.php Updates expectations for the new refresh model.
js/​cards.js Adds the shared card interaction controller.
js/​apcupsd_dashboard.js Adapts dashboard endpoints and controls to the shared controller.
includes/​dashboard.php Emits shared markup, loads fallback assets, and configures refresh.
css/​cards.css Adds shared card layout and toolbar styles.
css/​card-widgets.css Adds shared chart primitives and status styles.
css/​apcupsd.css Defines dashboard-specific shared-card variables.

Review effort: Balanced

Comment thread css/apcupsd.css Resolved
Comment thread js/apcupsd_dashboard.js Resolved
Comment thread js/apcupsd_dashboard.js Resolved
Comment thread js/apcupsd_dashboard.js Resolved
Comment thread js/apcupsd_dashboard.js Resolved
Comment thread js/apcupsd_dashboard.js Resolved
Comment thread js/cards.js Resolved
The .ccToolbar sits above #apcupsd_dashboard as a sibling, not a child, so it
never inherited --cc-text. .ccToolbarLabel/.ccAdd therefore fell back to the
shared chrome's light-theme #23362f default and rendered dark green on dark
themes. Bind the card palette to .ccToolbar as well so the toolbar follows
the theme foreground like the grid and dialog already do.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
bmfmancini
bmfmancini previously approved these changes Nov 11, 2026
…resh race

- Migrate the responsive breakpoints from the retired .apcupsdDashGrid/
  .apcupsdDashSpan* classes to #apcupsd_dashboard.ccGrid + .ccW*, clamping wide
  spans so narrow screens stack instead of creating implicit columns.
- Drop role=button from sortable <th> so the native columnheader role and
  aria-sort announcement are preserved; direction arrows now key off aria-sort
  instead of the no-longer-set apcupsdDashSortAsc/Desc classes.
- Re-enhance sort headers after every swap (via the controller's applyTheme
  post-swap hook) so refreshed/re-added cards stay keyboard-operable.
- Surface a server-rejected layout save in the .apcupsdDashSaveStatus live
  region instead of silently reverting on reload.
- Bridge Select2's jQuery change on the Add card select to a native event
  (guarding re-entry) so it works on Cacti 1.2.x and core controllers.
- Sync cards.js with the shared fix that preserves the live expand/collapse
  state at swap time (refresh race), byte-identical with core.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sync cards.js with the corrected shared controller (review on core #8700):
replaceCard() carries the live expand/collapse state only when the user toggled
during the request and the fresh card is still expandable, leaving host markup
authoritative otherwise. Pass the captured expanded state through the direct
refresh swap so it uses that mechanism.

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

Copy link
Copy Markdown

@TheWitness
TheWitness merged commit 1121b47 into develop Nov 11, 2026
2 of 7 checks passed
@TheWitness
TheWitness deleted the feature/standard-cards-bundle branch November 11, 2026 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants