feat(ui): anteprima duplicati/non smistati con pulizia cartella confermata
This commit is contained in:
@@ -133,6 +133,11 @@
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.rule-row.preview-actions {
|
||||
grid-template-columns: auto auto;
|
||||
justify-content: start;
|
||||
}
|
||||
|
||||
.rule-label {
|
||||
font-size: 13px;
|
||||
color: var(--muted);
|
||||
@@ -195,11 +200,21 @@
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.preview-header-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.preview-header h2 {
|
||||
margin: 0;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.danger {
|
||||
background: #b91c1c;
|
||||
}
|
||||
|
||||
.preview-meta {
|
||||
font-size: 12px;
|
||||
color: var(--muted);
|
||||
@@ -259,22 +274,26 @@
|
||||
<button id="browseDestinationBtn" class="browse">Sfoglia</button>
|
||||
<button id="saveDestinationBtn">Salva</button>
|
||||
</div>
|
||||
<div class="rule-row single-row">
|
||||
<div class="rule-row single-row preview-actions">
|
||||
<button id="openUnroutedBtn" class="browse">Anteprima non smistati</button>
|
||||
<button id="openDuplicatesBtn" class="browse">Anteprima duplicati</button>
|
||||
</div>
|
||||
<div class="rule-status" id="destinationStatus"></div>
|
||||
</section>
|
||||
<pre id="output">Pronto.</pre>
|
||||
</main>
|
||||
|
||||
<section class="preview-overlay" id="unroutedPreviewOverlay">
|
||||
<section class="preview-overlay" id="previewOverlay">
|
||||
<article class="preview-card">
|
||||
<div class="preview-header">
|
||||
<h2>Anteprima __NON_SMISTATI</h2>
|
||||
<button id="closeUnroutedPreviewBtn" class="secondary">Chiudi</button>
|
||||
<h2 id="previewTitle">Anteprima</h2>
|
||||
<div class="preview-header-actions">
|
||||
<button id="clearPreviewBtn" class="danger">Pulisci cartella</button>
|
||||
<button id="closePreviewBtn" class="secondary">Chiudi</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="preview-meta" id="unroutedPreviewMeta"></div>
|
||||
<pre class="preview-list" id="unroutedPreviewList">Nessun dato.</pre>
|
||||
<div class="preview-meta" id="previewMeta"></div>
|
||||
<pre class="preview-list" id="previewList">Nessun dato.</pre>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
|
||||
@@ -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