E2: interfaccia delle copie esterne

Impostazioni → Esportazione (cartella generale, stesso post in due account,
cartelle degli account), finestra della cartella delle copie (scelta nativa
o sottocartelle di /esporta, tipi, nomi come la libreria o schema suo con
anteprima), blocco «Copie esterne» nelle impostazioni dell'account con
«Esporta questo account» e il conto dei file non ancora copiati.

«Copia in…» con il riepilogo del piano e «Copia di nuovo anche i tolti o
superati» (spento), dal menu dell'icona CSV, dalla barra della selezione,
dall'account e dal visore; filtro «Copie» ricordato nell'indirizzo, segno
sulle tessere, righe delle copie nel pannello File con «Copia di nuovo».
Dashboard con la scheda Esportazione: avanzamento, Interrompi, Riprendi,
lavori recenti e resoconto. Testi in it.json, stili in febe.css.

Serve a usare dall'interfaccia il motore e le API delle copie esterne
della tappa E2 (§4.10).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-27 12:15:40 +01:00
1 parent 4a7925ad23
commit 2306f5a453
14 files changed
+1596 -33

No files matched your search

+170 -3
View File
@@ -2,6 +2,9 @@
// the link to the profile; tabs Contenuti (Post, Storie as a regular 9:16 grid, In evidenza grouped by collection,
// Taggati, Profilo when there is more than one picture), Impostazioni (with «Con queste impostazioni» recomputed at
// every change and the fixed save bar) and Cronologia (the checks with their outcome).
// Copies to external folders (spec §4.10, tappa E2): in Contenuti the menu of the CSV icon, «Copia in…» in the
// selection bar and the «Copie» filter; in Impostazioni the block «Copie esterne» under «Cartella», with «Esporta
// questo account» (on unless switched off), the folder of the copies and «312 su 1.204 non ancora copiati».
import { api, download, withCarried } from '../core/api.js';
import { caps, serverNow } from '../core/context.js';
@@ -15,6 +18,7 @@ import { confirmDelete, selectionBar } from './library.js';
import { Mosaic, justify, tileElement, defaultDayLabel, filesDayLabel, modeSwitch, storedMode } from './mosaic.js';
import { kindName, orderEditor, orderOrDefault } from './download-order.js';
import { openViewer } from './viewer.js';
import { copiesApi, copiesLabel, copiesMenu, copyDialog, destinationDialog, exportButton, exportMenu, separator } from './export-dialogs.js';
const KINDS = [
{ key: 'post', api: 'posts', stat: 'posts', label: 'scheda.tipi.posts' },
@@ -108,6 +112,9 @@ async function contentsTab(page, route, detail) {
const available = KINDS.filter((k) => k.key !== 'profilo' || s.profilePictures > 1);
let kind = available.find((k) => k.key === route.query.get('tipo')) || available.find((k) => s[k.stat] > 0) || available[0];
let period = route.query.get('periodo') || '';
let copies = copiesApi(route.query.get('copie')) ? route.query.get('copie') : '';
// The «Copie» filter and «Copia in…» make sense once this account has a folder of the copies.
const hasDestination = Boolean(detail.export && detail.export.destination);
let mosaic = null;
// «Raggruppa i post» / «Tutte le foto» (spec §4.6): one choice for the views of every account, apart from the Libreria.
let mode = storedMode('account');
@@ -121,8 +128,10 @@ async function contentsTab(page, route, detail) {
let showToken = 0;
const chips = h('div.filtri', { role: 'group', 'aria-label': t('scheda.linguette.contenuti') });
const periodButton = h('button.campo.scelta', { type: 'button', 'aria-haspopup': 'true', 'aria-expanded': 'false', style: { minWidth: '150px' } });
const copiesButton = h('button.campo.scelta', { type: 'button', 'aria-haspopup': 'true', 'aria-expanded': 'false', hidden: !hasDestination && !copies, style: { minWidth: '96px' } });
const selectButton = h('button.btn', { type: 'button', 'aria-pressed': 'false' }, icon('circle-check'), h('span', t('libreria.seleziona')));
page.tools(h('div', { style: { display: 'contents' } }, chips, periodButton, h('div.destra', modes, selectButton)));
const csvButton = exportButton();
page.tools(h('div', { style: { display: 'contents' } }, chips, periodButton, copiesButton, h('div.destra', csvButton, modes, selectButton)));
const host = h('div');
fill(page.body, host);
@@ -136,6 +145,8 @@ async function contentsTab(page, route, detail) {
},
}, t(k.label), h('i', number(s[k.stat])))));
fill(periodButton, h('span.val', period ? t(`libreria.periodi.${period}`) : t('libreria.periodi.qualsiasi')), icon('chevron-down', 's'));
fill(copiesButton, h('span.val', copiesLabel(copies)), icon('chevron-down', 's'));
copiesButton.classList.toggle('attivo', Boolean(copies));
selectButton.hidden = kind.key === 'evidenza';
// «In evidenza» is drawn by collection, one tile per item (almost always a single story): no switch there.
modes.hidden = kind.key === 'evidenza';
@@ -149,8 +160,28 @@ async function contentsTab(page, route, detail) {
show();
}));
copiesButton.addEventListener('click', () => copiesMenu(copiesButton, copies, (value) => {
copies = value;
setQuery({ copie: value || null });
show();
}));
csvButton.addEventListener('click', () => exportMenu(csvButton, {
hasDestinations: hasDestination,
csv: async () => {
try {
await download('/api/entries/export', { query: query() }, 'febe-elementi.csv');
toast(t('libreria.esportatoFiltro'));
} catch (error) {
showError(error);
}
},
copy: () => copyDialog({ query: query(), mode: mode === 'files' ? 'files' : 'grouped' }),
}));
function query() {
const q = new URLSearchParams({ accounts: String(detail.account.id), kind: kind.api });
const copiesFilter = copiesApi(copies);
if (copiesFilter) q.set('copies', copiesFilter);
const today = caps().today;
const add = (n) => new Date(Date.parse(`${today}T12:00:00Z`) + n * 86400000).toISOString().slice(0, 10);
const year = Number(today.slice(0, 4));
@@ -177,6 +208,9 @@ async function contentsTab(page, route, detail) {
showError(error);
}
},
copySelected: hasDestination
? () => copyDialog(mosaic.files ? { mediaIds: [...mosaic.selected] } : { entryIds: mosaic.selectedEntries().ids })
: null,
deleteSelected: async () => {
const { ids, files } = mosaic.selectedEntries();
const removed = await confirmDelete(ids, mosaic.files ? { files: mosaic.selected.size, total: files } : null);
@@ -234,11 +268,16 @@ async function contentsTab(page, route, detail) {
}
const onChange = later(() => mosaic && mosaic.refresh().catch(() => {}), 500);
const onMarks = later(() => mosaic && mosaic.refreshMarks().catch(() => {}), 600);
page.onLibrary((change) => {
if (!change.accountId || change.accountId === detail.account.id) onChange();
if (!change.accountId || change.accountId === detail.account.id) {
onChange();
if (change.reason === 'export') onMarks();
}
});
page.onLeave(() => {
onChange.cancel();
onMarks.cancel();
if (mosaic) mosaic.destroy();
if (highlightCleanup) highlightCleanup();
});
@@ -467,7 +506,8 @@ function settingsTab(page, detail) {
h('div.riga-campi', depthExtra),
h('div', { style: { marginTop: '14px' } }, storyVideos)),
h('div.sezione', h('h2.sez', t('impAccount.cartella')), h('p.aiuto', t(c.foldersReadOnly ? 'impAccount.cartellaDocker' : 'impAccount.cartellaAiuto')),
h('div.cartella', h('div.campo.sola', icon('folder', 's'), folderValue), folderActions)));
h('div.cartella', h('div.campo.sola', icon('folder', 's'), folderValue), folderActions)),
copiesBlock(page, detail));
function drawPlan() {
const lines = plan.lines.map((l) => {
@@ -540,6 +580,133 @@ function settingsTab(page, detail) {
});
}
// --------------------------------------------------------------------------------------------- copie esterne
/**
* «Copie esterne» (spec §4.10, mockup 05): «Esporta questo account», which acts at once and is not part of the form
* (decision D1: on unless switched off), where the copies go, how many files are still to copy and «Copia in…».
*/
function copiesBlock(page, detail) {
const account = detail.account;
const box = h('div.sezione.copie-esterne');
let data = detail.export || { enabled: true, hasOwnFolder: false, destination: null, due: 0, notCopied: 0, removedOrSuperseded: 0, failed: 0 };
const body = h('div.copie-corpo');
const toggleBox = toggle({
checked: data.enabled,
label: t('esportazione.account.interruttore'),
onchange: async (value, input) => {
input.disabled = true;
try {
const result = await api(`/api/accounts/${account.id}/export-enabled`, { method: 'POST', body: { value } });
toast(result.message);
await reload();
} catch (error) {
input.checked = !value;
showError(error);
} finally {
input.disabled = false;
}
},
});
async function reload() {
try {
const fresh = await api(`/api/accounts/${account.id}`, { signal: page.signal });
data = fresh.export || data;
toggleBox.input.checked = data.enabled;
draw();
} catch (error) {
if (error.name !== 'AbortError') showError(error);
}
}
async function chooseOwn() {
const saved = await destinationDialog({ scope: 'account', accountId: account.id, username: account.username, destination: data.hasOwnFolder ? data.destination : null });
if (saved) await reload();
}
async function useGeneral() {
const general = data.hasOwnFolder && data.destination;
if (!general) return;
// Is there a general folder to fall back to? The overview says so.
let overview = null;
try {
overview = await api('/api/export');
} catch (error) {
showError(error);
return;
}
const fallback = Boolean(overview.general);
const ok = await confirmDialog({
title: t(fallback ? 'esportazione.account.usaGeneraleTitolo' : 'esportazione.account.togliTitolo', { nome: account.username }),
text: t(fallback ? 'esportazione.account.usaGeneraleTesto' : 'esportazione.account.togliTesto'),
buttons: [
{ label: t('comune.annulla'), value: false, kind: 'nudo', autofocus: true },
{ label: t(fallback ? 'esportazione.account.usaGenerale' : 'esportazione.togliSi'), value: true, kind: fallback ? 'primo' : 'pericolo' },
],
});
if (!ok) return;
try {
const result = await api(`/api/export/destinations/${data.destination.id}`, { method: 'DELETE' });
toast(result.message);
await reload();
} catch (error) {
showError(error);
}
}
function draw() {
const d = data.destination;
const rows = [];
if (d) {
const where = data.hasOwnFolder ? d.display : `${d.display}${separator(d.display)}${account.username}`;
rows.push(h('div.cartella',
h('div.campo.sola', { title: where }, icon('hard-drive', 's'),
h('span.val', h('span.muto', `${t(data.hasOwnFolder ? 'esportazione.account.sua' : 'esportazione.account.generale')}: `), h('span.dati', where))),
data.hasOwnFolder
? [h('button.btn', { type: 'button', onclick: chooseOwn }, t('esportazione.modifica')),
h('button.btn.nudo', { type: 'button', onclick: useGeneral }, t('esportazione.account.usaGenerale'))]
: h('button.btn', { type: 'button', onclick: chooseOwn }, t('esportazione.account.scegliSua'))));
if (d.pausedAt || d.problem) {
rows.push(h('div.avviso.ambra', { style: { marginTop: '10px' } }, icon('pause', 's'), h('span', t('esportazione.pausa', { problema: d.problem || '' }))));
}
} else {
rows.push(h('div.cartella',
h('div.campo.sola', icon('folder', 's'), h('span.val.tenue', t('esportazione.nessunaCartella'))),
h('button.btn', { type: 'button', onclick: chooseOwn }, t('esportazione.account.scegliSua'))),
h('p.aiuto', { style: { marginTop: '8px' } }, t('esportazione.account.nessuna')));
}
if (!data.enabled) {
rows.push(h('p.aiuto.conteggio-copie', icon('info', 'xs'), ' ', t('esportazione.account.spento')));
} else if (d) {
let count;
if (!data.due) count = t('esportazione.account.nessunFile');
else if (!data.notCopied) count = t('esportazione.account.tuttiCopiati', { n: data.due });
else count = t('esportazione.account.conteggio', { n: data.notCopied, totale: data.due });
const extra = [];
if (data.removedOrSuperseded) extra.push(t('esportazione.account.tolti', { n: data.removedOrSuperseded }));
if (data.failed) extra.push(t('esportazione.account.falliti', { n: data.failed }));
rows.push(h('div.riga-conteggi.conteggio-copie',
h('span', h('b', count), extra.length ? ` · ${extra.join(' · ')}` : ''),
h('button.btn', { type: 'button', onclick: () => copyDialog({ accountId: account.id }, { title: t('esportazione.copia.titolo') }) }, icon('copy'), t('esportazione.account.copiaIn'))));
}
fill(body, rows);
}
draw();
fill(box,
h('h2.sez', t('esportazione.account.titolo')),
h('p.aiuto', t('esportazione.account.aiuto')),
h('div', { style: { margin: '12px 0 4px' } }, toggleBox),
body);
const onChange = later(() => reload(), 600);
page.onLibrary((change) => {
if (change.reason === 'export' && (!change.accountId || change.accountId === account.id)) onChange();
});
page.onLeave(() => onChange.cancel());
return box;
}
// --------------------------------------------------------------------------------------------- history
async function historyTab(page, detail) {