feat(ui): aggiunge anteprima desktop dei file non smistati

This commit is contained in:
2026-03-16 10:11:59 +01:00
parent 164959acaf
commit 3a567c390c
5 changed files with 198 additions and 1 deletions

View File

@@ -5,7 +5,12 @@ const output = document.getElementById('output');
const destinationInput = document.getElementById('destinationInput');
const browseDestinationBtn = document.getElementById('browseDestinationBtn');
const saveDestinationBtn = document.getElementById('saveDestinationBtn');
const openUnroutedBtn = document.getElementById('openUnroutedBtn');
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 defaultDropZoneText = 'Trascina qui una cartella o un file .zip';
let isProcessing = false;
@@ -18,6 +23,31 @@ function setDestinationLoading(isLoading) {
destinationInput.disabled = isLoading;
browseDestinationBtn.disabled = isLoading;
saveDestinationBtn.disabled = isLoading;
openUnroutedBtn.disabled = isLoading;
}
function formatBytes(bytes) {
const value = Number(bytes || 0);
if (value < 1024) return `${value} B`;
if (value < 1024 * 1024) return `${(value / 1024).toFixed(1)} KB`;
if (value < 1024 * 1024 * 1024) return `${(value / (1024 * 1024)).toFixed(1)} MB`;
return `${(value / (1024 * 1024 * 1024)).toFixed(1)} GB`;
}
function showUnroutedPreview(payload) {
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.';
unroutedPreviewMeta.textContent = `cartella: ${directory} | file totali: ${files.length}`;
unroutedPreviewList.textContent = lines;
unroutedPreviewOverlay.classList.add('visible');
}
function hideUnroutedPreview() {
unroutedPreviewOverlay.classList.remove('visible');
}
function renderResult(title, result) {
@@ -166,6 +196,34 @@ saveDestinationBtn.addEventListener('click', async () => {
}
});
openUnroutedBtn.addEventListener('click', async () => {
try {
setDestinationLoading(true);
destinationStatus.textContent = 'Caricamento anteprima non smistati...';
const result = await window.api.listUnroutedFiles();
showUnroutedPreview(result);
destinationStatus.textContent = `Anteprima caricata (${result.files?.length || 0} file).`;
} catch (error) {
destinationStatus.textContent = `Errore: ${error.message}`;
} finally {
setDestinationLoading(false);
}
});
closeUnroutedPreviewBtn.addEventListener('click', hideUnroutedPreview);
unroutedPreviewOverlay.addEventListener('click', (event) => {
if (event.target === unroutedPreviewOverlay) {
hideUnroutedPreview();
}
});
window.addEventListener('keydown', (event) => {
if (event.key === 'Escape' && unroutedPreviewOverlay.classList.contains('visible')) {
hideUnroutedPreview();
}
});
async function initConfigUI() {
try {
const destinationResult = await window.api.getDestination();