feat(admin): Library pages on the web panel (owner review 2, R6)

The web panel now manages the library without editing it: the owner can
browse and view sequences and photos, delete sequences and photos into the
archive's trash, restore or empty the trash and run mass operations, as
R6 asks, on top of the engine endpoints of the previous commit.

- Library page right after the Dashboard: search, Year/Camera/Status/Tag
  filters fed by a new GET /api/v1/sequences/facets, sort, cards or list
  (remembered per browser), lazy cover thumbnails, Load more by cursor,
  multi-select with Shift ranges and "Select all N" of the filter, and a
  sticky bar for the selection: Analyse, Proxies, Thumbnails, Verify,
  Tags (add/remove), Export CSV (client-side) and Delete (dry run, list
  of what moves to the trash, then the move). Filters live in the address,
  so Back from a sequence finds them again.
- Sequence view (#/library?id=): inline title, tags, rating and notes,
  facts, photos in pages of 500 with content-visibility, a photo viewer
  (proxy, arrows, Esc, Exif facts), Set cover, Download original, Delete
  photos (typing the count above 20 photos), Delete sequence, renders to
  download. No video editing controls.
- Trash view (#/library?view=trash, also linked from Archive): entries,
  Restore, and Empty (dry run, list, the localised word typed, the plan's
  fingerprint sent back, the job followed to its end).
- Live updates from sequenceChanged and jobState; keyboard grid (one tab
  stop, arrows, Space, Shift+Space, Enter, Ctrl+A, Esc); RTL, dark theme.
- GET /sequences takes rendered=true|false for the Status filter.
- ui.js: confirmDialog's typed confirmation by name, word or count, with a
  list of what the action concerns; formDialog. api.js: putBytes for the
  web upload, which the Library imports on demand (upload.js, optional).
- New web icons from icons.py (Image for the Library, trash, grid/list,
  arrows, stars, cover); directional glyphs mirror in right-to-left pages.
- Strings in en and it; tests for the facets (both dialects), the rendered
  filter, the menu, the modules and the on-demand upload import.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 029cf334f66cb6fa1265b96a6f8faff2964c11ea)
This commit is contained in:
Alby96 committed 2026-10-27 10:51:04 +01:00
1 parent 51782a3ada
commit aa1d4913a3
23 files changed
+2540 -31

No files matched your search

+69 -8
View File
@@ -1,5 +1,5 @@
// Small DOM and formatting helpers shared by the admin pages. No inline styles: the panel runs under a strict CSP.
import { t, culture } from "./i18n.js";
import { t, culture, applyStrings } from "./i18n.js";
export function escapeHtml(s) {
return String(s ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" }[c]));
@@ -145,33 +145,53 @@ export function toast(message, isError = false) {
let dialogs = 0;
/** What a typed confirmation asks for: its field's tooltip, the confirm button's while it waits, and how a value matches. */
const TYPED = {
// A name (an account), exactly as shown.
name: { tip: "Admin.Common.TypeToConfirm.Tip", first: "Admin.Common.TypeFirst.Tip", matches: (value, typed) => value === typed },
// A word of the interface (the localised "empty"), whatever its case.
word: { tip: "Admin.Common.TypeWord.Tip", first: "Admin.Common.TypeWordFirst.Tip",
matches: (value, typed) => value.trim().toLocaleLowerCase() === typed.toLocaleLowerCase() },
// A count (the photos a deletion moves), its digits whatever the separators typed between them.
count: { tip: "Admin.Common.TypeCount.Tip", first: "Admin.Common.TypeCountFirst.Tip",
matches: (value, typed) => value.replace(/[\s.,'’  ]/g, "") === typed },
};
/**
* Two-button confirmation dialog (safe action left and default, Esc keeps). Resolves true when the destructive action
* is chosen; with `typed`, that button stays disabled until the text is typed into the labelled field.
* is chosen; with `typed`, that button stays disabled until the text is typed into the labelled field, as `typedKind`
* says: a name exactly, a word whatever its case, or a count. `list` adds the items the action concerns (titles,
* entries) under the body, in a scrolling box; user text, so each keeps its own direction.
*/
export function confirmDialog({ title, body, confirm, confirmTip, cancel, cancelTip, typed }) {
export function confirmDialog({ title, body, list, confirm, confirmTip, cancel, cancelTip, typed, typedKind = "name" }) {
return new Promise((resolve) => {
const id = `dialog-${++dialogs}`;
const dialog = document.createElement("dialog");
dialog.className = "dialog";
dialog.setAttribute("aria-labelledby", `${id}-title`);
if (body) dialog.setAttribute("aria-describedby", `${id}-body`);
const kind = TYPED[typedKind] ?? TYPED.name;
const firstTip = t(kind.first);
const matches = (value) => kind.matches(value, String(typed));
// The text to type stands out of its sentence, and keeps its own direction.
const typedLabel = typed ? escapeHtml(t("Admin.Common.TypeToConfirm", "\u0001")).replace("\u0001", `<strong dir="auto">${escapeHtml(typed)}</strong>`) : "";
dialog.innerHTML = `
<form method="dialog">
<h2 id="${id}-title" dir="auto">${escapeHtml(title)}</h2>
${body ? `<p id="${id}-body">${escapeHtml(body)}</p>` : ""}
${typed ? `<label class="field-label"><span>${escapeHtml(t("Admin.Common.TypeToConfirm", typed))}</span>
<input class="input" name="typed" autocomplete="off" spellcheck="false" dir="auto" title="${attr(t("Admin.Common.TypeToConfirm.Tip"))}"></label>` : ""}
${list?.length ? `<ul class="dialog-list" tabindex="0" aria-label="${attr(title)}">${list.map((item) => `<li dir="auto">${escapeHtml(item)}</li>`).join("")}</ul>` : ""}
${typed ? `<label class="field-label"><span>${typedLabel}</span>
<input class="input" name="typed" autocomplete="off" spellcheck="false" dir="auto" ${typedKind === "count" ? 'inputmode="numeric"' : ""} title="${attr(t(kind.tip))}"></label>` : ""}
<div class="buttons">
<button class="btn" value="cancel" title="${attr(cancelTip)}" autofocus>${escapeHtml(cancel)}</button>
<button class="btn destructive" value="ok" title="${attr(typed ? t("Admin.Common.TypeFirst.Tip") : confirmTip)}" ${typed ? "disabled" : ""}>${escapeHtml(confirm)}</button>
<button class="btn destructive" value="ok" title="${attr(typed ? firstTip : confirmTip)}" ${typed ? "disabled" : ""}>${escapeHtml(confirm)}</button>
</div>
</form>`;
document.body.appendChild(dialog);
const ok = dialog.querySelector('button[value="ok"]');
dialog.querySelector('input[name="typed"]')?.addEventListener("input", (e) => {
ok.disabled = e.target.value !== typed;
ok.title = ok.disabled ? t("Admin.Common.TypeFirst.Tip") : confirmTip;
ok.disabled = !matches(e.target.value);
ok.title = ok.disabled ? firstTip : confirmTip;
});
dialog.addEventListener("close", () => {
resolve(dialog.returnValue === "ok");
@@ -181,6 +201,47 @@ export function confirmDialog({ title, body, confirm, confirmTip, cancel, cancel
});
}
/**
* A dialog of form fields (fields: HTML whose data-i18n attributes are filled here) with the action on the right, which
* Enter in a field chooses too; Esc or the safe button cancels. Resolves the FormData once confirmed, null when cancelled.
* check(form) may refuse the values: it marks the field (markInvalid) and returns false, and the dialog stays open.
*/
export function formDialog({ title, fields, confirm, confirmTip, cancel, cancelTip, check }) {
return new Promise((resolve) => {
const id = `dialog-${++dialogs}`;
const dialog = document.createElement("dialog");
dialog.className = "dialog";
dialog.setAttribute("aria-labelledby", `${id}-title`);
dialog.innerHTML = `
<form method="dialog" class="form" novalidate>
<h2 id="${id}-title" dir="auto">${escapeHtml(title)}</h2>
${fields}
<div class="buttons">
<button class="btn" type="button" value="cancel" title="${attr(cancelTip)}">${escapeHtml(cancel)}</button>
<button class="btn primary" value="ok" title="${attr(confirmTip)}">${escapeHtml(confirm)}</button>
</div>
</form>`;
applyStrings(dialog);
document.body.appendChild(dialog);
const form = dialog.querySelector("form");
let result = null;
form.addEventListener("submit", (e) => {
if (check && !check(form)) {
e.preventDefault();
return;
}
result = new FormData(form);
});
dialog.querySelector('button[value="cancel"]').addEventListener("click", () => dialog.close());
dialog.addEventListener("close", () => {
resolve(result);
dialog.remove();
});
dialog.showModal();
form.querySelector("input, select, textarea")?.focus();
});
}
/** The localised message of an API failure, or the generic one when the server was not reached. */
export function errorText(err) {
return err?.message && err.status ? err.message : t("Admin.Error.Unreachable");