Skip to content

chore(cards): bundle css/card-widgets.css from the Cacti core Card API - #505

Merged
TheWitness merged 2 commits into
developfrom
chore/card-widgets-css
Dec 5, 2026
Merged

TheWitness merged 2 commits into
developfrom
chore/card-widgets-css

Conversation

@TheWitness

Copy link
Copy Markdown
Member

Summary

Bundle css/card-widgets.css, the Cacti core Card API chart-widget stylesheet, which this plugin was missing (it bundled only cards.css and cards.js). syslog.php now loads it with the same file_exists() gate already used for cards.css. A new CardWidgetsSyncTest pins its hash and checks the gate.

css/card-widgets.css is now byte-identical (sha256 5bbeaf771e39623c5091d79aae99c5e1363648b6534b5bf8c9b79449b6d913d3) to Cacti core's include/css/card-widgets.css in Cacti/cacti#9322 (1.2.x) and Cacti/cacti#9323 (develop), and to the copy in every other plugin that bundles the Card API: alarmmanager, apcupsd, hmib, intropage, mactrack, syslog and topx. The bundled copy loads only when core does not ship the file, so on Cacti 1.2.32+ core's copy is used.

About the new chart types

Following the agreement to add no new PHP helpers to the plugins, this PR adds no card_*() functions. The helpers live in core lib/html.php.

  • Progress ring: needs no helper. It is drawn entirely by the stylesheet from a --cc-pct custom property, so this plugin can use it on any core:
    <div class="ccRing ccRing--up" style="--cc-pct:42"><span class="ccRingValue">42%</span></div>
  • Donut and box-and-whisker: these need a helper to compute segment offsets and scale positions, so they are available only through core's card_donut() and card_boxplot(). Their styles still ship here, so markup produced by those helpers renders correctly on every core.

The bundled copies, including the hash pinned in CardWidgetsSyncTest, can be removed once this plugin's minimum Cacti version is 1.2.32.

Verification

  • tests/Unit/CardWidgetsSyncTest.php (new): 2 passed.
  • tests/bin/validate-manifest.php: the manifest matches the tree.

Not verified: this has not been rendered in a browser on a running Cacti, and the plugin's full CI suite was not run locally.

Cacti/cacti#9322 (1.2.x) and Cacti/cacti#9323 (develop) extend the Card API
chart-widget stylesheet; every Card API plugin carries a byte-identical copy
until its minimum Cacti version is 1.2.32.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: TheWitness <thewitness@cacti.net>
Copilot AI balanced review requested due to automatic review settings December 5, 2026 13:02

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

The loading-guard assertion misses a removed negation, allowing regressions that disable the fallback on older cores and load a duplicate stylesheet on newer ones.

1 open issue
What changed in this PR

Adds the shared Card API chart-widget stylesheet as a fallback for Syslog installations whose Cacti core does not provide it.

Changes:

  • Bundles chart-widget styles without adding PHP helpers.
  • Loads the bundled stylesheet only when the core file is absent.
  • Adds hash and loader-source checks and documents the change.
File Description
tests/​Unit/​CardWidgetsSyncTest.php Pins the stylesheet hash and checks loader source.
syslog.php Adds conditional fallback stylesheet loading.
css/​card-widgets.css Bundles shared chart-widget styles.
CHANGELOG.md Records the stylesheet fallback addition.

Review effort: Balanced

Comment thread tests/Unit/CardWidgetsSyncTest.php Resolved
xmacan
xmacan previously approved these changes Dec 5, 2026
…ylesheet

Re-sync css/card-widgets.css with Cacti/cacti#9322 and #9323 after their
review (the column chart zero line, .ccColsBase) and update the pinned hash.

Check that the negated file_exists() guard directly wraps the one bundled
load, so dropping the '!' fails the test instead of passing.

Give the sync test the repository GPL v2 header from setup.php.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: TheWitness <thewitness@cacti.net>
@sonarqubecloud

sonarqubecloud Bot commented Dec 5, 2026

Copy link
Copy Markdown

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.

🟢 Approval recommended

There are no active review issues for the stylesheet fallback supporting older Cacti installations.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@somethingwithproof somethingwithproof left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Checked against #9322/#9323: css/card-widgets.css here is byte-identical to both core copies (sha256 f1b152e70086de7b31ea3e27b6f66b7a199d21d9d29fff38af0bd66d833e6301, the value CardWidgetsSyncTest pins), the file only loads when core doesn't ship its own, every rule is .cc*-scoped with no !important, and CI is green. Approve with nits:

  • The description quotes sha256 5bbeaf77…; the file and the test pin f1b152e7….

  • The core PRs are still open. Merging this first would ship a copy of CSS core hasn't merged yet; holding it until #9322/#9323 land (or saying so in the description) avoids that.

  • The load gate checks only that include/css/card-widgets.css exists. A 1.2.32 snapshot from before #9322 already has the older sparkline-era file, so the newer widgets would render unstyled there. Gating on something that tracks the new content (e.g. function_exists('card_donut')) or noting the window would cover it.

  • The sync test compares against a hash constant in this repo, so a later core change drifts silently; a comment naming the core commit the copy came from would make re-syncs easier.

  • The gate test matches the source text with a regex rather than running the page-head code, so it would not catch a gate that is present but never reached.

@somethingwithproof somethingwithproof left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approving. The nits in my earlier review are non-blocking; please merge this after #9322/#9323 land so the bundled copy matches merged core, and correct the sha256 in the description.

@TheWitness
TheWitness merged commit e9e5f0b into develop Dec 5, 2026
12 checks passed
@TheWitness
TheWitness deleted the chore/card-widgets-css branch December 5, 2026 19:12
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