From 7804546434b7d30d5483062fbd80092bc82c8bb3 Mon Sep 17 00:00:00 2001 From: "Valentin V. Bartenev" Date: Sun, 31 May 2026 02:56:37 +0300 Subject: [PATCH] Web: add eventLabel helper and show low_memory free heap in events panel Extract eventLabel(event) to centralize per-event label formatting in the web panel events history. The helper replaces the inline ternary that was previously inlined in renderEventsSection(). Add a low_memory case to eventLabel: when a low_memory event carries a non-null value (free heap in KB at the time of the event), the label is rendered as "low memory (N KB)". The value is already emitted by appendJsonEvents and stored as free_heap/1024 by recordStatsEvent(). The boot case is unchanged: boot events with a non-null value continue to display the reset reason string via bootReasonLabel(). renderEventsSection() is simplified back to a plain template literal now that label construction is delegated to eventLabel(). --- src/helpers/web/WebPanelServer.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/helpers/web/WebPanelServer.cpp b/src/helpers/web/WebPanelServer.cpp index b0b5085d..3d4a6625 100644 --- a/src/helpers/web/WebPanelServer.cpp +++ b/src/helpers/web/WebPanelServer.cpp @@ -1635,6 +1635,13 @@ const char kWebPanelAppHtml[] PROGMEM = R"HTML( }; return ESP_RESET_REASONS[value] || ("reason " + value); } + function eventLabel(event) { + if (event.type === "boot" && event.value != null) + return `boot (${bootReasonLabel(event.value)})`; + if (event.type === "low_memory" && event.value != null) + return `low memory (${event.value} KB)`; + return event.type || "event"; + } function renderEventsSection(events) { if (!Array.isArray(events) || !events.length) { return `
@@ -1642,15 +1649,10 @@ const char kWebPanelAppHtml[] PROGMEM = R"HTML(
No recent events
`; } - const rows = events.map((event) => { - const label = event.type === "boot" && event.value != null - ? `boot (${bootReasonLabel(event.value)})` - : (event.type || "event"); - return ` - ${escapeHtml(label)} - ${escapeHtml(formatDuration(event.t || 0))} - `; - }).join(""); + const rows = events.map((event) => ` + ${escapeHtml(eventLabel(event))} + ${escapeHtml(formatDuration(event.t || 0))} + `).join(""); return `

Events