[web] Design review: last row's menu not clipped, Hostname focused after loading, popover closes on Esc and outside click, phone engine chip in the top bar, paused and needs-attention copy with Restore in the panel, change bar offers and countdown, focus after share and kept, fingerprint check when signing by hand, draft kept through sign-in
This commit is contained in:
@@ -4,10 +4,10 @@
|
||||
<script lang="ts">
|
||||
// Handoff §7.4 and §7.5: the last-change bar with Undo (1 click), and the reverted / not
|
||||
// applied banner that stands in for its first line.
|
||||
import { Banner, Button, Icon, Progress } from "@ianitor/ui";
|
||||
import { Banner, Button, Details, Icon, Progress } from "@ianitor/ui";
|
||||
import { ApiError, call, del, newKey, post, sentence } from "../lib/api";
|
||||
import { app, refresh, secondsLeft, toast } from "../lib/app.svelte";
|
||||
import { firstSentence, when } from "../lib/format";
|
||||
import { atTime, firstSentence, when } from "../lib/format";
|
||||
import type { ApplyView } from "../lib/types";
|
||||
|
||||
let { onshowsteps, onedit }: { onshowsteps: (id: string) => void; onedit: (a: ApplyView, field?: string) => void } = $props();
|
||||
@@ -21,7 +21,7 @@
|
||||
let pushing = $state(false);
|
||||
const dismissKey = $derived(last ? `apply:${last.id}` : "");
|
||||
|
||||
function runningHeading(summary: string, a: ApplyView | null): string {
|
||||
function runningHeading(summary: string, a: { kind: string; hosts: string[]; summary: string } | null): string {
|
||||
if (!a) return summary;
|
||||
const h = a.hosts[0] ?? "";
|
||||
switch (a.kind) {
|
||||
@@ -29,6 +29,8 @@
|
||||
case "remove": return `Removing ${h}`;
|
||||
case "edit": return `Changing ${h}`;
|
||||
case "share_links": return `Turning on share links for ${h}`;
|
||||
case "undo": return `Undoing: ${a.summary.replace(/^Undid: /, "")}`;
|
||||
case "restore": return a.summary.replace(/^Restored /, "Restoring ");
|
||||
default: return summary;
|
||||
}
|
||||
}
|
||||
@@ -85,7 +87,29 @@
|
||||
});
|
||||
const pushFailed = $derived(last?.state === "kept" && last.push?.state === "failed");
|
||||
const undoReason = $derived(undo?.blocked && undo.blocked.code !== "undo.nothing" ? undo.blocked.message : null);
|
||||
const watchLeft = $derived(last?.watch ? secondsLeft(last.watch.ends_at) : null);
|
||||
// Ticks every second on the local clock (§7.2), not only on the 5 s poll.
|
||||
const watchLeft = $derived(
|
||||
active?.watch_ends_at ? secondsLeft(active.watch_ends_at) : active?.seconds_left != null ? active.seconds_left : null,
|
||||
);
|
||||
// The outcome's offer, by code (§7.5).
|
||||
const offer = $derived.by(() => {
|
||||
const c = last?.reason?.code ?? "";
|
||||
if (/^apply\.reverted\.(not_found|redirect|sign_in)$/.test(c)) return { label: "Edit health check", field: "health_check.path" };
|
||||
if (/^apply\.(interrupted|reverted\.edge_lost|interrupted\.queued)$/.test(c)) return { label: "Try again", field: last?.reason?.field ?? undefined };
|
||||
if (/^apply\.failed\.(reload|build|edge_unreachable)$/.test(c)) return null;
|
||||
if (last?.attempted_host) return { label: "Edit and try again", field: last?.reason?.field ?? undefined };
|
||||
return null;
|
||||
});
|
||||
const pushLine = $derived.by(() => {
|
||||
const p = last?.push;
|
||||
const remote = "Gitea";
|
||||
switch (p?.error_code) {
|
||||
case "push.failed.rejected": return `Kept, but ${remote} has changes Ianitor does not have, so nothing was sent. Nothing is lost on this server.`;
|
||||
case "push.failed.auth": return `Kept, but ${remote} refused Ianitor's access key. Check the key in Custos.`;
|
||||
default: return `Kept, but not yet saved to ${remote}: ${remote} did not answer.${p?.next_try_at ? ` Ianitor tries again ${atTime(p.next_try_at, app.now)}.` : " Ianitor tries again by itself."}`;
|
||||
}
|
||||
});
|
||||
const canPushNow = $derived(pushFailed && last?.push?.error_code !== "push.failed.rejected");
|
||||
</script>
|
||||
|
||||
{#if last && (last.state === "reverted" || last.state === "failed") && !app.dismissed.includes(dismissKey)}
|
||||
@@ -93,8 +117,9 @@
|
||||
<Banner tone="notice" ondismiss={() => (app.dismissed = [...app.dismissed, dismissKey])}>
|
||||
{#snippet title()}<span class="ia-status" data-s="reverted"><Icon name="undo" /><span class="word">{last.state === "failed" ? "not applied" : "reverted"}</span></span> <strong>{parts[0]}</strong>{/snippet}
|
||||
{#if parts[1]}Reason: {parts[1]}{/if}
|
||||
{#if last.reason?.detail && last.reason.code.startsWith("apply.failed.")}<Details detail={last.reason.detail} />{/if}
|
||||
{#snippet actions()}
|
||||
{#if last.attempted_host}<Button variant="outline" onclick={() => onedit(last, last.reason?.field ?? undefined)}>Edit and try again</Button>{/if}
|
||||
{#if offer}<Button variant="outline" onclick={() => onedit(last, offer?.field)}>{offer.label}</Button>{/if}
|
||||
{/snippet}
|
||||
</Banner>
|
||||
{/if}
|
||||
@@ -104,8 +129,8 @@
|
||||
{#if active}
|
||||
<div class="grow">
|
||||
<div class="ia-status" data-s="running"><Icon name="clock" /><span class="word">{active.state === "queued" ? "waiting" : active.state === "watching" ? "watching" : "applying"}</span>
|
||||
<span>{runningHeading(active.summary, last && last.id === active.id ? last : null)}</span></div>
|
||||
<div class="ia-sub">{active.state === "queued" ? "Waiting for another change to finish" : `${watchLeft ?? active.seconds_left ?? 0} s left`}</div>
|
||||
<span>{runningHeading(active.summary, active.kind ? active : null)}</span></div>
|
||||
<div class="ia-sub">{active.state === "queued" ? "Waiting for another change to finish" : active.state === "watching" ? `${watchLeft ?? 0} s left` : "Checking and loading the change"}</div>
|
||||
{#if active.state === "watching" && watchLeft != null}
|
||||
{@const total = o?.site?.watch_seconds ?? 60}
|
||||
<Progress label="Health watch" max={total} now={total - watchLeft} text="{watchLeft} seconds left" />
|
||||
@@ -116,7 +141,7 @@
|
||||
<div class="grow">
|
||||
{#if last.state === "kept"}
|
||||
<div><span class="ia-status" data-s="kept"><Icon name="check" /><span class="word">kept</span></span> {last.summary}</div>
|
||||
<div class="ia-sub" class:warn={pushFailed}>{pushFailed ? "Kept, but not yet saved to Gitea. Ianitor tries again by itself." : keptLine}</div>
|
||||
<div class="ia-sub" class:warn={pushFailed}>{pushFailed ? pushLine : keptLine}</div>
|
||||
{:else if undo?.target}
|
||||
<div>Undo: {undo.target.summary}</div>
|
||||
{/if}
|
||||
@@ -125,7 +150,7 @@
|
||||
{#if undoReason}<div class="ia-sub" id="undo-reason">{undoReason}</div>{/if}
|
||||
{#if !undo?.target}<div class="ia-sub">Nothing to undo yet.</div>{/if}
|
||||
</div>
|
||||
{#if pushFailed}<Button onclick={pushNow} pending={pushing}>Try now</Button>{/if}
|
||||
{#if canPushNow}<Button onclick={pushNow} pending={pushing}>Try now</Button>{/if}
|
||||
{#if undo?.target}
|
||||
<Button icon="undo" onclick={doUndo} pending={undoing} disabled={!!undoReason || !undo.available}
|
||||
describedby={undoReason ? "undo-reason" : undefined}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<!-- 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 §2.4: the engine chip (click 1 of the switch). On the main screen's header on a
|
||||
// desktop, in the top bar on a phone (§2.16).
|
||||
import { Icon } from "@ianitor/ui";
|
||||
import { app } from "../lib/app.svelte";
|
||||
|
||||
const o = $derived(app.overview);
|
||||
const engineName = $derived(o?.engine.running === "caddy" ? "Caddy" : "Pingora");
|
||||
const engineLabel = $derived(
|
||||
o?.engine.state === "switching" ? "Engine: switching" : `Engine: ${engineName}${o?.engine.state === "stopped" ? ", not answering" : ""}. Change engine`,
|
||||
);
|
||||
</script>
|
||||
|
||||
{#if o}
|
||||
<button type="button" class="ia-engine" data-engine-chip aria-haspopup="dialog" aria-expanded={app.panel?.kind === "engine"} aria-label={engineLabel}
|
||||
onclick={() => (app.panel = app.panel?.kind === "engine" ? null : { kind: "engine" })}>
|
||||
{#if o.engine.state === "switching"}<Icon name="clock" /> Engine Switching…{:else}
|
||||
<span class="ia-status" data-s={o.engine.state === "stopped" ? "down" : "healthy"}><span class="ia-dot"></span></span>
|
||||
<small class="desktop">Engine</small> {engineName}{#if o.engine.running === "caddy"} <small>(fallback)</small>{/if}{/if}
|
||||
<Icon name="chevron" />
|
||||
</button>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
@media (max-width: 719.98px) { .desktop { display: none; } }
|
||||
</style>
|
||||
@@ -4,11 +4,11 @@
|
||||
<script lang="ts">
|
||||
// Handoff §9: the engine popover. Click 1 is the chip, click 2 "Switch to Caddy" (the popover
|
||||
// is the confirmation). The switch runs in control; this polls GET /engine until it ends.
|
||||
import { onDestroy } from "svelte";
|
||||
import { Banner, Button, Dialog, Icon, Progress } from "@ianitor/ui";
|
||||
import { onDestroy, onMount } from "svelte";
|
||||
import { Banner, Button, Details, Dialog, Icon, Progress } from "@ianitor/ui";
|
||||
import { call, get, newKey, sentence } from "../lib/api";
|
||||
import { app, refresh } from "../lib/app.svelte";
|
||||
import { when } from "../lib/format";
|
||||
import { whenInline } from "../lib/format";
|
||||
import type { EngineView } from "../lib/types";
|
||||
|
||||
let { onclose }: { onclose: () => void } = $props();
|
||||
@@ -23,7 +23,17 @@
|
||||
let timer: ReturnType<typeof setTimeout> | undefined;
|
||||
onDestroy(() => clearTimeout(timer));
|
||||
|
||||
const activeLinks = $derived(app.overview?.hosts.filter((h) => h.share_links).length ?? 0);
|
||||
let activeLinks = $state(0);
|
||||
onMount(async () => {
|
||||
try {
|
||||
const l = await get<{ items: { state: string }[] }>("/share-links", { quiet: true });
|
||||
activeLinks = l.items.filter((x) => x.state === "active").length;
|
||||
} catch {
|
||||
/* the count is only a hint */
|
||||
}
|
||||
});
|
||||
const fr = $derived(e?.fallback_ready ?? null);
|
||||
const differs = $derived(fr ? fr.compared - fr.matched : 0);
|
||||
const notReady = $derived(running === "pingora" && !e?.fallback_ready?.built_at);
|
||||
const disabledReason = $derived(!e?.switchable ? "This server does not let Ianitor switch engines." : notReady ? "Caddy is not ready: its settings have not been built yet." : null);
|
||||
|
||||
@@ -62,17 +72,21 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<Dialog title="Serving with {name}" kind="popover" modal={false} {onclose}>
|
||||
<Dialog title={e?.state === "stopped" ? `${name} is not answering` : `Serving with ${name}`} kind="popover" modal={false} escape={!switching} {onclose}>
|
||||
<p class="ia-label">Engine</p>
|
||||
{#if e?.state === "stopped"}
|
||||
<p><strong>{name} is not answering.</strong> Visitors may not reach any host. Switching to {other} is the quickest way back.</p>
|
||||
<p>Visitors may not reach any host. Switching to {other} is the quickest way back.</p>
|
||||
{:else}
|
||||
<p class="ia-text2">
|
||||
{#if e?.since}Since {when(e.since, app.now)}. {/if}
|
||||
{#if e?.since}Since {whenInline(e.since, app.now)}. {/if}
|
||||
{#if running === "pingora"}
|
||||
{#if notReady}Caddy is not ready: its settings have not been built yet.{:else}Caddy is ready with the same routes: built {when(e?.fallback_ready?.built_at, app.now)}{e?.fallback_ready?.current ? "" : " (it is rebuilt from the current routes when you switch)"}.{/if}
|
||||
{#if notReady}Caddy is not ready: its settings have not been built yet.{:else if differs > 0}Caddy is built with the same routes {whenInline(fr?.built_at, app.now)}, but {differs} of {fr?.compared} hosts behave differently on it.{:else}Caddy is ready with the same routes: built {whenInline(fr?.built_at, app.now)}{fr?.compared ? `, and all ${fr.compared} hosts behave the same` : ""}.{/if}
|
||||
{#if !notReady && !fr?.current} It is rebuilt from the current routes when you switch.{/if}
|
||||
{:else}Pingora is ready with the same routes.{/if}
|
||||
</p>
|
||||
{#if running === "pingora" && !notReady && fr?.differences.length}
|
||||
<Details detail={fr.differences.join("\n")} />
|
||||
{/if}
|
||||
{/if}
|
||||
<div class="ia-card">
|
||||
<p><strong>What happens</strong></p>
|
||||
@@ -81,10 +95,10 @@
|
||||
<li>Open connections close; videos and uploads in progress restart.</li>
|
||||
<li>Hosts and certificates stay the same.</li>
|
||||
{#if running === "pingora"}
|
||||
<li>Share links stop working while Caddy serves: visitors with a link get the normal sign-in. They work again when you switch back.{#if activeLinks} Hosts with share links: {activeLinks}.{/if}</li>
|
||||
<li>Changes wait while Caddy serves; switch back to make them.</li>
|
||||
<li>Share links stop working while Caddy serves: visitors with a link get the normal sign-in. They work again when you switch back.{#if activeLinks}{" "}{activeLinks === 1 ? "1 share link is" : `${activeLinks} share links are`} active.{/if}</li>
|
||||
<li>Changes keep working: Ianitor tries each one on Caddy and undoes it if a host stops answering.</li>
|
||||
{:else}
|
||||
<li>Share links work again, and changes can be made again.</li>
|
||||
<li>Share links work again.</li>
|
||||
{/if}
|
||||
<li>This page may lose contact for a few seconds.</li>
|
||||
</ul>
|
||||
|
||||
@@ -111,7 +111,7 @@
|
||||
<span class="ia-sub phone">{w}{phoneDetail(h) ? ` · ${phoneDetail(h)}` : ""}</span>
|
||||
</span>
|
||||
<span role="cell" class="desktop">
|
||||
<span>{h.upstreams[0] ?? ""}</span>{#if h.upstreams.length > 1} <span class="ia-muted">+{h.upstreams.length - 1} more</span>{/if}
|
||||
<span>{h.upstreams[0] ?? ""}</span>{#if h.upstreams.length > 1}{" "}<span class="ia-muted">+{h.upstreams.length - 1} more</span>{/if}
|
||||
<span class="ia-sub" class:problem={s.problem} style="display:block">{running.includes(h.hostname) ? "Changing now · " : ""}{s.text}</span>
|
||||
{#if h.certificate.state === "pending"}<span class="ia-sub" style="display:block">Waiting for Let's Encrypt to issue the certificate.</span>{/if}
|
||||
{#if h.certificate.state === "failed"}
|
||||
|
||||
@@ -52,7 +52,9 @@
|
||||
|
||||
function pick(it: Item) {
|
||||
if (it.reason) return;
|
||||
close(false);
|
||||
// Focus back on More first: a dialog the item opens returns focus there when it closes
|
||||
// (§2.9), not to a menu item that no longer exists.
|
||||
close(true);
|
||||
it.run();
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
import { Banner, Button, Details, Dialog, Icon, Segmented } from "@ianitor/ui";
|
||||
import ApplyProgress from "./ApplyProgress.svelte";
|
||||
import { ApiError, call, del, get, newKey, sentence } from "../lib/api";
|
||||
import { app, changesBlocked, refresh, toast } from "../lib/app.svelte";
|
||||
import { app, changesBlocked, refresh, restoreLastKept, toast } from "../lib/app.svelte";
|
||||
import { FINAL, follow } from "../lib/applies";
|
||||
import { firstSentence } from "../lib/format";
|
||||
import type { ApplyView, ErrorBody, HeaderRule, HostSpec } from "../lib/types";
|
||||
@@ -62,6 +62,8 @@
|
||||
|
||||
// ---- the apply
|
||||
let apply = $state<ApplyView | null>(null);
|
||||
let restoring = $state(false);
|
||||
let restoreProblem = $state<string | null>(null);
|
||||
let phase = $state<"form" | "progress">("form");
|
||||
let stop: (() => void) | undefined;
|
||||
let closeTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
@@ -128,16 +130,43 @@
|
||||
rev = app.overview?.rev ?? null;
|
||||
if (!signinOk) host.auth = "none";
|
||||
}
|
||||
loading = false;
|
||||
if (focusField) {
|
||||
if (focusField.startsWith("health_check")) more = true;
|
||||
setTimeout(() => document.getElementById(fieldId(focusField))?.focus(), 0);
|
||||
// A form saved before this tab went to sign in comes back (App.svelte, signIn).
|
||||
try {
|
||||
const raw = sessionStorage.getItem(DRAFT);
|
||||
const d = raw ? (JSON.parse(raw) as { hostname: string; host: typeof host }) : null;
|
||||
if (d && d.hostname === (hostname ?? "") && !resume) {
|
||||
Object.assign(host, d.host);
|
||||
more = more || d.host.hc || d.host.req.length > 0 || d.host.resp.length > 0;
|
||||
}
|
||||
sessionStorage.removeItem(DRAFT);
|
||||
} catch {
|
||||
/* no storage: nothing to bring back */
|
||||
}
|
||||
loading = false;
|
||||
if (phase === "form") {
|
||||
// The Dialog focused its heading while this said "Loading…": now the first field
|
||||
// (Hostname; Send traffic to when editing), so typing right after opening works.
|
||||
const f = focusField ?? (hostname ? "upstreams[0]" : "hostname");
|
||||
if (f.startsWith("health_check")) more = true;
|
||||
setTimeout(() => document.getElementById(fieldId(f))?.focus(), 0);
|
||||
}
|
||||
window.addEventListener("ianitor:save-draft", saveDraft);
|
||||
});
|
||||
|
||||
const DRAFT = "ianitor-draft";
|
||||
function saveDraft() {
|
||||
if (phase !== "form") return;
|
||||
try {
|
||||
sessionStorage.setItem(DRAFT, JSON.stringify({ hostname: hostname ?? "", host: $state.snapshot(host) }));
|
||||
} catch {
|
||||
/* no storage */
|
||||
}
|
||||
}
|
||||
|
||||
onDestroy(() => {
|
||||
stop?.();
|
||||
clearTimeout(closeTimer);
|
||||
if (typeof window !== "undefined") window.removeEventListener("ianitor:save-draft", saveDraft);
|
||||
});
|
||||
|
||||
function fieldId(f: string): string {
|
||||
@@ -226,6 +255,7 @@
|
||||
function onApply(a: ApplyView) {
|
||||
apply = a;
|
||||
if (a.state === "kept") {
|
||||
if (a.kind !== "remove") app.focusHost = a.hosts[0] ?? null;
|
||||
closeTimer = setTimeout(() => onclose(), 1500);
|
||||
}
|
||||
}
|
||||
@@ -291,6 +321,10 @@
|
||||
return `Removing ${h}`;
|
||||
case "share_links":
|
||||
return `Turning on share links for ${h}`;
|
||||
case "undo":
|
||||
return `Undoing: ${apply.summary.replace(/^Undid: /, "")}`;
|
||||
case "restore":
|
||||
return apply.summary.replace(/^Restored /, "Restoring ");
|
||||
default:
|
||||
return `Changing ${h}`;
|
||||
}
|
||||
@@ -321,7 +355,7 @@
|
||||
{#if apply.state === "kept"}
|
||||
<Banner tone="kept">
|
||||
{#snippet title()}<span class="ia-status" data-s="kept"><span class="word">kept</span></span> <strong>{apply?.hosts[0] ?? name}</strong> {apply?.kind === "remove" ? "is removed." : "is live."}{/snippet}
|
||||
{apply.reason?.message ?? ""}{#if apply.commit_short} Saved as commit {apply.commit_short}{apply.push?.state === "pushed" ? " and pushed to Gitea" : ""}.{/if}
|
||||
{(apply.reason?.message ?? "").replace(/^\S+ is (live|removed)\.\s*/, "")}{#if apply.commit_short} Saved as commit {apply.commit_short}{apply.push?.state === "pushed" ? " and pushed to Gitea" : ""}.{/if}
|
||||
</Banner>
|
||||
{:else if apply.state === "reverted" || apply.state === "failed"}
|
||||
{@const parts = firstSentence(apply.reason?.message ?? "")}
|
||||
@@ -337,7 +371,12 @@
|
||||
{#if apply.reason?.detail}<Details detail={apply.reason.detail} />{/if}
|
||||
<p class="ia-hint">Your form is kept. History records the attempt as {apply.state === "failed" ? "not applied" : "reverted"}.</p>
|
||||
{:else if apply.state === "needs_attention"}
|
||||
<Banner tone="down" live="alert">{#snippet title()}<strong>Ianitor could not undo a failed change.</strong>{/snippet}{apply.reason?.message}</Banner>
|
||||
<Banner tone="down" live="alert">{#snippet title()}<strong>Ianitor could not undo a failed change.</strong>{/snippet}{apply.reason?.message}
|
||||
{#if restoreProblem}<p role="status">{restoreProblem}</p>{/if}
|
||||
{#snippet actions()}
|
||||
{#if app.overview?.undo?.target}<Button variant="primary" pending={restoring} onclick={async () => { restoring = true; restoreProblem = await restoreLastKept(); restoring = false; }}>Restore the last kept version</Button>{/if}
|
||||
{/snippet}
|
||||
</Banner>
|
||||
{/if}
|
||||
{:else}
|
||||
<form id="host-form" onsubmit={submit} novalidate>
|
||||
|
||||
@@ -46,8 +46,7 @@
|
||||
{@const r = i.renewal}
|
||||
<Banner tone="notice" label="Domi intermediate certificate">
|
||||
{#snippet title()}
|
||||
<span tabindex="-1">Sign the renewal on the offline computer. Check that it shows the same code:</span>
|
||||
<span class="code" aria-label="Match code {r.match_code}">{r.match_code}</span>
|
||||
<span tabindex="-1">Sign the renewal on the offline computer. Sign it by hand shows the files, the command and the fingerprint to check.</span>
|
||||
{/snippet}
|
||||
The request stays open for {duration(secondsLeft(r.expires_at))}. {#if problem}{problem}{/if}
|
||||
{#snippet actions()}
|
||||
@@ -58,12 +57,9 @@
|
||||
{:else if i?.banner}
|
||||
<Banner tone={i.state === "due" ? "notice" : "down"} label="Domi intermediate certificate">
|
||||
{#snippet title()}<strong>{i.banner?.message}</strong>{/snippet}
|
||||
{i.state === "missing" ? "Setting it up makes a request that the Domi root signs on the offline computer." : "Renewing makes a request that the Domi root signs; check the match code on both screens."}
|
||||
{i.state === "missing" ? "Setting it up makes a request that the Domi root signs on the offline computer." : "Renewing makes a request that the Domi root signs on the offline computer."}
|
||||
{#if problem} {problem}{/if}
|
||||
{#snippet actions()}<Button variant="outline" onclick={renew} {pending}>{i.state === "missing" ? "Set up" : "Renew"}</Button>{/snippet}
|
||||
</Banner>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.code { font-family: var(--font-inscription); font-size: 1.4rem; letter-spacing: 0.16em; color: var(--accent-strong); margin-left: 8px; }
|
||||
</style>
|
||||
|
||||
@@ -17,8 +17,9 @@
|
||||
|
||||
let { hostname, onclose }: { hostname: string; onclose: () => void } = $props();
|
||||
|
||||
const row = $derived(app.overview?.hosts.find((h) => h.hostname === hostname));
|
||||
let on = $state(false);
|
||||
// Known before the Dialog mounts, so its focus lands on Copy link (§2.9), not the title.
|
||||
// svelte-ignore state_referenced_locally
|
||||
let on = $state(!!app.overview?.hosts.find((h) => h.hostname === hostname)?.share_links);
|
||||
let link = $state<MintedLink | null>(null);
|
||||
let minting = $state(false);
|
||||
let copied = $state(false);
|
||||
@@ -33,10 +34,9 @@
|
||||
let usingPassword = $state(false);
|
||||
let turning = $state<ApplyView | null>(null);
|
||||
let stopFollow: (() => void) | undefined;
|
||||
let secretBox: HTMLInputElement | undefined = $state();
|
||||
let secretBox: HTMLTextAreaElement | undefined = $state();
|
||||
|
||||
onMount(() => {
|
||||
on = !!row?.share_links;
|
||||
if (on) void mint();
|
||||
});
|
||||
onDestroy(() => stopFollow?.());
|
||||
@@ -122,7 +122,7 @@
|
||||
{#if link?.warning}<p class="ia-hint">{link.warning.message}</p>{/if}
|
||||
{#if problem}<Banner tone="notice" live="status">{#snippet title()}{problem}{/snippet}</Banner>{/if}
|
||||
{#if link}
|
||||
<input bind:this={secretBox} class="ia-secret" readonly value={link.url} aria-label="Share link" onfocus={(e) => (e.currentTarget as HTMLInputElement).select()} />
|
||||
<textarea bind:this={secretBox} class="ia-secret" readonly rows="3" value={link.url} aria-label="Share link" onfocus={(e) => (e.currentTarget as HTMLTextAreaElement).select()}></textarea>
|
||||
{:else if minting}
|
||||
<p class="ia-muted">Making the link…</p>
|
||||
{/if}
|
||||
|
||||
@@ -5,32 +5,36 @@
|
||||
// Handoff §2.8 order: paused / needs attention, lost contact, health unavailable, the Caddy
|
||||
// notice, then (on Hosts) the intermediate banner. First on every screen.
|
||||
import { Banner, Button, Details } from "@ianitor/ui";
|
||||
import { post, sentence } from "../lib/api";
|
||||
import { app, refresh } from "../lib/app.svelte";
|
||||
import { when } from "../lib/format";
|
||||
import type { ApplyView } from "../lib/types";
|
||||
import { app, refresh, restorable as canRestore, restoreLastKept } from "../lib/app.svelte";
|
||||
import { atTime, whenInline } from "../lib/format";
|
||||
|
||||
const o = $derived(app.overview);
|
||||
let restoring = $state(false);
|
||||
let problem = $state<string | null>(null);
|
||||
|
||||
const restorable = $derived(
|
||||
!!o?.paused && ["apply.needs_attention", "control.files_unwritten"].includes(o.paused_reason ?? "") && !!o.undo?.target,
|
||||
);
|
||||
const restorable = $derived(canRestore());
|
||||
|
||||
async function restoreLastKept() {
|
||||
if (!o?.undo?.target) return;
|
||||
async function restore() {
|
||||
restoring = true;
|
||||
try {
|
||||
const a = await post<{ apply: ApplyView }>("/restore", { change_id: o.undo.target.change_id, base_rev: o.rev });
|
||||
app.panel = { kind: "host", resume: a.apply.id };
|
||||
} catch (e) {
|
||||
problem = sentence(e);
|
||||
} finally {
|
||||
restoring = false;
|
||||
}
|
||||
problem = await restoreLastKept();
|
||||
restoring = false;
|
||||
}
|
||||
|
||||
// §7.6: the bold line and line 2 by the pause's underlying code.
|
||||
const pause = $derived.by(() => {
|
||||
const code = o?.paused_reason ?? "";
|
||||
const message = o?.paused?.message ?? "";
|
||||
if (code === "apply.needs_attention")
|
||||
return { bold: "Ianitor could not undo a failed change.", line2: "Visitors are served the last good settings, but the routes repository still has the change. Restore the last kept version to make them match again.", extra: "" };
|
||||
if (code === "control.files_unwritten")
|
||||
return { bold: "The change is live, but Ianitor could not save the proxy settings to disk.", line2: "Changes are paused until Ianitor restarts and saves them. Restoring the last kept version also clears this.", extra: "On the server: sudo systemctl restart ianitor-control" };
|
||||
// control.paused wraps the reason: "Changes are paused: <reason>"; show the reason itself.
|
||||
const own = message.replace(/^Changes are paused: /, "");
|
||||
if (/^(repo|file|site)\./.test(code))
|
||||
return { bold: own, line2: `Fix the file in the ${o?.repo?.name ?? "routes"} repository; Ianitor picks it up by itself.`, extra: "" };
|
||||
return { bold: own, line2: "", extra: "" };
|
||||
});
|
||||
|
||||
async function retry() {
|
||||
await refresh();
|
||||
}
|
||||
@@ -38,11 +42,13 @@
|
||||
|
||||
{#if o?.paused}
|
||||
<Banner tone="down" live="alert">
|
||||
{#snippet title()}<span class="ia-status" data-s="down"><span class="word">{restorable ? "needs attention" : "paused"}</span></span> <strong>{o.paused?.message}</strong>{/snippet}
|
||||
{#if restorable && o.undo?.target}Goes back to "{o.undo.target.summary}" from {when(o.undo.target.kept_at, app.now)}. It is checked like any change.{/if}
|
||||
{#if problem} {problem}{/if}
|
||||
{#snippet title()}<span class="ia-status" data-s="down"><span class="word">{o.paused_reason === "apply.needs_attention" ? "needs attention" : "paused"}</span></span> <strong>{pause.bold}</strong>{/snippet}
|
||||
{#if pause.line2}<span class="line2">{pause.line2}</span>{/if}
|
||||
{#if restorable && o.undo?.target}<p class="ia-hint">Goes back to "{o.undo.target.summary}" from {whenInline(o.undo.target.kept_at, app.now)}. It is checked like any change.</p>{/if}
|
||||
{#if problem}<p role="status">{problem}</p>{/if}
|
||||
{#if pause.extra}<Details detail={pause.extra} />{/if}
|
||||
{#snippet actions()}
|
||||
{#if restorable}<Button variant="primary" onclick={restoreLastKept} pending={restoring}>Restore the last kept version</Button>{/if}
|
||||
{#if restorable}<Button variant="primary" onclick={restore} pending={restoring}>Restore the last kept version</Button>{/if}
|
||||
{/snippet}
|
||||
</Banner>
|
||||
{/if}
|
||||
@@ -50,7 +56,7 @@
|
||||
{#if app.lostContact}
|
||||
<Banner tone="down" live="alert">
|
||||
{#snippet title()}<strong>{typeof navigator !== "undefined" && navigator.onLine === false ? "This device is offline. Ianitor keeps running." : "Ianitor's control service is not answering."}</strong>{/snippet}
|
||||
Traffic keeps flowing; changes wait until it is back.{#if app.lastUpdated} Last updated {when(new Date(app.lastUpdated).toISOString(), app.now)}.{/if}
|
||||
Traffic keeps flowing; changes wait until it is back.{#if app.lastUpdated} Last updated {atTime(new Date(app.lastUpdated).toISOString(), app.now)}.{/if}
|
||||
{#snippet actions()}<Button onclick={retry}>Try again now</Button>{/snippet}
|
||||
</Banner>
|
||||
{/if}
|
||||
|
||||
Reference in New Issue
Block a user