Add three composition cases driven by the same generic web Tool: - examples/doc-site (documentation site), - examples/research-workspace (existing section 8 workbench prototype), - examples/quantum-editor (finite scenario/interaction design). Add a real production delivery trial in examples/research-workbench-app (Express + JSON persistence + static UI): validation, search, status transitions, linked statistics, JSON errors, real file persistence; node:test API acceptance and a Playwright browser E2E. The production app is not a runtime dependency of the web Tool; prototype PASS is kept separate from production PASS. docs/WEB-04-delivery.md records the design-source to implementation mapping, intentional non-goals and task splits. scripts/domain-acceptance.sh is the explicit domain entry: installs the built Tool, runs check/preview/handoff for the three cases, then installs/tests the production app incl. browser E2E, and removes the Tool. Evidence records the real CLI/Design/Preview identities and local PASS results. Pin the domain submodules to the merged Design (WEB-01/03) and Preview (WEB-02) candidates; activation and root gitlink belong to WEB-05. Refs cflmy/marqdo-ext-web#2, cflmy/marqdo#6
79 lines
2.7 KiB
JavaScript
79 lines
2.7 KiB
JavaScript
const statsNode = document.querySelector("#stats");
|
|
const tasksNode = document.querySelector("#tasks");
|
|
const errorNode = document.querySelector("#error");
|
|
const searchNode = document.querySelector("#search");
|
|
const form = document.querySelector("#create-form");
|
|
const titleNode = document.querySelector("#title");
|
|
const priorityNode = document.querySelector("#priority");
|
|
|
|
const showError = (message) => {
|
|
errorNode.textContent = message;
|
|
errorNode.classList.toggle("hidden", !message);
|
|
};
|
|
|
|
async function request(path, options) {
|
|
const response = await fetch(path, options);
|
|
const body = await response.json().catch(() => ({}));
|
|
if (!response.ok) throw new Error(body?.error?.message ?? `HTTP ${response.status}`);
|
|
return body;
|
|
}
|
|
|
|
async function refresh() {
|
|
try {
|
|
const query = encodeURIComponent(searchNode.value.trim());
|
|
const [tasks, stats] = await Promise.all([
|
|
request(`/api/tasks?q=${query}`),
|
|
request("/api/stats"),
|
|
]);
|
|
statsNode.textContent = `总数 ${stats.total} · 待办 ${stats.byStatus.open} · 进行中 ${stats.byStatus.doing} · 完成 ${stats.byStatus.done}`;
|
|
tasksNode.replaceChildren(
|
|
...tasks.tasks.map((task) => {
|
|
const item = document.createElement("li");
|
|
const label = document.createElement("span");
|
|
label.textContent = `${task.title} · ${task.priority} · ${task.status}`;
|
|
item.append(label);
|
|
if (task.status !== "done") {
|
|
const button = document.createElement("button");
|
|
button.type = "button";
|
|
button.textContent = task.status === "open" ? "开始" : "完成";
|
|
button.addEventListener("click", async () => {
|
|
try {
|
|
await request(`/api/tasks/${task.id}/status`, {
|
|
method: "PATCH",
|
|
headers: { "content-type": "application/json" },
|
|
body: JSON.stringify({ status: task.status === "open" ? "doing" : "done" }),
|
|
});
|
|
showError("");
|
|
await refresh();
|
|
} catch (error) {
|
|
showError(error.message);
|
|
}
|
|
});
|
|
item.append(button);
|
|
}
|
|
return item;
|
|
}),
|
|
);
|
|
} catch (error) {
|
|
showError(error.message);
|
|
}
|
|
}
|
|
|
|
form.addEventListener("submit", async (event) => {
|
|
event.preventDefault();
|
|
try {
|
|
await request("/api/tasks", {
|
|
method: "POST",
|
|
headers: { "content-type": "application/json" },
|
|
body: JSON.stringify({ title: titleNode.value, priority: priorityNode.value }),
|
|
});
|
|
titleNode.value = "";
|
|
showError("");
|
|
await refresh();
|
|
} catch (error) {
|
|
showError(error.message);
|
|
}
|
|
});
|
|
searchNode.addEventListener("input", refresh);
|
|
refresh();
|