web: artifacts gallery, full-screen viewer and session export link (R8/R9)
Port the Android artifact derivation into a pure, DOM-free src/artifacts.js (presentedArtifacts with the retired session.md hidden everywhere, grouping by stage/visit, the header/summary/capture-note wording, kind and size formatting, viewer paging and sessionExportArtifact) and unit-test it. Wire it into src/app.js: a run-level artifacts gallery with per-(stage,visit) groups, per-visit summaries and tiles, a full-screen viewer overlay (paging, Escape/backdrop close) and the read-only session.html link. Every server string is set with textContent; captures/ stays untracked. Captured live against run 430 through test/ui-smoke.mjs: captures/04-run-430-artifacts.png, 05-artifact-viewer.png, 06-session-export-link.png. PARITY.md marks R8 and R9 done.
This commit is contained in:
+354
-20
@@ -4,17 +4,30 @@
|
||||
import { PipelinesClient } from "./client.js";
|
||||
import { PipelinesRepository } from "./repository.js";
|
||||
import { validateServerUrl, resolveArtifactUrl } from "./serverUrl.js";
|
||||
import {
|
||||
ArtifactKind,
|
||||
artifactCaptureNotes,
|
||||
artifactGroups,
|
||||
artifactKind,
|
||||
artifactKindLabel,
|
||||
artifactsHeader,
|
||||
artifactsSummary,
|
||||
artifactViewerPositionLabel,
|
||||
displayVisit,
|
||||
humanBytes,
|
||||
pagedArtifacts,
|
||||
pagedIndex,
|
||||
presentedArtifacts,
|
||||
resolvedArtifactUrl,
|
||||
sessionExportArtifact,
|
||||
viewerIndexByUrl,
|
||||
} from "./artifacts.js";
|
||||
|
||||
const STORAGE_KEY = "pipelines.web.serverUrl.v2";
|
||||
|
||||
/**
|
||||
* The retired markdown session export. The server no longer writes it, but a run
|
||||
* recorded before the HTML-only change still lists session.md among its stored
|
||||
* artifacts. It is dated evidence the operator never sees, so every artifact
|
||||
* listing hides it rather than showing it beside the session html (mirroring the
|
||||
* app's presentedArtifacts).
|
||||
*/
|
||||
const LEGACY_SESSION_MARKDOWN_ARTIFACT = "session.md";
|
||||
/** Shown where tiles exist but the configured server URL cannot resolve them. */
|
||||
const ARTIFACT_SERVER_HINT =
|
||||
"Set the server URL in Settings to open or copy artifact links.";
|
||||
|
||||
/**
|
||||
* The page is normally served by serve.mjs, which also proxies /connect to the
|
||||
@@ -342,6 +355,14 @@ function renderRunDetail() {
|
||||
);
|
||||
|
||||
const steps = d.steps ?? [];
|
||||
const executing = isExecuting(d);
|
||||
|
||||
// Run-level artifacts gallery (parity R8). The header is the run summary line
|
||||
// and the gallery below it draws one group per (stage, visit); all derivation
|
||||
// lives in artifacts.js so the count can never disagree with the tiles.
|
||||
pane.append(h("h3", { class: "artifacts-header", text: artifactsHeader(steps, executing) }));
|
||||
pane.append(renderArtifactGallery(steps));
|
||||
|
||||
pane.append(h("h3", { text: `Steps (${steps.length})` }));
|
||||
if (!steps.length) {
|
||||
pane.append(h("div", { class: "muted pad", text: "No steps recorded yet." }));
|
||||
@@ -369,7 +390,8 @@ function renderRunDetail() {
|
||||
kv("Session", s.session_id || "—"),
|
||||
s.diagnostic ? kv("Diagnostic", s.diagnostic) : null,
|
||||
),
|
||||
renderArtifacts(s),
|
||||
renderVisitArtifacts(s),
|
||||
renderSessionExport(s),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -377,21 +399,333 @@ function renderRunDetail() {
|
||||
return pane;
|
||||
}
|
||||
|
||||
function renderArtifacts(step) {
|
||||
const artifacts = (step.artifacts ?? []).filter((a) => a.name !== LEGACY_SESSION_MARKDOWN_ARTIFACT);
|
||||
if (!artifacts.length) return null;
|
||||
const wrap = h("div", { class: "artifacts" }, h("span", { class: "muted", text: "Artifacts: " }));
|
||||
for (const a of artifacts) {
|
||||
const href = resolveArtifactUrl(state.url, a.url);
|
||||
if (href) {
|
||||
wrap.append(h("a", { href, target: "_blank", rel: "noreferrer", text: a.name || a.url }));
|
||||
} else {
|
||||
wrap.append(h("span", { class: "muted", text: `${a.name || a.url} (no server URL)` }));
|
||||
}
|
||||
/** Whether the configured server URL can resolve a server-relative artifact. */
|
||||
function artifactsResolvable() {
|
||||
return resolveArtifactUrl(state.url, "/artifacts/0/0/probe") != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The run-level gallery: one header per (stage, visit) and one grid of tiles per
|
||||
* visit, in the gallery order (stages first-appearance, visits by sequence). A
|
||||
* run with no artifacts shows the header (which already says why) and nothing
|
||||
* else, so the section is never blank.
|
||||
*/
|
||||
function renderArtifactGallery(steps) {
|
||||
const wrap = h("div", { class: "artifact-gallery" });
|
||||
const groups = artifactGroups(steps);
|
||||
if (!groups.length) return wrap;
|
||||
if (!artifactsResolvable()) {
|
||||
wrap.append(h("div", { class: "muted artifact-hint", text: ARTIFACT_SERVER_HINT }));
|
||||
}
|
||||
const viewable = pagedArtifacts(groups);
|
||||
const viewerIndexOf = viewerIndexByUrl(groups);
|
||||
for (const group of groups) {
|
||||
wrap.append(
|
||||
h("div", { class: "artifact-group-head", text: `${group.stageKey} · visit ${group.visit}` }),
|
||||
renderArtifactGrid(group.artifacts, viewable, viewerIndexOf),
|
||||
);
|
||||
}
|
||||
return wrap;
|
||||
}
|
||||
|
||||
/**
|
||||
* The per-visit artifacts section shown inside one step: the summary line, the
|
||||
* capture notes, the no-server-URL hint and a headerless grid of that visit's
|
||||
* tiles (matching the Android ArtifactsSection). Its viewer pages only through
|
||||
* that visit's media, exactly as the Android section does.
|
||||
*/
|
||||
function renderVisitArtifacts(step) {
|
||||
const wrap = h("div", { class: "artifacts" });
|
||||
wrap.append(h("div", { class: "artifacts-summary", text: artifactsSummary(step) }));
|
||||
for (const note of artifactCaptureNotes(step)) {
|
||||
wrap.append(h("div", { class: "artifacts-note muted", text: note }));
|
||||
}
|
||||
const artifacts = presentedArtifacts(step);
|
||||
if (artifacts.length) {
|
||||
if (!artifactsResolvable()) {
|
||||
wrap.append(h("div", { class: "muted artifact-hint", text: ARTIFACT_SERVER_HINT }));
|
||||
}
|
||||
const group = { stageKey: step.stage, visit: displayVisit(step, 0), artifacts };
|
||||
wrap.append(
|
||||
renderArtifactGrid(artifacts, pagedArtifacts([group]), viewerIndexByUrl([group])),
|
||||
);
|
||||
}
|
||||
return wrap;
|
||||
}
|
||||
|
||||
/** One visit's tiles in a CSS grid. */
|
||||
function renderArtifactGrid(artifacts, viewable, viewerIndexOf) {
|
||||
const grid = h("div", { class: "artifact-grid" });
|
||||
for (const artifact of artifacts) {
|
||||
grid.append(renderArtifactTile(artifact, viewable, viewerIndexOf));
|
||||
}
|
||||
return grid;
|
||||
}
|
||||
|
||||
/**
|
||||
* One gallery tile: an image thumbnail, a video poster with a play marker (never
|
||||
* a <video> element or autoplay), or a kind/name/size label. Every server string
|
||||
* is set as text, never as markup.
|
||||
*/
|
||||
function renderArtifactTile(artifact, viewable, viewerIndexOf) {
|
||||
const resolved = resolvedArtifactUrl(artifact, state.url);
|
||||
const kind = artifactKind(artifact.content_type, artifact.name);
|
||||
const media = kind === ArtifactKind.Image || kind === ArtifactKind.Video;
|
||||
const name = artifact.name || "(unnamed artifact)";
|
||||
const tile = h("div", { class: "artifact-tile clickable" });
|
||||
const openViewer = () => {
|
||||
const at = viewerIndexOf.get(artifact.url);
|
||||
if (at != null) openArtifactViewer(viewable, at);
|
||||
};
|
||||
const openTab = () => {
|
||||
if (resolved) window.open(resolved, "_blank", "noopener,noreferrer");
|
||||
};
|
||||
if (kind === ArtifactKind.Image) {
|
||||
const img = h("img", { class: "artifact-thumb", alt: name, loading: "lazy" });
|
||||
if (resolved) img.src = resolved;
|
||||
tile.append(img);
|
||||
tile.addEventListener("click", openViewer);
|
||||
} else if (kind === ArtifactKind.Video) {
|
||||
tile.append(h("div", { class: "artifact-poster" }, h("span", { class: "artifact-play", text: "▶" })));
|
||||
tile.append(h("div", { class: "artifact-name", text: name }));
|
||||
tile.addEventListener("click", openViewer);
|
||||
} else {
|
||||
tile.append(
|
||||
h("div", { class: "artifact-kind", text: artifactKindLabel(kind) }),
|
||||
h("div", { class: "artifact-name", text: name }),
|
||||
h("div", { class: "artifact-size", text: humanBytes(artifact.size_bytes) }),
|
||||
);
|
||||
tile.addEventListener("click", openTab);
|
||||
}
|
||||
tile.append(renderTileActions(resolved, media));
|
||||
return tile;
|
||||
}
|
||||
|
||||
/** The compact per-tile actions: copy-link (non-media tiles) and share. */
|
||||
function renderTileActions(resolved, media) {
|
||||
const actions = h("div", { class: "artifact-actions" });
|
||||
const stop = (fn) => (event) => {
|
||||
event.stopPropagation();
|
||||
fn();
|
||||
};
|
||||
if (!media) {
|
||||
actions.append(
|
||||
h("button", {
|
||||
class: "artifact-action",
|
||||
type: "button",
|
||||
text: "Copy link",
|
||||
disabled: !resolved || !canCopyLink(),
|
||||
onclick: stop(() => copyArtifactLink(resolved)),
|
||||
}),
|
||||
);
|
||||
}
|
||||
actions.append(
|
||||
h("button", {
|
||||
class: "artifact-action",
|
||||
type: "button",
|
||||
text: "Share",
|
||||
disabled: !resolved || !canShare(),
|
||||
onclick: stop(() => shareArtifact(resolved)),
|
||||
}),
|
||||
);
|
||||
return actions;
|
||||
}
|
||||
|
||||
function canCopyLink() {
|
||||
return typeof navigator !== "undefined" && Boolean(navigator.clipboard?.writeText);
|
||||
}
|
||||
|
||||
function canShare() {
|
||||
return typeof navigator !== "undefined" && typeof navigator.share === "function";
|
||||
}
|
||||
|
||||
async function copyArtifactLink(resolved) {
|
||||
if (!resolved || !canCopyLink()) return;
|
||||
try {
|
||||
await navigator.clipboard.writeText(resolved);
|
||||
} catch {
|
||||
// Clipboard permission may be denied; the link is still openable.
|
||||
}
|
||||
}
|
||||
|
||||
async function shareArtifact(resolved) {
|
||||
if (!resolved || !canShare()) return;
|
||||
try {
|
||||
await navigator.share({ url: resolved });
|
||||
} catch {
|
||||
// The share chooser may be dismissed.
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The step's session export: a link opening the read-only session.html in a new
|
||||
* tab, or the plain notice when the visit exported nothing (parity R9).
|
||||
*/
|
||||
function renderSessionExport(step) {
|
||||
const file = sessionExportArtifact(step);
|
||||
const wrap = h("div", { class: "session-export" });
|
||||
if (!file) {
|
||||
wrap.append(h("span", { class: "muted", text: "No session was exported for this visit." }));
|
||||
return wrap;
|
||||
}
|
||||
const href = resolvedArtifactUrl(file, state.url);
|
||||
if (href) {
|
||||
wrap.append(
|
||||
h("a", {
|
||||
class: "session-link",
|
||||
href,
|
||||
target: "_blank",
|
||||
rel: "noreferrer",
|
||||
text: `Open ${file.name || "session.html"}`,
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
wrap.append(
|
||||
h("span", { class: "muted", text: "Set the server URL in Settings to open the session." }),
|
||||
);
|
||||
}
|
||||
return wrap;
|
||||
}
|
||||
|
||||
let viewerOverlay = null;
|
||||
let viewerKeydown = null;
|
||||
|
||||
/** Close the full-screen viewer and remove its Escape listener. */
|
||||
function closeArtifactViewer() {
|
||||
if (viewerKeydown) {
|
||||
document.removeEventListener("keydown", viewerKeydown);
|
||||
viewerKeydown = null;
|
||||
}
|
||||
viewerOverlay?.remove();
|
||||
viewerOverlay = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the full-screen viewer at `startIndex` into `viewable`, the same ordered
|
||||
* media list the grid drew. Previous/Next are disabled at the ends and absent for
|
||||
* a single artifact; Escape and a backdrop click close it. Nothing autoplays: a
|
||||
* non-image artifact shows a still poster placeholder instead.
|
||||
*/
|
||||
function openArtifactViewer(viewable, startIndex) {
|
||||
closeArtifactViewer();
|
||||
if (!viewable?.length) return;
|
||||
let index = pagedIndex(startIndex, 0, viewable.length);
|
||||
const overlay = h("div", {
|
||||
class: "artifact-viewer",
|
||||
role: "dialog",
|
||||
"aria-modal": "true",
|
||||
"aria-label": "Artifact viewer",
|
||||
});
|
||||
overlay.addEventListener("click", (event) => {
|
||||
if (event.target === overlay) closeArtifactViewer();
|
||||
});
|
||||
|
||||
const renderViewer = () => {
|
||||
const artifact = viewable[index] ?? {};
|
||||
const resolved = resolvedArtifactUrl(artifact, state.url);
|
||||
const kind = artifactKind(artifact.content_type, artifact.name);
|
||||
const name = artifact.name || "(unnamed artifact)";
|
||||
|
||||
const board = h("div", { class: "viewer-board" });
|
||||
if (kind === ArtifactKind.Image && resolved) {
|
||||
board.append(h("img", { class: "viewer-image", src: resolved, alt: name }));
|
||||
} else {
|
||||
board.append(
|
||||
h(
|
||||
"div",
|
||||
{ class: "viewer-placeholder" },
|
||||
h("span", { class: "artifact-play", text: "▶" }),
|
||||
h("span", { class: "viewer-placeholder-name", text: name }),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
const head = h(
|
||||
"div",
|
||||
{ class: "viewer-head" },
|
||||
h("div", { class: "viewer-title", text: name }),
|
||||
h("div", {
|
||||
class: "viewer-position muted",
|
||||
text: artifactViewerPositionLabel(index, viewable.length, artifact.content_type),
|
||||
}),
|
||||
);
|
||||
|
||||
const actions = h("div", { class: "viewer-actions" });
|
||||
if (resolved) {
|
||||
actions.append(
|
||||
h("button", {
|
||||
class: "viewer-action",
|
||||
type: "button",
|
||||
text: "Open",
|
||||
onclick: () => window.open(resolved, "_blank", "noopener,noreferrer"),
|
||||
}),
|
||||
h("button", {
|
||||
class: "viewer-action",
|
||||
type: "button",
|
||||
text: "Copy link",
|
||||
disabled: !canCopyLink(),
|
||||
onclick: () => copyArtifactLink(resolved),
|
||||
}),
|
||||
h("button", {
|
||||
class: "viewer-action",
|
||||
type: "button",
|
||||
text: "Share",
|
||||
disabled: !canShare(),
|
||||
onclick: () => shareArtifact(resolved),
|
||||
}),
|
||||
);
|
||||
}
|
||||
actions.append(
|
||||
h("button", {
|
||||
class: "viewer-action viewer-close",
|
||||
type: "button",
|
||||
text: "Close viewer",
|
||||
onclick: closeArtifactViewer,
|
||||
}),
|
||||
);
|
||||
|
||||
const nodes = [head, board];
|
||||
if (viewable.length > 1) {
|
||||
nodes.push(
|
||||
h(
|
||||
"div",
|
||||
{ class: "viewer-nav" },
|
||||
h("button", {
|
||||
class: "viewer-page",
|
||||
type: "button",
|
||||
text: "Previous artifact",
|
||||
disabled: pagedIndex(index, -1, viewable.length) === index,
|
||||
onclick: () => {
|
||||
index = pagedIndex(index, -1, viewable.length);
|
||||
renderViewer();
|
||||
},
|
||||
}),
|
||||
h("button", {
|
||||
class: "viewer-page",
|
||||
type: "button",
|
||||
text: "Next artifact",
|
||||
disabled: pagedIndex(index, 1, viewable.length) === index,
|
||||
onclick: () => {
|
||||
index = pagedIndex(index, 1, viewable.length);
|
||||
renderViewer();
|
||||
},
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
nodes.push(actions);
|
||||
overlay.replaceChildren(...nodes);
|
||||
};
|
||||
|
||||
renderViewer();
|
||||
document.body.append(overlay);
|
||||
viewerOverlay = overlay;
|
||||
viewerKeydown = (event) => {
|
||||
if (event.key === "Escape") closeArtifactViewer();
|
||||
};
|
||||
document.addEventListener("keydown", viewerKeydown);
|
||||
}
|
||||
|
||||
function kv(key, value) {
|
||||
return h(
|
||||
"div",
|
||||
|
||||
Reference in New Issue
Block a user