Repository navigation
chore(cards): bundle css/card-widgets.css from the Cacti core Card API - #505
Conversation
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>
There was a problem hiding this comment.
🟡 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
…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>
|
somethingwithproof
left a comment
There was a problem hiding this comment.
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 pinf1b152e7…. -
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.cssexists. 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
left a comment
There was a problem hiding this comment.
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.




Summary
Bundle
css/card-widgets.css, the Cacti core Card API chart-widget stylesheet, which this plugin was missing (it bundled onlycards.cssandcards.js).syslog.phpnow loads it with the samefile_exists()gate already used forcards.css. A newCardWidgetsSyncTestpins its hash and checks the gate.css/card-widgets.cssis now byte-identical (sha2565bbeaf771e39623c5091d79aae99c5e1363648b6534b5bf8c9b79449b6d913d3) to Cacti core'sinclude/css/card-widgets.cssin 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 corelib/html.php.--cc-pctcustom 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>card_donut()andcard_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.