feat(admin): Convert dialog in the Library for JPEG, TIFF-16 or linear DNG
Owner review 2, R7 asks for mass conversion after import on the web panel too, with what happens to the originals chosen at every run. The Library's mass bar gets Convert… for the selection (every sequence after Select all without a filter, else at most a thousand ids, the same rule as Reorganize, now one helper). The dialog (convert.js) offers the format (linear DNG, the archival choice, first), the JPEG quality (shown for JPEG only, 1-100, checked on the field) and the mode, Replace or New sequence, never preselected, each tooltip saying what happens to the originals. Every change asks POST /archive/convert for a dry run, one request at a time and debounced while typing; the table shows per sequence the photos converted, the photos left as they are with why (what blocks the whole sequence first), and the size before and after, then the totals and the server's space line. While no mode is chosen the table is planned as New sequence (what converts does not depend on the mode) and Apply waits; choosing Replace plans again, since the fingerprint names the mode. Apply confirms Replace by typing the localised word, New sequence with a plain confirmation, sends the shown plan's fingerprint back and links the queued job; plan_changed, not_enough_space and nothing_to_convert plan again. Server refusals land on the field they name. The trash says what Restore does to a replaced entry (the originals swap back while their conversions are unchanged) and toasts it; the audit entry archive_converted reads as a sentence. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 2a09572e3e67ef95a931333c35cd3bb1e818db71) (cherry picked from commit 1d71a18fa112a7cb39e3e7ced7d7234230eb4453)
This commit is contained in:
1 parent
0e52929274
commit
2143a093a2
11 files changed
+863
-27
No files matched your search
@@ -433,14 +433,15 @@ dialog.dialog.reorganize { width: 960px; }
|
||||
.reorg-fields .field-error { grid-column: 2; color: var(--error); font-size: 12px; overflow-wrap: anywhere; }
|
||||
.reorg-fields .field-error:empty { display: none; }
|
||||
.reorg-totals { min-height: 18px; color: var(--text-muted); }
|
||||
.reorg-preview { max-height: 46vh; overflow: auto; border: 1px solid var(--stroke); border-radius: var(--radius); background: var(--bg); }
|
||||
.reorg-preview:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
||||
.reorg-preview.stale .table { opacity: .55; }
|
||||
/* A dry run's table, Reorganize's and Convert's: scrolls inside the dialog, dimmed while it no longer matches the fields. */
|
||||
.reorg-preview, .plan-preview { max-height: 46vh; overflow: auto; border: 1px solid var(--stroke); border-radius: var(--radius); background: var(--bg); }
|
||||
.reorg-preview:focus-visible, .plan-preview:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
||||
.reorg-preview.stale .table, .plan-preview.stale .table { opacity: .55; }
|
||||
.table.reorg { grid-template-columns: minmax(120px, 1fr) minmax(160px, 1.3fr) minmax(160px, 1.3fr); font-size: 12px; }
|
||||
.table.reorg .thead { position: sticky; top: 0; z-index: 1; padding: 8px 12px; background: var(--bg); }
|
||||
.table.reorg .row { min-height: 0; padding: 8px 12px; align-items: start; }
|
||||
.table.reorg .row:hover { background: none; }
|
||||
.table.reorg .row:last-child { border-bottom: 0; }
|
||||
.table.reorg .thead, .table.convert .thead { position: sticky; top: 0; z-index: 1; padding: 8px 12px; background: var(--bg); }
|
||||
.table.reorg .row, .table.convert .row { min-height: 0; padding: 8px 12px; align-items: start; }
|
||||
.table.reorg .row:hover, .table.convert .row:hover { background: none; }
|
||||
.table.reorg .row:last-child, .table.convert .row:last-child { border-bottom: 0; }
|
||||
.table.reorg .pill { align-self: flex-start; margin-block-start: 4px; }
|
||||
.change { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
|
||||
.change .was { color: var(--text-muted); text-decoration: line-through; }
|
||||
@@ -448,11 +449,29 @@ dialog.dialog.reorganize { width: 960px; }
|
||||
.reorg-samples, .reorg-kept { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 2px; }
|
||||
.reorg-samples { color: var(--text-muted); }
|
||||
.reorg-kept { color: var(--warning); }
|
||||
.reorg-preview .table-foot { padding: 8px 12px; border-top: 1px solid var(--stroke); }
|
||||
.reorg-preview .table-foot, .plan-preview .table-foot { padding: 8px 12px; border-top: 1px solid var(--stroke); }
|
||||
|
||||
/* Convert dialog (owner review 2, R7, convert.js): format, JPEG quality and mode side by side (the mode never preselected),
|
||||
the dry run's totals and space line, then per sequence the photos converted, those left as they are with why (what
|
||||
blocks the whole sequence first, ▲ in the warning colour) and the size before and after. */
|
||||
dialog.dialog.convert { width: 960px; }
|
||||
.convert-fields { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 12px 32px; }
|
||||
.convert-choice { border: 0; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px 20px; }
|
||||
.convert-choice legend { color: var(--text-muted); padding: 0; margin-block-end: 8px; }
|
||||
.convert-choice[aria-invalid="true"] { outline: 2px solid var(--error); outline-offset: 4px; border-radius: var(--radius); }
|
||||
.convert-quality .input { width: 88px; }
|
||||
.convert-summary { display: grid; gap: 4px; min-height: 18px; color: var(--text-muted); }
|
||||
.convert-space.short { color: var(--error); }
|
||||
.convert-next { color: var(--text); }
|
||||
.table.convert { grid-template-columns: minmax(140px, 1.3fr) max-content minmax(160px, 1.6fr) max-content; font-size: 12px; }
|
||||
.plan-notes { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; color: var(--text-muted); }
|
||||
.plan-notes .blocked { color: var(--warning); }
|
||||
|
||||
/* Narrow windows: each step's cells one under the other; the column names stay for screen readers. */
|
||||
@media (max-width: 700px) {
|
||||
.table.reorg { grid-template-columns: minmax(0, 1fr); }
|
||||
.table.reorg .thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
|
||||
.table.reorg, .table.convert { grid-template-columns: minmax(0, 1fr); }
|
||||
.table.reorg .thead, .table.convert .thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
|
||||
.table.convert .end { justify-self: start; }
|
||||
}
|
||||
|
||||
/* About: the last group of Settings (owner review 2); #/about scrolls to it below the sticky header and focuses its heading. */
|
||||
|
||||
@@ -80,6 +80,13 @@ export function detailText(entry) {
|
||||
if (!/^\d+$/.test(sequences) || !/^\d+$/.test(files ?? "")) return details;
|
||||
return [plural("Admin.Library.Count", Number(sequences)), plural("Admin.Reorganize.FilesRenamed", Number(files)), ...templates.filter(Boolean)].join(" · ");
|
||||
}
|
||||
// Owner review 2, R7: "sequences · photos · target · mode", e.g. "2 · 120 · linear-dng · replace".
|
||||
case "archive_converted": {
|
||||
const [sequences, photos, target, mode] = details.split(" · ");
|
||||
if (!/^\d+$/.test(sequences) || !/^\d+$/.test(photos ?? "")) return details;
|
||||
return [plural("Admin.Library.Count", Number(sequences)), plural("Admin.Dashboard.PhotoCount", Number(photos)),
|
||||
wireLabel("Admin.Convert.Format.", target), wireLabel("Admin.Convert.Mode.", mode)].filter(Boolean).join(" · ");
|
||||
}
|
||||
default:
|
||||
return details;
|
||||
}
|
||||
@@ -107,6 +114,13 @@ function scheduleNameIn(parts) {
|
||||
return scheduleName({ systemKey, name: (systemKey ? parts.slice(1) : parts).join(" · ") });
|
||||
}
|
||||
|
||||
/** A code of the API in words by its key under prefix ("linear-dng" → Admin.Convert.Format.LinearDng); else as recorded. */
|
||||
function wireLabel(prefix, code) {
|
||||
if (!code) return "";
|
||||
const key = prefix + pascal(code);
|
||||
return has(key) ? t(key) : code;
|
||||
}
|
||||
|
||||
function splitLast(details) {
|
||||
const at = details.lastIndexOf(" · ");
|
||||
return at < 0 ? [details] : [details.slice(0, at), details.slice(at + 3)];
|
||||
|
||||
@@ -0,0 +1,399 @@
|
||||
// Convert dialog of the admin panel (owner review 2, R7; BRIEF §12.5, §14.8): the photos of the Library's selection, or of
|
||||
// every sequence, converted to JPEG, TIFF-16 or linear DNG. What happens to the originals is chosen at every run, never
|
||||
// preselected: Replace (the converted files become the sequence's photos, the originals go to the archive's trash) or New
|
||||
// sequence (converted copies in a new sequence, the source untouched). Each change asks the server for a dry run (nothing
|
||||
// is touched) and the table shows, per sequence, what converts, what stays as it is and why, and the size before and
|
||||
// after. Apply confirms that very plan by its fingerprint (Replace by typing a word), and the server runs it as a job
|
||||
// (kind "convert") that verifies every converted file before anything changes.
|
||||
import { t, plural, applyStrings } from "./i18n.js";
|
||||
import { escapeHtml, attr, formatBytes, formatNumber, toast, errorText, confirmDialog, markInvalid, clearInvalid } from "./ui.js";
|
||||
import { listed } from "./pages/library/shared.js";
|
||||
|
||||
const ENDPOINT = "/api/v1/archive/convert";
|
||||
/** Wait after the last keystroke in Quality before the dry run, and the steps the table draws at a time. */
|
||||
const PLAN_DELAY = 400;
|
||||
const PAGE = 200;
|
||||
const DEFAULT_QUALITY = 95;
|
||||
/** The formats, as the API names them, with their strings; linear DNG, the archival choice, is the one chosen first. */
|
||||
const TARGETS = [
|
||||
{ value: "jpeg", label: "Admin.Convert.Format.Jpeg", tip: "Admin.Convert.Format.Jpeg.Tip" },
|
||||
{ value: "tiff16", label: "Admin.Convert.Format.Tiff16", tip: "Admin.Convert.Format.Tiff16.Tip" },
|
||||
{ value: "linear-dng", label: "Admin.Convert.Format.LinearDng", tip: "Admin.Convert.Format.LinearDng.Tip" },
|
||||
];
|
||||
const ARCHIVAL = "linear-dng";
|
||||
/** What happens to the originals; no default: the person converting chooses every time. */
|
||||
const MODES = [
|
||||
{ value: "replace", label: "Admin.Convert.Mode.Replace", tip: "Admin.Convert.Mode.Replace.Tip" },
|
||||
{ value: "new-sequence", label: "Admin.Convert.Mode.NewSequence", tip: "Admin.Convert.Mode.NewSequence.Tip" },
|
||||
];
|
||||
/**
|
||||
* The mode the dry run is asked with while none is chosen: what converts does not depend on the mode, so the table shows
|
||||
* the plan at once; Apply waits for a choice, and a choice other than this one plans again (the fingerprint names it).
|
||||
*/
|
||||
const PREVIEW_MODE = "new-sequence";
|
||||
|
||||
let dialogs = 0;
|
||||
|
||||
/**
|
||||
* Opens the Convert dialog. target is { all: true } (every sequence of the archive) or { sequenceIds } (at most a bulk
|
||||
* request's thousand); names maps sequence ids to the titles the page shows. Resolves when the dialog closes: the queued
|
||||
* job, or null.
|
||||
*/
|
||||
export function openConvert({ api, target, names = new Map() } = {}) {
|
||||
return new Promise((resolve) => {
|
||||
const id = `convert-${++dialogs}`;
|
||||
/** The last dry run, with key: the request it answers. */
|
||||
let plan = null;
|
||||
let shown = PAGE;
|
||||
let timer = null;
|
||||
let planning = false;
|
||||
let again = false;
|
||||
let busy = false;
|
||||
let queued = null;
|
||||
/** A message the next plan shows (why the plan was made again). */
|
||||
let notice = "";
|
||||
const title = target.all ? t("Admin.Convert.TitleAll") : plural("Admin.Convert.Title", target.sequenceIds.length);
|
||||
const radio = (name, o, checked) => `<label class="check" title="${attr(t(o.tip))}"><input type="radio" name="${name}" value="${o.value}"
|
||||
${checked ? "checked" : ""} title="${attr(t(o.tip))}"><span>${escapeHtml(t(o.label))}</span></label>`;
|
||||
|
||||
const dialog = document.createElement("dialog");
|
||||
dialog.className = "dialog convert";
|
||||
dialog.setAttribute("aria-labelledby", `${id}-title`);
|
||||
dialog.innerHTML = `
|
||||
<form novalidate>
|
||||
<h2 id="${id}-title" dir="auto">${escapeHtml(title)}</h2>
|
||||
<div class="convert-fields">
|
||||
<fieldset class="convert-choice" data-field="target"><legend data-i18n="Admin.Convert.Format"></legend>
|
||||
${TARGETS.map((o) => radio("target", o, o.value === ARCHIVAL)).join("")}</fieldset>
|
||||
<label class="field-label convert-quality"><span data-i18n="Admin.Convert.Quality"></span>
|
||||
<input class="input narrow" name="quality" type="number" min="1" max="100" step="1" inputmode="numeric" value="${DEFAULT_QUALITY}"
|
||||
autocomplete="off" data-i18n-title="Admin.Convert.Quality.Tip"></label>
|
||||
<fieldset class="convert-choice" data-field="mode" role="radiogroup" aria-required="true"><legend data-i18n="Admin.Convert.Mode"></legend>
|
||||
${MODES.map((o) => radio("mode", o, false)).join("")}</fieldset>
|
||||
</div>
|
||||
<div class="convert-summary" role="status">
|
||||
<span class="convert-totals"></span>
|
||||
<span class="convert-space" hidden></span>
|
||||
<span class="convert-next" hidden data-i18n="Admin.Convert.ChooseMode"></span>
|
||||
</div>
|
||||
<div class="plan-preview" role="region" tabindex="0" aria-label="${attr(t("Admin.Convert.Preview"))}" title="${attr(t("Admin.Convert.Preview.Tip"))}" hidden>
|
||||
<div class="table convert" role="table" aria-label="${attr(t("Admin.Convert.Preview"))}">
|
||||
<div class="thead" role="row"><span role="columnheader" data-i18n="Admin.Convert.Column.Sequence"></span>
|
||||
<span role="columnheader" class="end" data-i18n="Admin.Convert.Column.Converted"></span>
|
||||
<span role="columnheader" data-i18n="Admin.Convert.Column.Unchanged"></span>
|
||||
<span role="columnheader" class="end" data-i18n="Admin.Convert.Column.Size"></span></div>
|
||||
<div role="rowgroup" class="convert-rows"></div>
|
||||
</div>
|
||||
<div class="table-foot" hidden><span class="muted convert-shown"></span><span class="spacer"></span>
|
||||
<button class="btn small" type="button" data-act="more" data-i18n="Admin.Common.More" data-i18n-title="Admin.Common.More.Tip"></button></div>
|
||||
</div>
|
||||
<div class="error" role="alert"></div>
|
||||
<div class="buttons">
|
||||
<button class="btn" type="button" data-act="close" data-i18n="Admin.Common.Cancel" data-i18n-title="Admin.Convert.Cancel.Tip"></button>
|
||||
<button class="btn primary" type="button" data-act="apply" disabled data-i18n="Admin.Convert.Apply" data-i18n-title="Admin.Convert.Apply.Tip"></button>
|
||||
</div>
|
||||
</form>`;
|
||||
document.body.appendChild(dialog);
|
||||
applyStrings(dialog);
|
||||
const form = dialog.querySelector("form");
|
||||
const quality = form.elements.quality;
|
||||
const qualityField = dialog.querySelector(".convert-quality");
|
||||
const targetSet = dialog.querySelector('[data-field="target"]');
|
||||
const modeSet = dialog.querySelector('[data-field="mode"]');
|
||||
const totals = dialog.querySelector(".convert-totals");
|
||||
const space = dialog.querySelector(".convert-space");
|
||||
const next = dialog.querySelector(".convert-next");
|
||||
const preview = dialog.querySelector(".plan-preview");
|
||||
const rows = dialog.querySelector(".convert-rows");
|
||||
const foot = dialog.querySelector(".table-foot");
|
||||
const shownText = dialog.querySelector(".convert-shown");
|
||||
const errorLine = dialog.querySelector(".error");
|
||||
const closeButton = dialog.querySelector('[data-act="close"]');
|
||||
const applyButton = dialog.querySelector('[data-act="apply"]');
|
||||
|
||||
for (const set of [targetSet, modeSet]) {
|
||||
set.addEventListener("change", () => {
|
||||
clearInvalid(set);
|
||||
showError("");
|
||||
drawQuality();
|
||||
// Choosing the mode the table was planned with needs no new dry run.
|
||||
if (!planning && plan !== null && plan.key === keyNow()) drawPlan();
|
||||
else schedule(0);
|
||||
});
|
||||
}
|
||||
quality.addEventListener("input", () => {
|
||||
clearInvalid(quality);
|
||||
showError("");
|
||||
schedule(PLAN_DELAY);
|
||||
});
|
||||
// Enter in Quality plans at once; only the Apply button changes anything.
|
||||
form.addEventListener("submit", (e) => {
|
||||
e.preventDefault();
|
||||
if (!busy) schedule(0);
|
||||
});
|
||||
closeButton.addEventListener("click", () => {
|
||||
if (!busy) dialog.close();
|
||||
});
|
||||
applyButton.addEventListener("click", apply);
|
||||
dialog.querySelector('[data-act="more"]').addEventListener("click", () => {
|
||||
shown += PAGE;
|
||||
drawRows();
|
||||
if (foot.hidden) preview.focus();
|
||||
});
|
||||
// Esc closes, except while the change is being sent.
|
||||
dialog.addEventListener("cancel", (e) => {
|
||||
if (busy) e.preventDefault();
|
||||
});
|
||||
const signedOut = () => dialog.close();
|
||||
window.addEventListener("chronos:signed-out", signedOut);
|
||||
dialog.addEventListener("close", () => {
|
||||
clearTimeout(timer);
|
||||
window.removeEventListener("chronos:signed-out", signedOut);
|
||||
dialog.remove();
|
||||
resolve(queued);
|
||||
});
|
||||
dialog.showModal();
|
||||
drawQuality();
|
||||
targetSet.querySelector("input:checked").focus();
|
||||
schedule(0);
|
||||
|
||||
/** The value of a choice's checked radio button, null while none is. */
|
||||
function chosen(set) {
|
||||
return set.querySelector("input:checked")?.value ?? null;
|
||||
}
|
||||
|
||||
/** The quality typed, a whole number from 1 to 100, else null. */
|
||||
function qualityValue() {
|
||||
const text = quality.value.trim();
|
||||
const n = Number(text);
|
||||
return /^\d+$/.test(text) && n >= 1 && n <= 100 ? n : null;
|
||||
}
|
||||
|
||||
/** The request the fields make (without dryRun); its quality only for a JPEG, its mode the preview's until one is chosen. */
|
||||
function request() {
|
||||
const body = target.all ? { all: true } : { all: false, sequenceIds: target.sequenceIds };
|
||||
const format = chosen(targetSet);
|
||||
body.target = format;
|
||||
body.quality = format === "jpeg" ? qualityValue() : null;
|
||||
body.mode = chosen(modeSet) ?? PREVIEW_MODE;
|
||||
return body;
|
||||
}
|
||||
|
||||
function keyNow() {
|
||||
return JSON.stringify(request());
|
||||
}
|
||||
|
||||
/** Quality is a JPEG's alone: hidden for the lossless formats. */
|
||||
function drawQuality() {
|
||||
qualityField.hidden = chosen(targetSet) !== "jpeg";
|
||||
}
|
||||
|
||||
/** Plans again after delay ms; what the table shows until then no longer matches the fields. */
|
||||
function schedule(delay) {
|
||||
clearTimeout(timer);
|
||||
preview.classList.add("stale");
|
||||
drawButtons();
|
||||
timer = setTimeout(runPlan, delay);
|
||||
}
|
||||
|
||||
/** One dry run at a time: a change made while one is answered plans again right after it. */
|
||||
async function runPlan() {
|
||||
if (!dialog.open) return;
|
||||
if (planning) {
|
||||
again = true;
|
||||
return;
|
||||
}
|
||||
if (chosen(targetSet) === "jpeg" && qualityValue() === null) {
|
||||
plan = null;
|
||||
fieldError(quality, t("Admin.Convert.QualityRange"));
|
||||
drawPlan();
|
||||
return;
|
||||
}
|
||||
const body = request();
|
||||
const key = JSON.stringify(body);
|
||||
planning = true;
|
||||
totals.textContent = t("Admin.Convert.Planning");
|
||||
drawButtons();
|
||||
try {
|
||||
const answer = await api.post(ENDPOINT, { ...body, dryRun: true });
|
||||
if (!dialog.open) return;
|
||||
plan = { ...answer, key };
|
||||
shown = PAGE;
|
||||
showError(notice);
|
||||
notice = "";
|
||||
} catch (err) {
|
||||
if (!dialog.open) return;
|
||||
plan = null;
|
||||
// A refusal of an older request is not shown: the fields changed since, and the next plan tells.
|
||||
if (key === keyNow()) showProblem(err);
|
||||
} finally {
|
||||
planning = false;
|
||||
}
|
||||
if (again) {
|
||||
again = false;
|
||||
drawPlan();
|
||||
runPlan();
|
||||
return;
|
||||
}
|
||||
drawPlan();
|
||||
}
|
||||
|
||||
function drawPlan() {
|
||||
const current = plan !== null && plan.key === keyNow();
|
||||
preview.classList.toggle("stale", !current);
|
||||
if (!plan) {
|
||||
totals.textContent = "";
|
||||
space.hidden = true;
|
||||
next.hidden = true;
|
||||
preview.hidden = true;
|
||||
} else {
|
||||
totals.textContent = plan.photos === 0 ? t("Admin.Convert.NothingToConvert")
|
||||
: t("Admin.Convert.Totals", formatNumber(plan.sequences), formatNumber(plan.photos), formatNumber(plan.skipped),
|
||||
formatBytes(plan.bytesBefore), formatBytes(plan.bytesAfter));
|
||||
space.hidden = plan.photos === 0;
|
||||
space.textContent = plan.space.message;
|
||||
space.classList.toggle("short", !plan.space.enough);
|
||||
next.hidden = plan.photos === 0 || !plan.space.enough || chosen(modeSet) !== null;
|
||||
preview.hidden = plan.steps.length === 0;
|
||||
if (!preview.hidden) drawRows();
|
||||
}
|
||||
drawButtons();
|
||||
}
|
||||
|
||||
function drawRows() {
|
||||
const steps = plan.steps;
|
||||
rows.innerHTML = steps.slice(0, shown).map(rowHtml).join("");
|
||||
foot.hidden = steps.length <= shown;
|
||||
shownText.textContent = t("Admin.Library.Shown", formatNumber(Math.min(shown, steps.length)), formatNumber(steps.length));
|
||||
}
|
||||
|
||||
/**
|
||||
* One sequence: its title and folder, the photos converted (or what blocks it), the photos left as they are with why,
|
||||
* and the size of those converted before and after (an estimate).
|
||||
*/
|
||||
function rowHtml(s) {
|
||||
const name = names.get(s.sequenceId) || s.title || folderName(s.folder);
|
||||
const blocked = s.blocked ?? [];
|
||||
const skipped = s.skipped ?? [];
|
||||
const converts = blocked.length === 0 && s.photos > 0;
|
||||
const count = converts ? `<strong class="num">${escapeHtml(formatNumber(s.photos))}</strong>` : `<span class="muted">—</span>`;
|
||||
// What blocks the whole sequence first, then the photos left as they are.
|
||||
const notes = [...blocked.map((b) => `<li class="blocked"><span aria-hidden="true">▲</span> ${escapeHtml(b.message)}</li>`),
|
||||
...skipped.map((k) => `<li>${escapeHtml(t("Admin.Convert.SkippedPhotos", plural("Admin.Dashboard.PhotoCount", k.photos), k.message))}</li>`)];
|
||||
const left = notes.length > 0 ? `<ul class="plan-notes">${notes.join("")}</ul>` : `<span class="muted">—</span>`;
|
||||
const size = converts
|
||||
? `<span class="num nowrap" dir="auto" title="${attr(t("Admin.Convert.Size.Tip"))}">${escapeHtml(t("Admin.Convert.SizeChange", formatBytes(s.bytesBefore), formatBytes(s.bytesAfter)))}</span>`
|
||||
: `<span class="muted">—</span>`;
|
||||
return `<div class="row${converts ? "" : " dim"}" role="row" data-key="${attr(s.sequenceId)}">
|
||||
<span role="cell" class="stack"><strong class="ellipsis" dir="auto" title="${attr(name)}">${escapeHtml(name)}</strong>
|
||||
<small class="path" dir="ltr" title="${attr(s.folder || "/")}">${escapeHtml(s.folder || "/")}</small></span>
|
||||
<span role="cell" class="end">${count}</span>
|
||||
<span role="cell">${left}</span>
|
||||
<span role="cell" class="end">${size}</span>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
/** Apply waits for a current plan that converts something, with the space it needs, and for the mode; its tooltip says which. */
|
||||
function drawButtons() {
|
||||
for (const field of form.querySelectorAll("input")) field.disabled = busy;
|
||||
const current = plan !== null && plan.key === keyNow() && !planning;
|
||||
const mode = chosen(modeSet);
|
||||
const reason = !current ? null
|
||||
: plan.photos === 0 ? "Admin.Convert.Nothing.Tip"
|
||||
: !plan.space.enough ? "Admin.Convert.NoSpace.Tip"
|
||||
: mode === null ? "Admin.Convert.ChooseMode.Tip" : null;
|
||||
applyButton.disabled = busy || !current || reason !== null;
|
||||
applyButton.title = t(reason ?? "Admin.Convert.Apply.Tip");
|
||||
closeButton.disabled = busy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace asks for a word to be typed (the originals leave the sequence for the trash); New sequence for a plain
|
||||
* confirmation. The plan sent back is the one the table shows (the fields cannot change meanwhile).
|
||||
*/
|
||||
async function apply() {
|
||||
if (applyButton.disabled) return;
|
||||
const shownPlan = plan;
|
||||
const body = JSON.parse(shownPlan.key);
|
||||
const format = targetLabel(body.target);
|
||||
const going = shownPlan.steps.filter((s) => (s.blocked ?? []).length === 0 && s.photos > 0);
|
||||
const list = listed(going.map((s) => t("Admin.Convert.PlanItem", names.get(s.sequenceId) || s.title || folderName(s.folder),
|
||||
plural("Admin.Dashboard.PhotoCount", s.photos), t("Admin.Convert.SizeChange", formatBytes(s.bytesBefore), formatBytes(s.bytesAfter)))));
|
||||
const replace = body.mode === "replace";
|
||||
const confirmed = await confirmDialog(replace ? {
|
||||
title: t("Admin.Convert.ConfirmReplaceTitle", format),
|
||||
body: plural("Admin.Convert.ConfirmReplace", shownPlan.photos, plural("Admin.Library.Count", shownPlan.sequences)),
|
||||
list,
|
||||
confirm: t("Admin.Convert.Confirm.Replace"),
|
||||
confirmTip: t("Admin.Convert.Confirm.Replace.Tip"),
|
||||
cancel: t("Admin.Common.Keep"),
|
||||
cancelTip: t("Admin.Common.Keep.Tip"),
|
||||
typed: t("Admin.Convert.ReplaceWord"),
|
||||
typedKind: "word",
|
||||
} : {
|
||||
title: t("Admin.Convert.ConfirmNewTitle", format),
|
||||
body: plural("Admin.Convert.ConfirmNew", shownPlan.photos),
|
||||
list,
|
||||
confirm: t("Admin.Convert.Confirm.New"),
|
||||
confirmTip: t("Admin.Convert.Confirm.New.Tip"),
|
||||
cancel: t("Admin.Common.Keep"),
|
||||
cancelTip: t("Admin.Common.Keep.Tip"),
|
||||
});
|
||||
if (!confirmed || !dialog.open || plan !== shownPlan) return;
|
||||
busy = true;
|
||||
showError("");
|
||||
drawButtons();
|
||||
try {
|
||||
const job = await api.post(ENDPOINT, { ...body, dryRun: false, fingerprint: shownPlan.fingerprint });
|
||||
queued = job;
|
||||
busy = false;
|
||||
dialog.close();
|
||||
toast(t("Admin.Convert.Queued"), false,
|
||||
{ label: t("Admin.Convert.OpenJob"), tip: t("Admin.Convert.OpenJob.Tip"), href: `#/jobs?job=${encodeURIComponent(job.id)}` });
|
||||
} catch (err) {
|
||||
busy = false;
|
||||
if (!dialog.open) return;
|
||||
if (err?.code === "plan_changed" || err?.code === "not_enough_space" || err?.code === "nothing_to_convert") {
|
||||
// The archive changed since the dry run (or its volume filled up): the new plan is shown, and Apply waits for it.
|
||||
notice = err.code === "plan_changed" ? err.message || t("Admin.Error.Unreachable") : errorText(err);
|
||||
plan = null;
|
||||
schedule(0);
|
||||
} else {
|
||||
showProblem(err);
|
||||
}
|
||||
drawButtons();
|
||||
(applyButton.disabled ? closeButton : applyButton).focus();
|
||||
}
|
||||
}
|
||||
|
||||
/** A refusal on the field it names (quality, format, mode), else under the table. */
|
||||
function showProblem(err) {
|
||||
const field = err?.code === "bad_request" ? { quality, target: targetSet, mode: modeSet }[err.details] : undefined;
|
||||
if (field === quality) fieldError(quality, t("Admin.Convert.QualityRange"));
|
||||
else if (field) fieldError(field, errorText(err));
|
||||
else if (err?.code === "not_found") showError(t("Admin.Convert.Gone"));
|
||||
else showError(errorText(err));
|
||||
}
|
||||
|
||||
/** The field's error border with the message as its tooltip (DESIGN §4), and the message in the dialog's alert line. */
|
||||
function fieldError(field, message) {
|
||||
markInvalid(field, message);
|
||||
showError(message);
|
||||
}
|
||||
|
||||
function showError(message) {
|
||||
errorLine.textContent = message;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/** A format's name in the panel's language ("jpeg" → "JPEG", "linear-dng" → "Linear DNG"). */
|
||||
function targetLabel(value) {
|
||||
const known = TARGETS.find((o) => o.value === value);
|
||||
return known ? t(known.label) : String(value ?? "");
|
||||
}
|
||||
|
||||
/** The last part of a sequence folder ("2026/2026-09-28 Roof" → "2026-09-28 Roof"), its name when it has no title. */
|
||||
function folderName(folder) {
|
||||
return String(folder ?? "").split("/").filter(Boolean).pop() ?? "—";
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
// Library (owner review 2, R6; BRIEF §14.8): the panel browses, views and deletes sequences and photos and runs mass
|
||||
// operations on them, but never edits a video (no settings, no render). #/library lists the sequences with filters in the
|
||||
// address, #/library?id=<sequence> opens one (library/sequence.js), #/library?view=trash the archive's trash (library/trash.js).
|
||||
// Reorganize (R7) applies new folder, file and title templates to the selection (reorganize.js).
|
||||
// Reorganize (R7) applies new folder, file and title templates to the selection (reorganize.js), Convert (R7) converts its
|
||||
// photos to JPEG, TIFF-16 or linear DNG (convert.js).
|
||||
import { t, plural, applyStrings } from "../i18n.js";
|
||||
import { escapeHtml, attr, formatBytes, formatNumber, toast, errorText, confirmDialog, formDialog, markInvalid, emptyState, routeParams, redraw } from "../ui.js";
|
||||
import { icons } from "../icons.js";
|
||||
@@ -9,6 +10,7 @@ import { BULK_LIMIT, factsLine, captureText, cameraLabel, statusChips, lazyImage
|
||||
import { renderSequence } from "./library/sequence.js";
|
||||
import { renderTrash } from "./library/trash.js";
|
||||
import { openReorganize } from "../reorganize.js";
|
||||
import { openConvert } from "../convert.js";
|
||||
|
||||
const VIEW_KEY = "chronos.admin.library.view";
|
||||
const PAGE = 100;
|
||||
@@ -345,6 +347,7 @@ async function renderList(root, { api, setMeta, actions, onEvent }, params) {
|
||||
<span class="spacer"></span>
|
||||
${JOBS.map(job).join("")}
|
||||
<button class="btn small" id="mass-reorganize" data-mass="reorganize" data-i18n="Admin.Reorganize.Action" data-i18n-title="Admin.Reorganize.Action.Tip"></button>
|
||||
<button class="btn small" id="mass-convert" data-mass="convert" data-i18n="Admin.Convert.Action" data-i18n-title="Admin.Convert.Action.Tip"></button>
|
||||
<button class="btn small" id="mass-retag" data-mass="retag" data-i18n="Admin.Library.Retag" data-i18n-title="Admin.Library.Retag.Tip"></button>
|
||||
<button class="btn small" id="mass-csv" data-mass="csv" data-i18n="Admin.Library.ExportCsv" data-i18n-title="Admin.Library.ExportCsv.Tip"></button>
|
||||
<button class="btn small destructive" id="mass-delete" data-mass="delete" data-i18n="Admin.Library.Delete" data-i18n-title="Admin.Library.Delete.Tip"></button>
|
||||
@@ -364,8 +367,9 @@ async function renderList(root, { api, setMeta, actions, onEvent }, params) {
|
||||
}
|
||||
if (action === "all") return selectAll();
|
||||
if (action === "csv") return exportCsv();
|
||||
// A modal dialog: the button stays enabled, so the focus comes back to it when the dialog closes.
|
||||
// Modal dialogs: the button stays enabled, so the focus comes back to it when the dialog closes.
|
||||
if (action === "reorganize") return reorganize();
|
||||
if (action === "convert") return convert();
|
||||
button.disabled = true;
|
||||
try {
|
||||
if (action === "job") await queueJobs(button.dataset.kind);
|
||||
@@ -425,20 +429,36 @@ async function renderList(root, { api, setMeta, actions, onEvent }, params) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Reorganize (owner review 2, R7) of the selected sequences: their ids, at most a bulk request's thousand (one plan,
|
||||
* one job). Beyond that, every sequence of the archive, but only while the selection is exactly what Select all
|
||||
* fetched without a filter and the archive has not grown since: a sequence unticked or added later is never included.
|
||||
* What a plan-first mass operation (owner review 2, R7: Reorganize, Convert) works on: the selected sequences' ids, at
|
||||
* most a bulk request's thousand (one plan, one job). Beyond that, every sequence of the archive, but only while the
|
||||
* selection is exactly what Select all fetched without a filter and the archive has not grown since: a sequence unticked
|
||||
* or added later is never included. Null, with tooMany's toast, otherwise.
|
||||
*/
|
||||
async function reorganize() {
|
||||
function planTarget(tooMany) {
|
||||
const ids = [...selection.ids];
|
||||
const everything = ids.length > BULK_LIMIT && matching !== null && !isFiltered() && total === matching.length &&
|
||||
ids.length === matching.length && matching.every((s) => selection.has(s.id));
|
||||
if (!everything && ids.length > BULK_LIMIT) {
|
||||
toast(t("Admin.Reorganize.TooMany", formatNumber(BULK_LIMIT)), true);
|
||||
return;
|
||||
toast(t(tooMany, formatNumber(BULK_LIMIT)), true);
|
||||
return null;
|
||||
}
|
||||
return everything ? { all: true } : { sequenceIds: ids };
|
||||
}
|
||||
|
||||
/** Reorganize of the selected sequences: new folder, file and title templates, with a dry run. */
|
||||
async function reorganize() {
|
||||
const target = planTarget("Admin.Reorganize.TooMany");
|
||||
if (!target) return;
|
||||
const names = new Map(selectedRows().map((s) => [s.id, s.displayTitle]));
|
||||
await openReorganize({ api, target: everything ? { all: true } : { sequenceIds: ids }, names });
|
||||
await openReorganize({ api, target, names });
|
||||
}
|
||||
|
||||
/** Convert of the selected sequences' photos: the format and, at every run, Replace or New sequence, with a dry run. */
|
||||
async function convert() {
|
||||
const target = planTarget("Admin.Convert.TooMany");
|
||||
if (!target) return;
|
||||
const names = new Map(selectedRows().map((s) => [s.id, s.displayTitle]));
|
||||
await openConvert({ api, target, names });
|
||||
}
|
||||
|
||||
async function retag() {
|
||||
|
||||
@@ -78,7 +78,7 @@ export async function renderTrash(root, { api, setMeta, actions, onEvent }, { ba
|
||||
<span class="col-by ellipsis" role="cell" dir="auto">${escapeHtml(e.deletedBy ?? "—")}</span>
|
||||
<span class="muted nowrap" role="cell">${escapeHtml(formatDateTime(e.deletedAt))}</span>
|
||||
<span class="row-actions" role="cell"><button class="btn small" data-restore="${attr(e.name)}" data-i18n="Admin.Trash.Restore"
|
||||
data-i18n-title="${e.kind === "sequence" ? "Admin.Trash.RestoreSequence.Tip" : "Admin.Trash.RestorePhotos.Tip"}" ${restoring.has(e.name) ? "disabled" : ""}></button></span>
|
||||
data-i18n-title="${restoreTip(e.kind)}" ${restoring.has(e.name) ? "disabled" : ""}></button></span>
|
||||
</div>`).join("")
|
||||
|| `<div class="row" role="row"><div class="wide" role="cell">${emptyState("Admin.Trash.IsEmpty",
|
||||
`<a class="btn small" href="${attr(back)}" data-i18n="Admin.Trash.Back" data-i18n-title="Admin.Trash.Back.Tip"></a>`)}</div></div>`;
|
||||
@@ -104,8 +104,11 @@ export async function renderTrash(root, { api, setMeta, actions, onEvent }, { ba
|
||||
else draw();
|
||||
return;
|
||||
}
|
||||
// A replaced entry (owner review 2, R7) swaps back: its originals take their conversions' place, which go to the trash.
|
||||
const lines = [result.kind === "sequence" ? t("Admin.Trash.RestoredSequence", entry.title)
|
||||
: result.newSequence ? plural("Admin.Trash.RestoredNew", result.photos) : plural("Admin.Trash.RestoredPhotos", result.photos, entry.title)];
|
||||
: result.newSequence ? plural("Admin.Trash.RestoredNew", result.photos)
|
||||
: result.kind === "replaced" ? plural("Admin.Trash.RestoredOriginals", result.photos, entry.title)
|
||||
: plural("Admin.Trash.RestoredPhotos", result.photos, entry.title)];
|
||||
// The server says, in the page's language, how many photos stayed in the trash and why (one sentence per reason).
|
||||
if (result.kept.length > 0 && result.message) lines.push(result.message);
|
||||
toast(lines.join(" "), result.kept.length > 0);
|
||||
@@ -212,6 +215,11 @@ export async function renderTrash(root, { api, setMeta, actions, onEvent }, { ba
|
||||
await load();
|
||||
}
|
||||
|
||||
/** What Restore does to an entry of this kind: a sequence's folder back, photos back, or originals back in place of their conversions. */
|
||||
function restoreTip(kind) {
|
||||
return kind === "sequence" ? "Admin.Trash.RestoreSequence.Tip" : kind === "replaced" ? "Admin.Trash.RestoreReplaced.Tip" : "Admin.Trash.RestorePhotos.Tip";
|
||||
}
|
||||
|
||||
function kindLabel(kind) {
|
||||
return t(kind === "sequence" ? "Admin.Trash.Kind.Sequence" : kind === "replaced" ? "Admin.Trash.Kind.Replaced" : "Admin.Trash.Kind.Photos");
|
||||
}
|
||||
Reference in new issue
Block a user