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().
这个提交包含在:
Valentin V. Bartenev
2026-05-31 02:56:37 +03:00
父节点 9c8f884f11
当前提交 7804546434
+11 -9
查看文件
@@ -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 `<section class="hud-card">
@@ -1642,15 +1649,10 @@ const char kWebPanelAppHtml[] PROGMEM = R"HTML(
<div class="events-empty">No recent events</div>
</section>`;
}
const rows = events.map((event) => {
const label = event.type === "boot" && event.value != null
? `boot (${bootReasonLabel(event.value)})`
: (event.type || "event");
return `<tr>
<td>${escapeHtml(label)}</td>
<td>${escapeHtml(formatDuration(event.t || 0))}</td>
</tr>`;
}).join("");
const rows = events.map((event) => `<tr>
<td>${escapeHtml(eventLabel(event))}</td>
<td>${escapeHtml(formatDuration(event.t || 0))}</td>
</tr>`).join("");
return `<section class="hud-card">
<h3>Events</h3>
<div class="events-table-wrap">