feat(ui): anteprima duplicati/non smistati con pulizia cartella confermata
This commit is contained in:
@@ -6,13 +6,17 @@ const destinationInput = document.getElementById('destinationInput');
|
||||
const browseDestinationBtn = document.getElementById('browseDestinationBtn');
|
||||
const saveDestinationBtn = document.getElementById('saveDestinationBtn');
|
||||
const openUnroutedBtn = document.getElementById('openUnroutedBtn');
|
||||
const openDuplicatesBtn = document.getElementById('openDuplicatesBtn');
|
||||
const destinationStatus = document.getElementById('destinationStatus');
|
||||
const unroutedPreviewOverlay = document.getElementById('unroutedPreviewOverlay');
|
||||
const closeUnroutedPreviewBtn = document.getElementById('closeUnroutedPreviewBtn');
|
||||
const unroutedPreviewMeta = document.getElementById('unroutedPreviewMeta');
|
||||
const unroutedPreviewList = document.getElementById('unroutedPreviewList');
|
||||
const previewOverlay = document.getElementById('previewOverlay');
|
||||
const closePreviewBtn = document.getElementById('closePreviewBtn');
|
||||
const clearPreviewBtn = document.getElementById('clearPreviewBtn');
|
||||
const previewTitle = document.getElementById('previewTitle');
|
||||
const previewMeta = document.getElementById('previewMeta');
|
||||
const previewList = document.getElementById('previewList');
|
||||
const defaultDropZoneText = 'Trascina qui una cartella o un file .zip';
|
||||
let isProcessing = false;
|
||||
let currentPreviewKind = null;
|
||||
|
||||
function setLoading(isLoading) {
|
||||
folderBtn.disabled = isLoading;
|
||||
@@ -24,6 +28,8 @@ function setDestinationLoading(isLoading) {
|
||||
browseDestinationBtn.disabled = isLoading;
|
||||
saveDestinationBtn.disabled = isLoading;
|
||||
openUnroutedBtn.disabled = isLoading;
|
||||
openDuplicatesBtn.disabled = isLoading;
|
||||
clearPreviewBtn.disabled = isLoading;
|
||||
}
|
||||
|
||||
function formatBytes(bytes) {
|
||||
@@ -34,20 +40,39 @@ function formatBytes(bytes) {
|
||||
return `${(value / (1024 * 1024 * 1024)).toFixed(1)} GB`;
|
||||
}
|
||||
|
||||
function showUnroutedPreview(payload) {
|
||||
function showPreview(kind, title, payload, emptyMessage) {
|
||||
const files = payload?.files || [];
|
||||
const directory = payload?.directory || '';
|
||||
const lines = files.length
|
||||
? files.map((file) => `- ${file.relativePath} | ${formatBytes(file.size)}`).join('\n')
|
||||
: 'Nessun file presente in __NON_SMISTATI.';
|
||||
: emptyMessage;
|
||||
|
||||
unroutedPreviewMeta.textContent = `cartella: ${directory} | file totali: ${files.length}`;
|
||||
unroutedPreviewList.textContent = lines;
|
||||
unroutedPreviewOverlay.classList.add('visible');
|
||||
currentPreviewKind = kind;
|
||||
previewTitle.textContent = title;
|
||||
previewMeta.textContent = `cartella: ${directory} | file totali: ${files.length}`;
|
||||
previewList.textContent = lines;
|
||||
previewOverlay.classList.add('visible');
|
||||
}
|
||||
|
||||
function hideUnroutedPreview() {
|
||||
unroutedPreviewOverlay.classList.remove('visible');
|
||||
function hidePreview() {
|
||||
currentPreviewKind = null;
|
||||
previewOverlay.classList.remove('visible');
|
||||
}
|
||||
|
||||
async function loadPreviewData(kind) {
|
||||
if (kind === 'duplicates') {
|
||||
return window.api.listDuplicatesFiles();
|
||||
}
|
||||
|
||||
return window.api.listUnroutedFiles();
|
||||
}
|
||||
|
||||
async function clearPreviewData(kind) {
|
||||
if (kind === 'duplicates') {
|
||||
return window.api.clearDuplicatesFiles();
|
||||
}
|
||||
|
||||
return window.api.clearUnroutedFiles();
|
||||
}
|
||||
|
||||
function renderResult(title, result) {
|
||||
@@ -64,6 +89,7 @@ function renderResult(title, result) {
|
||||
`copiati: ${result.copied ?? 0}`,
|
||||
`saltati: ${result.skipped ?? 0}`,
|
||||
`non smistati: ${result.unrouted ?? 0}`,
|
||||
`duplicati: ${result.duplicates ?? 0}`,
|
||||
'',
|
||||
'dettagli (max 20):',
|
||||
detailsText,
|
||||
@@ -202,7 +228,12 @@ openUnroutedBtn.addEventListener('click', async () => {
|
||||
destinationStatus.textContent = 'Caricamento anteprima non smistati...';
|
||||
|
||||
const result = await window.api.listUnroutedFiles();
|
||||
showUnroutedPreview(result);
|
||||
showPreview(
|
||||
'unrouted',
|
||||
'Anteprima __NON_SMISTATI',
|
||||
result,
|
||||
'Nessun file presente in __NON_SMISTATI.'
|
||||
);
|
||||
destinationStatus.textContent = `Anteprima caricata (${result.files?.length || 0} file).`;
|
||||
} catch (error) {
|
||||
destinationStatus.textContent = `Errore: ${error.message}`;
|
||||
@@ -211,16 +242,65 @@ openUnroutedBtn.addEventListener('click', async () => {
|
||||
}
|
||||
});
|
||||
|
||||
closeUnroutedPreviewBtn.addEventListener('click', hideUnroutedPreview);
|
||||
unroutedPreviewOverlay.addEventListener('click', (event) => {
|
||||
if (event.target === unroutedPreviewOverlay) {
|
||||
hideUnroutedPreview();
|
||||
openDuplicatesBtn.addEventListener('click', async () => {
|
||||
try {
|
||||
setDestinationLoading(true);
|
||||
destinationStatus.textContent = 'Caricamento anteprima duplicati...';
|
||||
|
||||
const result = await window.api.listDuplicatesFiles();
|
||||
showPreview('duplicates', 'Anteprima duplicati', result, 'Nessun file presente in duplicati.');
|
||||
destinationStatus.textContent = `Anteprima caricata (${result.files?.length || 0} file).`;
|
||||
} catch (error) {
|
||||
destinationStatus.textContent = `Errore: ${error.message}`;
|
||||
} finally {
|
||||
setDestinationLoading(false);
|
||||
}
|
||||
});
|
||||
|
||||
clearPreviewBtn.addEventListener('click', async () => {
|
||||
if (!currentPreviewKind) {
|
||||
return;
|
||||
}
|
||||
|
||||
const isDuplicates = currentPreviewKind === 'duplicates';
|
||||
const confirmMessage = isDuplicates
|
||||
? 'Confermi la pulizia della cartella duplicati?'
|
||||
: 'Confermi la pulizia della cartella non smistati?';
|
||||
|
||||
if (!window.confirm(confirmMessage)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
setDestinationLoading(true);
|
||||
destinationStatus.textContent = 'Pulizia cartella in corso...';
|
||||
|
||||
const clearResult = await clearPreviewData(currentPreviewKind);
|
||||
const refreshed = await loadPreviewData(currentPreviewKind);
|
||||
const title = isDuplicates ? 'Anteprima duplicati' : 'Anteprima __NON_SMISTATI';
|
||||
const emptyMessage = isDuplicates
|
||||
? 'Nessun file presente in duplicati.'
|
||||
: 'Nessun file presente in __NON_SMISTATI.';
|
||||
|
||||
showPreview(currentPreviewKind, title, refreshed, emptyMessage);
|
||||
destinationStatus.textContent = `Cartella pulita: ${clearResult.directory}`;
|
||||
} catch (error) {
|
||||
destinationStatus.textContent = `Errore: ${error.message}`;
|
||||
} finally {
|
||||
setDestinationLoading(false);
|
||||
}
|
||||
});
|
||||
|
||||
closePreviewBtn.addEventListener('click', hidePreview);
|
||||
previewOverlay.addEventListener('click', (event) => {
|
||||
if (event.target === previewOverlay) {
|
||||
hidePreview();
|
||||
}
|
||||
});
|
||||
|
||||
window.addEventListener('keydown', (event) => {
|
||||
if (event.key === 'Escape' && unroutedPreviewOverlay.classList.contains('visible')) {
|
||||
hideUnroutedPreview();
|
||||
if (event.key === 'Escape' && previewOverlay.classList.contains('visible')) {
|
||||
hidePreview();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user