From 2f9ad7d52cd9c223ad880aa2f15c08c749332f1b Mon Sep 17 00:00:00 2001 From: bach Date: Fri, 4 Sep 2026 23:30:40 +0200 Subject: [PATCH] Rebuild /dashboard with charts, add Grand livre/Dashboard nav MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Nav: a small "Grand livre" / "Dashboard" switcher, top-right on both pages, with the current page highlighted. Needed hook_theme() to declare current_route as an accepted variable for both theme hooks -- same class of bug as the earlier can_view_history fix: an undeclared variable passed via the render array is silently dropped rather than reaching Twig. Dashboard: replaced the old "solde par compte / par client" tables (computed client-side from a full unwindowed JSON:API fetch of every node -- the same performance problem the /lignes sliding window was built to avoid, just not yet felt at 1500+ lines) with a single aggregate endpoint (DashboardStatsController, plain SQL GROUP BY) and five chart panels: CA par année, solde par compte (diverging, red/green), solde par compte trend (small multiples per compte), répartition par type, top clients par CA. No charting library -- small dependency-free div/CSS bar charts (HBarChart/ColumnChart/ MiniTrend components in dashboard.js), consistent with this project vendoring its own JS. Two data-correctness fixes along the way: (1) the historical stray mistyped dates (0213-06-15, 2015-08-29 -- preserved as-is per this module's policy) needed excluding from per-year buckets without excluding their money from all-time totals, so the filtering happens per-output-field in PHP rather than as a blanket SQL date range. (2) PHP silently casts numeric-looking array keys ("2021") to actual integers, so array_keys() on a year-keyed map produces a mix of ints and strings -- json_encode emits the int ones as bare JSON numbers in a list (unlike object keys, which JSON always stringifies), which broke the frontend's annees[i].slice(2) trend-card labels. Fixed with an explicit array_map('strval', ...). Verified: bar widths/colors match the underlying data exactly (e.g. EXT.'s red bar is proportionally sized against Maud's green one per their actual solde ratio), all 8 trend cards render correct year labels, and both nav links correctly highlight on their own page. --- .../figli_compta_ledger/css/admin-chrome.css | 39 +++ .../figli_compta_ledger/css/dashboard.css | 240 +++++++++++++--- .../figli_compta_ledger.module | 4 +- .../figli_compta_ledger.routing.yml | 7 + .../figli_compta_ledger/js/dashboard.js | 270 +++++++++++++----- .../src/Controller/DashboardController.php | 5 +- .../Controller/DashboardStatsController.php | 154 ++++++++++ .../figli-compta-dashboard.html.twig | 75 +++-- .../templates/figli-compta-home.html.twig | 4 + 9 files changed, 659 insertions(+), 139 deletions(-) create mode 100644 web/modules/custom/figli_compta_ledger/src/Controller/DashboardStatsController.php diff --git a/web/modules/custom/figli_compta_ledger/css/admin-chrome.css b/web/modules/custom/figli_compta_ledger/css/admin-chrome.css index e95888b..cd93155 100644 --- a/web/modules/custom/figli_compta_ledger/css/admin-chrome.css +++ b/web/modules/custom/figli_compta_ledger/css/admin-chrome.css @@ -13,6 +13,45 @@ margin-block-start: 0 !important; } +/* Grand livre / Dashboard switcher, top-right of both pages. Only present + on those two custom routes, but attached here (already loaded on every + page for the phantom-top-bar fix above) rather than duplicated between + home.css and dashboard.css -- and defined with its own explicit colors + rather than relying on either page's #figli-*-app-scoped custom + properties, since this