[web] The web UI: hosts, add/edit with apply progress, undo, history and restore, share links, engine switch, certificates and device installs, signing by hand, settings and tokens; smoke test counts every §4 flow's clicks

This commit is contained in:
2026-11-07 23:44:27 +01:00
parent aed5fbfcff
commit 3e326e85a0
47 changed files with 7868 additions and 3 deletions
@@ -0,0 +1,80 @@
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at https://mozilla.org/MPL/2.0/. -->
<script lang="ts">
// Handoff §7.1: the apply checklist, its countdown and the queued state.
import { Button, Icon, Progress } from "@ianitor/ui";
import type { ApplyView } from "../lib/types";
import { app, secondsLeft } from "../lib/app.svelte";
let { apply, oncancel }: { apply: ApplyView; oncancel?: () => void } = $props();
const engine = $derived(app.overview?.engine.running === "caddy" ? "Caddy" : "Pingora");
const watchSeconds = $derived(app.overview?.site?.watch_seconds ?? 60);
const left = $derived(apply.watch ? secondsLeft(apply.watch.ends_at) : watchSeconds);
const st = (k: string) => apply.steps.find((s) => s.key === k)?.state ?? "pending";
const merged = (a: string, b: string) => {
const x = st(a);
const y = st(b);
if (x === "failed" || y === "failed") return "failed";
if (x === "running" || y === "running") return "running";
if (x === "done" && (y === "done" || y === "skipped")) return "done";
return x;
};
const noWatch = $derived(apply.reason?.code === "apply.kept.no_watch");
const rows = $derived([
{ s: st("validate"), t: { pending: "Check the host file", running: "Checking the host file", done: "Checked the host file", failed: "The host file did not pass the check", skipped: "Check the host file" } },
{ s: merged("compile", "write"), t: { pending: "Build the Pingora and Caddy settings", running: "Building the Pingora and Caddy settings", done: "Built the Pingora and Caddy settings", failed: "Could not build the settings", skipped: "Build the Pingora and Caddy settings" } },
{ s: st("reload"), t: { pending: `Reload ${engine}`, running: `Reloading ${engine}`, done: `Reloaded ${engine}, no connections dropped`, failed: `${engine} did not take the new settings`, skipped: `Reload ${engine}` } },
{
s: st("watch"),
t: noWatch
? { pending: "Check that it answers", running: `Checking that it answers: ${left} s left`, done: "It answers", failed: "Health checks failed", skipped: "Nothing to watch: the host is removed." }
: { pending: `Watch health checks for ${watchSeconds} s`, running: `Watching health checks: ${left} s left`, done: `Health checks passed for ${watchSeconds} s`, failed: "Health checks failed", skipped: "Nothing to watch: the host is removed." },
},
]);
const prefix: Record<string, string> = { done: "Done:", running: "Now:", pending: "Next:", failed: "Failed:", skipped: "Skipped:" };
const final = $derived(["kept", "reverted", "failed", "needs_attention"].includes(apply.state));
</script>
{#if apply.state === "queued"}
<p class="ia-status" data-s="running">
<Icon name="clock" />
<span>
Waiting for "{apply.queue?.waiting_for?.summary ?? "another change"}" to finish{apply.queue?.waiting_for?.seconds_left != null
? `, about ${apply.queue.waiting_for.seconds_left} s`
: ""}.
{#if (apply.queue?.position ?? 1) > 1}{(apply.queue?.position ?? 1) - 1} other changes are ahead of this one.{/if}
</span>
</p>
{#if oncancel}<div><Button onclick={oncancel}>Cancel</Button></div>{/if}
{:else}
<ol class="steps">
{#each rows as r, i (i)}
<li class={r.s}>
{#if r.s === "done"}<Icon name="check" />{:else if r.s === "running"}<Icon name="clock" />{:else if r.s === "failed"}<Icon name="ring" />{:else}<span class="hollow" aria-hidden="true"></span>{/if}
<span><span class="sr-only">{prefix[r.s]}</span>{r.t[r.s as keyof typeof r.t]}</span>
</li>
{/each}
{#if st("watch") === "failed" && !final}
<li class="running"><Icon name="clock" /><span><span class="sr-only">Now:</span>Undoing the change</span></li>
{/if}
</ol>
{#if apply.state === "watching"}
<Progress label="Health watch" max={watchSeconds} now={watchSeconds - left} text="{left} seconds left" />
<p class="ia-hint">You can leave this screen. Other changes wait their turn; only one apply runs at a time.</p>
{/if}
{/if}
<style>
.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.steps li { display: flex; gap: 10px; align-items: center; }
.steps li.pending { color: var(--muted); }
.steps li.running { color: var(--text); }
.steps li.running :global(svg) { color: var(--accent); }
.steps li.done { color: var(--text-2); }
.steps li.done :global(svg) { color: var(--kept); }
.steps li.failed :global(svg) { color: var(--down); }
.steps li.skipped { color: var(--muted); }
.hollow { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--muted); margin: 2px; }
</style>