feat(server): the server keeps its sequences' projects, pushed and pulled like a PC's archive
Owner review 2, phase 5b (R8): a server is a project home. A workspace can
list a sequence's projects, make, rename and delete them, read their
versions and push new ones through /api/v1/sequences/{sid}/projects. The
endpoints run on the archive's ProjectService exactly as a desktop's archive
does (sidecars first, then the index, under the sequence's lease), so no
version is stored apart and a desktop sharing the archive sees the same
projects.
- Protocol: project, version, create, rename, version page, push answer
(outcome, stored version, head, plus code and message on 409/422) and
home frames DTOs, the projectChanged event, the "projects" capability and
the ChronosClient calls; a push returns its outcome without throwing on
409 or 422. ProjectWire maps them to and from the model for both sides.
- Server: Read lists and reads, Edit makes, renames and pushes, Delete (the
sequence's owner, the project's maker or an admin) deletes; refusals with
stable codes, 503 while the sequence is busy, offline or moved; the
pushing account becomes the version's author; creations, renames and
deletions audited, pushes logged.
- ProjectService tells the host what each call changed, compared under the
lease, so projectChanged also follows Main's external versions; a Main
version mirrored into the settings sends sequenceChanged too, for older
clients. ProjectCatchUp takes settings a PATCH, an analysis or a
conversion wrote into Main at once, for sequences that have a Main.
- Renders of a project version: POST /jobs checks the project and version
against the sequence and pins a project alone to its head; render nodes
get the version's settings placed on the frames they claim; the render
records the project and version.
- Admin panel: the sequence page lists its projects (Main marked, head,
last change, versions on demand) with Rename and Delete for the others,
live on projectChanged. It edits no settings.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
917cddde41
commit
e2ecc409a3
30 files changed
+2261
-35
No files matched your search
@@ -0,0 +1,232 @@
|
||||
// The projects of a sequence on the panel (owner review 2, R8): each project's name, Main marked, its newest version and who
|
||||
// changed it last, its versions on demand, and Rename and Delete for the projects other than Main. Nothing here edits a
|
||||
// project's settings: the desktop does, in its workspace, and pushes its versions here. The list follows projectChanged.
|
||||
import { t, plural, applyStrings } from "../../i18n.js";
|
||||
import { escapeHtml, attr, formatNumber, formatDateTime, toast, errorText, confirmDialog, formDialog, emptyState, markInvalid, redraw, fitColumns } from "../../ui.js";
|
||||
|
||||
/** Versions read at a time when a project is opened, and with each Load more. */
|
||||
const VERSION_PAGE = 20;
|
||||
/** A project name, as the server takes it (ProjectService.MaxNameLength). */
|
||||
const MAX_NAME = 60;
|
||||
/** The name every sequence's Main project is made with; shown in the panel's language. */
|
||||
const MAIN_NAME = "Main";
|
||||
/** How long after a projectChanged the projects are read again; one read covers every change meanwhile. */
|
||||
const AFTER_CHANGE_MS = 500;
|
||||
/** Version kinds the panel names (ProjectVersionKinds). */
|
||||
const KINDS = { commit: "Commit", merge: "Merge", restore: "Restore", imported: "Imported", external: "External" };
|
||||
|
||||
/**
|
||||
* Draws the Projects section of sequence sequenceId into host (its count into meta) and keeps it current. Returns
|
||||
* onEvent(e), which the sequence page passes every server event to.
|
||||
*/
|
||||
export function projectsSection(host, meta, { api, sequenceId }) {
|
||||
const base = `/api/v1/sequences/${encodeURIComponent(sequenceId)}/projects`;
|
||||
let projects = [];
|
||||
/** The versions read of each project opened: { items, more }. */
|
||||
const versions = new Map();
|
||||
const expanded = new Set();
|
||||
let timer = null;
|
||||
let failed = null;
|
||||
|
||||
host.innerHTML = `
|
||||
<div class="table projects" data-levels="1" role="table" aria-labelledby="projects-title">
|
||||
<div class="thead" role="row"><span role="columnheader" data-i18n="Admin.Projects.Name"></span>
|
||||
<span role="columnheader" class="end" data-i18n="Admin.Projects.Head"></span>
|
||||
<span role="columnheader" class="col-changed" data-i18n="Admin.Projects.Changed"></span>
|
||||
<span role="columnheader"><span class="sr-only" data-i18n="Admin.Common.Actions"></span></span></div>
|
||||
<div role="rowgroup" id="project-rows"></div>
|
||||
</div>`;
|
||||
applyStrings(host);
|
||||
const table = host.querySelector(".table");
|
||||
const rows = host.querySelector("#project-rows");
|
||||
|
||||
async function load() {
|
||||
try {
|
||||
projects = await api.get(base);
|
||||
failed = null;
|
||||
// A project deleted meanwhile (here or elsewhere) closes; the others' versions are read again.
|
||||
for (const id of expanded) {
|
||||
if (!projects.some((p) => p.id === id)) forget(id);
|
||||
}
|
||||
await Promise.all([...expanded].map((id) => loadVersions(id).catch(() => forget(id))));
|
||||
} catch (err) {
|
||||
projects = [];
|
||||
failed = errorText(err);
|
||||
}
|
||||
if (!host.isConnected) return;
|
||||
meta.textContent = failed ? "" : plural("Admin.Projects.Count", projects.length);
|
||||
draw();
|
||||
}
|
||||
|
||||
/** The newest versions of a project, or with more the next page after those shown. */
|
||||
async function loadVersions(id, more = false) {
|
||||
const known = versions.get(id);
|
||||
const before = more && known?.items.length ? `&before=${known.items[known.items.length - 1].number}` : "";
|
||||
const page = await api.get(`${base}/${encodeURIComponent(id)}/versions?limit=${VERSION_PAGE}${before}`);
|
||||
versions.set(id, { items: more && known ? known.items.concat(page.items) : page.items, more: page.more });
|
||||
}
|
||||
|
||||
function forget(id) {
|
||||
expanded.delete(id);
|
||||
versions.delete(id);
|
||||
}
|
||||
|
||||
function draw() {
|
||||
redraw(rows, () => {
|
||||
rows.innerHTML = failed
|
||||
? `<div class="row" role="row"><div class="wide empty" role="cell">${escapeHtml(failed)}</div></div>`
|
||||
: projects.map(rowHtml).join("") || `<div class="row" role="row"><div class="wide" role="cell">${emptyState("Admin.Projects.Empty")}</div></div>`;
|
||||
applyStrings(rows);
|
||||
});
|
||||
rows.querySelectorAll("[data-toggle]").forEach((b) => b.addEventListener("click", () => toggle(b.dataset.toggle)));
|
||||
rows.querySelectorAll("[data-act]").forEach((b) => b.addEventListener("click", () => act(b.dataset.act, find(b.closest("[data-key]").dataset.key))));
|
||||
rows.querySelectorAll("[data-more-versions]").forEach((b) => b.addEventListener("click", () => moreVersions(b.dataset.moreVersions)));
|
||||
fitColumns(table);
|
||||
}
|
||||
|
||||
function find(id) {
|
||||
return projects.find((p) => p.id === id);
|
||||
}
|
||||
|
||||
/** Main keeps the name it was made with in the panel's language; a Main renamed shows its name and the Main mark. */
|
||||
function projectName(p) {
|
||||
return p.isMain && p.name === MAIN_NAME ? t("Admin.Projects.Main") : p.name;
|
||||
}
|
||||
|
||||
function rowHtml(p) {
|
||||
const name = projectName(p);
|
||||
const mark = p.isMain && p.name !== MAIN_NAME
|
||||
? `<span class="pill" data-i18n="Admin.Projects.Main" data-i18n-title="Admin.Projects.Main.Tip"></span>` : "";
|
||||
const who = p.headAuthor ?? p.headClientName ?? "";
|
||||
const when = p.headStoredAt ?? p.updatedAt;
|
||||
const actions = p.isMain ? "" : `
|
||||
<button class="btn small" data-act="rename" data-i18n="Admin.Projects.Rename" data-i18n-title="Admin.Projects.Rename.Tip"></button>
|
||||
<button class="btn small destructive" data-act="delete" data-i18n="Admin.Projects.Delete" data-i18n-title="Admin.Projects.Delete.Tip"></button>`;
|
||||
return `
|
||||
<div class="row" role="row" data-key="${attr(p.id)}">
|
||||
<span class="name-cell" role="cell"><button class="link ellipsis" data-toggle="${attr(p.id)}" aria-expanded="${expanded.has(p.id)}"
|
||||
aria-controls="versions-${attr(p.id)}" dir="auto" title="${attr(p.isMain ? `${t("Admin.Projects.Main.Tip")}\n${t("Admin.Projects.Versions.Tip")}` : t("Admin.Projects.Versions.Tip"))}">${escapeHtml(name)}</button>${mark}</span>
|
||||
<span class="num end nowrap" role="cell" title="${attr(t("Admin.Projects.Head.Tip"))}">${escapeHtml(formatNumber(p.headNumber))}</span>
|
||||
<span class="col-changed ellipsis" role="cell" title="${attr([kindTip(p.headKind), p.headClientName].filter(Boolean).join("\n"))}"><span dir="auto">${escapeHtml(who)}</span>${who ? " · " : ""}<span class="muted nowrap">${escapeHtml(formatDateTime(when))}</span></span>
|
||||
<span class="row-actions" role="cell">${actions}</span>
|
||||
</div>
|
||||
${expanded.has(p.id) ? `<div class="row log-row" role="row"><div class="wide" role="cell" id="versions-${attr(p.id)}">${versionsHtml(p)}</div></div>` : ""}`;
|
||||
}
|
||||
|
||||
function versionsHtml(p) {
|
||||
const page = versions.get(p.id);
|
||||
if (!page) return "";
|
||||
if (page.items.length === 0) return emptyState("Admin.Projects.NoVersions");
|
||||
return `<div class="versions" role="list" aria-label="${attr(t("Admin.Projects.VersionsOf", projectName(p)))}">${page.items.map((v) => `
|
||||
<div class="version" role="listitem">
|
||||
<span class="num nowrap">${escapeHtml(t("Admin.Projects.Number", formatNumber(v.number)))}${v.id === p.headVersionId
|
||||
? ` <span class="pill" data-i18n="Admin.Projects.Current" data-i18n-title="Admin.Projects.Current.Tip"></span>` : ""}</span>
|
||||
<span class="nowrap" title="${attr(kindTip(v.kind))}">${escapeHtml(kindLabel(v.kind))}</span>
|
||||
<span class="ellipsis" dir="auto" title="${attr([v.author, v.clientName].filter(Boolean).join(" · "))}">${escapeHtml(v.author ?? v.clientName ?? "")}</span>
|
||||
<span class="ellipsis muted" dir="auto" title="${attr(v.note ?? "")}">${escapeHtml(v.note ?? "")}</span>
|
||||
<span class="muted nowrap num">${escapeHtml(formatDateTime(v.storedAt ?? v.createdAt))}</span>
|
||||
</div>`).join("")}
|
||||
${page.more ? `<button class="btn small more" data-more-versions="${attr(p.id)}" data-i18n="Admin.Common.More" data-i18n-title="Admin.Common.More.Tip"></button>` : ""}</div>`;
|
||||
}
|
||||
|
||||
function kindLabel(kind) {
|
||||
return KINDS[kind] ? t(`Admin.Projects.Kind.${KINDS[kind]}`) : String(kind ?? "");
|
||||
}
|
||||
|
||||
function kindTip(kind) {
|
||||
return KINDS[kind] ? t(`Admin.Projects.Kind.${KINDS[kind]}.Tip`) : "";
|
||||
}
|
||||
|
||||
async function toggle(id) {
|
||||
if (expanded.delete(id)) {
|
||||
versions.delete(id);
|
||||
draw();
|
||||
return;
|
||||
}
|
||||
expanded.add(id);
|
||||
try {
|
||||
await loadVersions(id);
|
||||
} catch (err) {
|
||||
forget(id);
|
||||
toast(errorText(err), true);
|
||||
}
|
||||
draw();
|
||||
}
|
||||
|
||||
async function moreVersions(id) {
|
||||
try {
|
||||
await loadVersions(id, true);
|
||||
} catch (err) {
|
||||
toast(errorText(err), true);
|
||||
return;
|
||||
}
|
||||
draw();
|
||||
}
|
||||
|
||||
async function act(action, project) {
|
||||
if (!project || project.isMain) return;
|
||||
if (action === "rename") return rename(project);
|
||||
if (action === "delete") return remove(project);
|
||||
}
|
||||
|
||||
async function rename(project) {
|
||||
const data = await formDialog({
|
||||
title: t("Admin.Projects.RenameTitle", project.name),
|
||||
fields: `<label><span data-i18n="Admin.Projects.NewName"></span><input class="input" name="name" dir="auto" maxlength="${MAX_NAME}" autocomplete="off"
|
||||
value="${attr(project.name)}" data-i18n-title="Admin.Projects.NewName.Tip"></label>`,
|
||||
confirm: t("Admin.Projects.RenameConfirm"),
|
||||
confirmTip: t("Admin.Projects.RenameConfirm.Tip"),
|
||||
cancel: t("Admin.Common.Cancel"),
|
||||
cancelTip: t("Admin.Common.Cancel.Tip"),
|
||||
check: (form) => {
|
||||
const name = form.elements.name.value.trim();
|
||||
if (name.length > 0 && name.length <= MAX_NAME) return true;
|
||||
markInvalid(form.elements.name, t("Admin.Projects.NameInvalid"));
|
||||
form.elements.name.focus();
|
||||
return false;
|
||||
},
|
||||
});
|
||||
const name = String(data?.get("name") ?? "").trim();
|
||||
if (!data || name === project.name) return;
|
||||
try {
|
||||
await api.patch(`${base}/${encodeURIComponent(project.id)}`, { name });
|
||||
toast(t("Admin.Projects.Renamed", name));
|
||||
} catch (err) {
|
||||
toast(errorText(err), true);
|
||||
}
|
||||
await load();
|
||||
}
|
||||
|
||||
/** Delete, after a confirmation that names the project: it and its versions move to the sequence's project trash. */
|
||||
async function remove(project) {
|
||||
const confirmed = await confirmDialog({
|
||||
title: t("Admin.Projects.DeleteTitle", project.name),
|
||||
body: t("Admin.Projects.DeleteBody", formatNumber(project.headNumber)),
|
||||
confirm: t("Admin.Projects.DeleteConfirm"),
|
||||
confirmTip: t("Admin.Projects.DeleteConfirm.Tip"),
|
||||
cancel: t("Admin.Common.Keep"),
|
||||
cancelTip: t("Admin.Common.Keep.Tip"),
|
||||
});
|
||||
if (!confirmed) return;
|
||||
try {
|
||||
await api.del(`${base}/${encodeURIComponent(project.id)}`);
|
||||
toast(t("Admin.Projects.Deleted", project.name));
|
||||
forget(project.id);
|
||||
} catch (err) {
|
||||
toast(errorText(err), true);
|
||||
}
|
||||
await load();
|
||||
}
|
||||
|
||||
load();
|
||||
return {
|
||||
onEvent(e) {
|
||||
if ((e.type === "projectChanged" && e.sequenceId === sequenceId) || e.type === "reconnected") {
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(() => {
|
||||
if (host.isConnected) load();
|
||||
}, AFTER_CHANGE_MS);
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user