Skip to content

cards: adopt the shared byte-identical card chrome - #412

Merged
TheWitness merged 8 commits into
developfrom
feature/standard-cards-bundle
Nov 9, 2026
Merged

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

Conversation

@TheWitness

Copy link
Copy Markdown
Member

Summary

Converges the MacTrack dashboard on the shared, byte-identical dashboarding card interface (the CactiCards chrome from intropage), as part of standardizing the card UI across the Cacti plugins so it can be promoted to core unchanged.

  • js/cards.js is now the byte-identical shared CactiCards controller (previously an inlined MacTrack-only copy). MacTrack-specific wiring moves to a thin js/mactrack_dashboard.js adapter (refresh / add / layout / maximize -> mactrack_view_dashboard.php endpoints).
  • css/cards.css is the byte-identical shared chrome. The card markup/CSS now use the shared .cc* contract. MacTrack's --cc-* theme bindings and card-body widgets (tables, key/value lists, proportion bars) live in css/mactrack-dashboard.css.
  • mactrack_view_dashboard.php renders .ccCard / .ccW* / .ccTool markup with the data-expandable / data-expanded attributes the shared chrome expects.

No functional change to the dashboard behaviour (drag/keyboard reorder, per-card tools, Add-card catalogue, layout persistence all unchanged). cards.js and cards.css are verified md5-identical to the intropage canonical bundle.

Validation

Static only: php -l (dashboard + setup),
ode --check (controller + adapter), and class/reference sweeps. Live UI validation pending (maintainer).

Context

Companion to Cacti/plugin_intropage#473 (which relocates the canonical bundle to js/cards.js + css/cards.css). Follow-ups converge hmib, apcupsd, syslog, alarmmanager, monitor and topx, then Phase 2 lands the bundle + PHP helpers in core 1.2.x and develop.

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

@TheWitness

Copy link
Copy Markdown
Member Author

SonarCloud Quality Gate — addressed

The gate failed with Reliability Rating C on new code. All 5 flagged issues were in js/cards.js — the shared, byte-identical card controller this PR adopts from intropage. Rather than diverge the bundle, I fixed them in the canonical source (Cacti/plugin_intropage#473) and re-synced the identical file here (59e1f5b):

Rule Severity Where Fix
javascript:S9383 MAJOR (Bug) fetch / resize / add promise chains Added a .catch so an adapter rejection can't become an unhandled rejection
javascript:S7773 MINOR data-height parsing (×2) Use Number.parseInt instead of the global parseInt

No behaviour change. js/cards.js remains md5-identical to the intropage canonical copy. These will close as Fixed on the next analysis.

TheWitness and others added 2 commits November 9, 2026 11:27
Converge the MacTrack dashboard on the shared dashboarding card interface so
the chrome can be promoted to Cacti core unchanged:

- js/cards.js is now the byte-identical shared CactiCards controller (was an
  inlined MacTrack-only copy); MacTrack-specific wiring moves to a thin
  js/mactrack_dashboard.js adapter (fetch/add/layout/maximize endpoints).
- css/cards.css is the byte-identical shared chrome; the card markup and CSS
  now use the shared .cc* contract. MacTrack's --cc-* theme bindings and
  card-body widgets (tables, key/value lists, bars) live in
  css/mactrack-dashboard.css.
- mactrack_view_dashboard.php renders .ccCard/.ccW*/.ccTool markup with the
  data-expandable/data-expanded attributes the shared chrome expects.

No functional change to the dashboard behaviour.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Re-sync the byte-identical shared card controller with the intropage canonical
copy, which now passes SonarCloud's Clean-as-You-Code gate:

- 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 remains byte-identical with plugin_intropage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@TheWitness
TheWitness force-pushed the feature/standard-cards-bundle branch from 59e1f5b to 599cab9 Compare November 9, 2026 16:27
@TheWitness
TheWitness marked this pull request as ready for review November 9, 2026 16:29
Copilot AI balanced review requested due to automatic review settings November 9, 2026 16:29

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

Overlapping layout saves can overwrite the user's latest order or expanded state, with additional unresolved duplicate-card, drag-and-drop, and dark-theme defects.

5 open issues
What changed in this PR

Migrates the MacTrack dashboard to the shared CactiCards interface, separating reusable card controls and styling from plugin-specific behavior in preparation for adoption by Cacti core.

Changes:

  • Replaces the MacTrack-only controller with shared card interactions and a thin endpoint adapter.
  • Converts dashboard markup to the .cc* contract and separates theme bindings and content widgets from shared styles.
  • Registers the new assets and documents the migration. Live UI validation remains pending.
File Description
setup.php Loads the dashboard adapter and plugin-specific stylesheet.
mactrack_view_dashboard.php Uses shared card classes and state attributes.
js/​mactrack_dashboard.js Connects shared controls to MacTrack endpoints and dialogs.
js/​cards.js Provides the shared card interaction controller.
css/​mactrack-dashboard.css Defines MacTrack theme bindings and content styles.
css/​cards.css Provides shared card layout and control styling.
CHANGELOG.md Documents the shared-interface migration.

Review effort: Balanced

Comment thread js/mactrack_dashboard.js Resolved
Comment thread css/mactrack-dashboard.css Resolved
Comment thread js/cards.js Resolved
Comment thread js/cards.js Resolved
Comment thread js/cards.js Resolved
TheWitness and others added 6 commits November 9, 2026 11:41
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 MacTrack-specific adapter and dashboard
CSS still load on every version. 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>
…quire the core file)

