feat(workflow): example stats page with embedded Chart.js, inline form validation errors

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-24 01:59:27 +02:00
co-authored by Claude Sonnet 5.5
parent 16a0bb0de4
commit 00af65613d
36 changed files with 1274 additions and 138 deletions
+86 -14
View File
@@ -21,6 +21,7 @@ const char kBase[] = R"BASE(<!DOCTYPE html>
<a href="/">Index</a>
<a href="/templates/page">Templates</a>
<a href="/forms/contact">Forms</a>
<a href="/stats">Stats</a>
<a href="/docs">Docs</a>
<a href="/health">Health</a>
</nav>
@@ -30,6 +31,7 @@ const char kBase[] = R"BASE(<!DOCTYPE html>
<a href="/">Index</a>
<a href="/templates/page">Templates</a>
<a href="/forms/contact">Forms</a>
<a href="/stats">Stats</a>
<a href="/docs">Docs</a>
<a href="/health">Health</a>
</nav>
@@ -78,24 +80,93 @@ const char kPage[] = R"PAGE({% extends "base.html" %}
{% endblock %}
)PAGE";
const char kContact[] = R"CONTACT({% extends "base.html" %}
const char kFormPage[] = R"FORM({% extends "base.html" %}
{% block content %}
<h1>Contact</h1>
{% if posted %}
<p class="ok">Thanks {{ name }}, message received.</p>
<h1>{{ title }}</h1>
{% if notice %}<p class="ok" role="status">{{ notice }}</p>{% endif %}
{% if error_count %}
<div class="form-errors" role="alert">
<h2>Please fix {{ error_count }} field(s) and send again</h2>
<ul>
{% for e in errors %}
<li><a href="#f-{{ e.name }}">{{ e.label }}</a> {{ e.message }}</li>
{% endfor %}
</ul>
</div>
{% endif %}
{% if done %}{% else %}
<form method="post" action="{{ action }}" novalidate>
{% for f in fields %}
<div class="field{% if f.invalid %} invalid{% endif %}">
<label for="f-{{ f.name }}">{{ f.label }}</label>
{% if f.textarea %}
<textarea id="f-{{ f.name }}" name="{{ f.name }}"{% if f.invalid %} aria-invalid="true" aria-describedby="e-{{ f.name }}"{% endif %}>{{ f.value }}</textarea>
{% else %}
<form method="post" action="/forms/contact">
<label>Name <input name="name" value="{{ name }}"></label>
<label>Email <input name="email" value="{{ email }}"></label>
<label>Message <textarea name="message">{{ message }}</textarea></label>
<button type="submit">Send</button>
<input id="f-{{ f.name }}" type="{{ f.type }}" name="{{ f.name }}" value="{{ f.value }}"{% if f.invalid %} aria-invalid="true" aria-describedby="e-{{ f.name }}"{% endif %}>
{% endif %}
{% if f.hint %}<span class="hint">{{ f.hint }}</span>{% endif %}
{% if f.error %}<p class="field-error" id="e-{{ f.name }}">{{ f.error }}</p>{% endif %}
</div>
{% endfor %}
<button type="submit">{{ submit }}</button>
</form>
{% endif %}
{% if error %}
<p class="error">{{ error }}</p>
{% endif %}
{% endblock %}
)CONTACT";
)FORM";
const char kStats[] = R"STATS({% extends "base.html" %}
{% block content %}
<h1>Statistics</h1>
<p class="hint">HTTP requests, connections, and service state of this running
server. History is 15 minutes in 10 second buckets. The server stops accepting
after its connection cap, so auto refresh is off by default.</p>
<div class="toolbar">
<button type="button" id="refresh">Refresh</button>
<label class="inline"><input type="checkbox" id="auto"> Auto refresh (5 s)</label>
<span class="hint" id="t-updated">loading...</span>
</div>
<section class="tiles" aria-label="Summary">
<div class="tile"><span class="k">Uptime</span><span class="v" id="t-uptime">-</span></div>
<div class="tile"><span class="k">Requests</span><span class="v" id="t-requests">-</span></div>
<div class="tile"><span class="k">Errors</span><span class="v" id="t-errors">-</span></div>
<div class="tile"><span class="k">Avg latency</span><span class="v" id="t-avg">-</span></div>
<div class="tile"><span class="k">p95 latency</span><span class="v" id="t-p95">-</span></div>
<div class="tile"><span class="k">p99 latency</span><span class="v" id="t-p99">-</span></div>
<div class="tile"><span class="k">Bytes in</span><span class="v" id="t-in">-</span></div>
<div class="tile"><span class="k">Bytes out</span><span class="v" id="t-out">-</span></div>
<div class="tile"><span class="k">Connections</span><span class="v" id="t-conn">-</span></div>
<div class="tile"><span class="k">Active</span><span class="v" id="t-active">-</span></div>
<div class="tile"><span class="k">Timeouts / malformed</span><span class="v" id="t-timeouts">-</span></div>
<div class="tile"><span class="k">Connections left (cap)</span><span class="v" id="t-left">-</span></div>
</section>
<h2>Traffic</h2>
<div class="grid">
<figure class="chart"><figcaption>Requests and errors per 10 s</figcaption><div class="plot"><canvas id="c-requests"></canvas></div></figure>
<figure class="chart"><figcaption>Average latency per 10 s</figcaption><div class="plot"><canvas id="c-latency"></canvas></div></figure>
<figure class="chart"><figcaption>Bytes in and out per 10 s</figcaption><div class="plot"><canvas id="c-bytes"></canvas></div></figure>
<figure class="chart"><figcaption>Connections opened per 10 s</figcaption><div class="plot"><canvas id="c-conns"></canvas></div></figure>
</div>
<h2>Requests</h2>
<div class="grid">
<figure class="chart"><figcaption>Status codes</figcaption><div class="plot"><canvas id="c-status"></canvas></div></figure>
<figure class="chart"><figcaption>Methods</figcaption><div class="plot"><canvas id="c-methods"></canvas></div></figure>
<figure class="chart"><figcaption>Latency distribution</figcaption><div class="plot"><canvas id="c-hist"></canvas></div></figure>
<figure class="chart"><figcaption>Top routes</figcaption><div class="plot"><canvas id="c-routes"></canvas></div></figure>
</div>
<div class="scroll"><table id="tbl-routes"></table></div>
<h2>Services</h2>
<div class="grid">
<figure class="chart"><figcaption>Store sizes</figcaption><div class="plot tall"><canvas id="c-stores"></canvas></div></figure>
<figure class="chart"><figcaption>Cache hits and misses</figcaption><div class="plot"><canvas id="c-cache"></canvas></div></figure>
<figure class="chart"><figcaption>Tasks by state</figcaption><div class="plot"><canvas id="c-tasks"></canvas></div></figure>
<figure class="chart"><figcaption>ORM tables and rows</figcaption><div class="plot"><canvas id="c-orm"></canvas></div></figure>
</div>
<div class="scroll"><table id="tbl-workers"></table></div>
<div class="scroll"><table id="tbl-metrics"></table></div>
<script src="/embedded/chart.umd.min.js"></script>
<script src="/embedded/stats.js"></script>
{% endblock %}
)STATS";
const char kDocs[] = R"DOCS({% extends "base.html" %}
{% block content %}
@@ -125,8 +196,9 @@ void load_templates(Services& services) {
services.templates->add_template("base.html", kBase);
services.templates->add_template("index.html", kIndex);
services.templates->add_template("page.html", kPage);
services.templates->add_template("contact.html", kContact);
services.templates->add_template("form_page.html", kFormPage);
services.templates->add_template("docs.html", kDocs);
services.templates->add_template("stats.html", kStats);
services.templates->add_template("error.html", kError);
services.templates->add_template("nav_hint.html", kNavHint);
services.templates->add_global("site", "MoloApp living example");