Only skip the bundled card chrome when Cacti is fully bootstrapped, is 1.2.32+,
AND actually ships include/js/cards.js (the version is bumped before the core
Card API lands). This keeps the bundled copy loaded - and its include lines
covered - until a core that provides the API is installed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Switch the conditional to file_exists(include/js/cards.js) instead of a
CACTI_VERSION check. It is more robust: the version is bumped to 1.2.32 before
the core Card API lands, 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>
Adopt the hardened CactiCards controller from the core Card API review
(dragReference pointer-row resolution + findCard re-resolution of detached
references) and the header-comment typo fix, keeping js/cards.js byte-identical
with Cacti core and the other plugin bundles.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Re-syncs js/cards.js byte-identical with the intropage canonical bundle,
picking up the guard that skips an "Add" whose card id is already on the
grid. This closes the duplicate-card window where selecting the same option
twice while the first request was pending appended two cards with the same
id (which the server then deduplicated, diverging the displayed layout from
the restored one).

cards.js stays md5-identical to Cacti/plugin_intropage#473.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Two MacTrack-specific fixes for the shared card dashboard:

- Serialize layout saves in the adapter. dash_layout replaces the entire
  saved layout, and the shared controller only debounces bursts within
  250 ms, so two reorders more than 250 ms apart could race and let an older
  request complete last, overwriting the user's final order/expanded state.
  Chain each POST after the previous one settles to preserve write order.

- Bind the --cc-* palette to the dashboard panel and the maximize dialog,
  not just the grid. The Add toolbar is a sibling of the grid and the dialog
  is moved under <body> by jQuery UI, so both previously fell back to the
  shared chrome's light-theme defaults (dark text, white select) on dark
  themes. Binding the panel and dialog lets all shared chrome follow the
  active theme.

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

sonarqubecloud Bot commented Nov 9, 2026

Copy link
Copy Markdown

@TheWitness

Copy link
Copy Markdown
Member Author

Review feedback addressed

All five Copilot review threads are fixed and resolved. CI (CodeQL, SonarCloud, JS analysis, PHP 8.2–8.6) is green/re-running on the new head.

Finding File Fix Commit
Overlapping layout saves can overwrite the latest order/expanded state js/mactrack_dashboard.js mactrackDashboardSaveLayout serializes dash_layout POSTs (chain each after the previous settles), preserving write order; one save in flight, continues across failures 20a8eaa
Toolbar label and maximized content use light-theme fallbacks on dark themes css/mactrack-dashboard.css Bound --cc-* to #mactrack_dashboard_panel and #mactrack_dashboard_dialog, so the Add toolbar (grid sibling) and the dialog (moved under <body>) follow the active theme 20a8eaa
Dragging the upper half of a row snaps insertion to the row start js/cards.js dragReference resolves the pointer's row first, then compares horizontal midpoints only within that row (rowMatch/belowMatch) bf2ce5d
card.draggable not reset after a native drag js/cards.js dragend calls disarm() (card.draggable = false) on every drag end bf2ce5d
Duplicate cards when adding the same option during a pending request js/cards.js Add handler skips the append when findCard(...) already returns the card 9a52cc6

The js/cards.js fixes were made in the canonical bundle (Cacti/plugin_intropage#473, commit 431f863) and re-synced here byte-identical — cards.js stays md5 887c535… and cards.css c4337c8… across both plugins.

@TheWitness
TheWitness merged commit 7c73fd4 into develop Nov 9, 2026
9 checks passed
@TheWitness
TheWitness deleted the feature/standard-cards-bundle branch November 9, 2026 18:47
TheWitness pushed a commit that referenced this pull request Nov 10, 2026
plugin_mactrack #412 merged with an earlier cards.js, leaving it byte-divergent
from the canonical CactiCards controller. Re-sync it to the converged baseline
(md5 84876af1) that Cacti core (#8684 for 1.2.x, #8683 for develop) and every
Card API plugin now carry: the refresh/resize supersede guard, async
remove-commit, the duplicate-add guard and expand/collapse keyboard focus.

mactrack uses only the card chrome (no chart primitives), so no card-widgets.css
is bundled; css/cards.css is already byte-identical to canonical.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
TheWitness added a commit that referenced this pull request Nov 11, 2026
)

* Bring the bundled Card API controller up to the converged baseline

Replace js/cards.js with the canonical controller (md5 20694b4c), byte-identical
with core and the other plugins. mactrack adopted the chrome early (#412), so its
bundled controller was an older lineage missing the request-generation guard,
confirmed card removal, keyboard refocus and the new swap-time expand/collapse
preservation. css/cards.css already matched; the controller API is a backward-
compatible superset so the mactrack adapter is unaffected.

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

* 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>

---------

Co-authored-by: TheWitness <copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

3 participants