feat(ui): anteprima duplicati/non smistati con pulizia cartella confermata
This commit is contained in:
11
main.js
11
main.js
@@ -4,7 +4,13 @@ const fs = require('fs-extra');
|
|||||||
|
|
||||||
const { processFolder } = require('./services/folderProcessor');
|
const { processFolder } = require('./services/folderProcessor');
|
||||||
const { processZip } = require('./services/zipProcessor');
|
const { processZip } = require('./services/zipProcessor');
|
||||||
const { resolveUnroutedDir, listUnroutedFiles } = require('./services/unrouted');
|
const {
|
||||||
|
resolveUnroutedDir,
|
||||||
|
listUnroutedFiles,
|
||||||
|
listDuplicateFiles,
|
||||||
|
clearUnroutedFiles,
|
||||||
|
clearDuplicateFiles,
|
||||||
|
} = require('./services/unrouted');
|
||||||
|
|
||||||
const CAD_EXTENSIONS = ['prt', 'asm', 'dwr'];
|
const CAD_EXTENSIONS = ['prt', 'asm', 'dwr'];
|
||||||
const DEFAULT_DESTINATION = './output/cad';
|
const DEFAULT_DESTINATION = './output/cad';
|
||||||
@@ -182,3 +188,6 @@ ipcMain.handle('open-unrouted-folder', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle('list-unrouted-files', async () => listUnroutedFiles());
|
ipcMain.handle('list-unrouted-files', async () => listUnroutedFiles());
|
||||||
|
ipcMain.handle('list-duplicates-files', async () => listDuplicateFiles());
|
||||||
|
ipcMain.handle('clear-unrouted-files', async () => clearUnroutedFiles());
|
||||||
|
ipcMain.handle('clear-duplicates-files', async () => clearDuplicateFiles());
|
||||||
|
|||||||
@@ -10,4 +10,7 @@ contextBridge.exposeInMainWorld('api', {
|
|||||||
updateDestination: (destination) => ipcRenderer.invoke('update-destination', { destination }),
|
updateDestination: (destination) => ipcRenderer.invoke('update-destination', { destination }),
|
||||||
openUnroutedFolder: () => ipcRenderer.invoke('open-unrouted-folder'),
|
openUnroutedFolder: () => ipcRenderer.invoke('open-unrouted-folder'),
|
||||||
listUnroutedFiles: () => ipcRenderer.invoke('list-unrouted-files'),
|
listUnroutedFiles: () => ipcRenderer.invoke('list-unrouted-files'),
|
||||||
|
listDuplicatesFiles: () => ipcRenderer.invoke('list-duplicates-files'),
|
||||||
|
clearUnroutedFiles: () => ipcRenderer.invoke('clear-unrouted-files'),
|
||||||
|
clearDuplicatesFiles: () => ipcRenderer.invoke('clear-duplicates-files'),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -133,6 +133,11 @@
|
|||||||
margin-top: 10px;
|
margin-top: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.rule-row.preview-actions {
|
||||||
|
grid-template-columns: auto auto;
|
||||||
|
justify-content: start;
|
||||||
|
}
|
||||||
|
|
||||||
.rule-label {
|
.rule-label {
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
color: var(--muted);
|
color: var(--muted);
|
||||||
@@ -195,11 +200,21 @@
|
|||||||
gap: 10px;
|
gap: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.preview-header-actions {
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
.preview-header h2 {
|
.preview-header h2 {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.danger {
|
||||||
|
background: #b91c1c;
|
||||||
|
}
|
||||||
|
|
||||||
.preview-meta {
|
.preview-meta {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
color: var(--muted);
|
color: var(--muted);
|
||||||
@@ -259,22 +274,26 @@
|
|||||||
<button id="browseDestinationBtn" class="browse">Sfoglia</button>
|
<button id="browseDestinationBtn" class="browse">Sfoglia</button>
|
||||||
<button id="saveDestinationBtn">Salva</button>
|
<button id="saveDestinationBtn">Salva</button>
|
||||||
</div>
|
</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="openUnroutedBtn" class="browse">Anteprima non smistati</button>
|
||||||
|
<button id="openDuplicatesBtn" class="browse">Anteprima duplicati</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="rule-status" id="destinationStatus"></div>
|
<div class="rule-status" id="destinationStatus"></div>
|
||||||
</section>
|
</section>
|
||||||
<pre id="output">Pronto.</pre>
|
<pre id="output">Pronto.</pre>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<section class="preview-overlay" id="unroutedPreviewOverlay">
|
<section class="preview-overlay" id="previewOverlay">
|
||||||
<article class="preview-card">
|
<article class="preview-card">
|
||||||
<div class="preview-header">
|
<div class="preview-header">
|
||||||
<h2>Anteprima __NON_SMISTATI</h2>
|
<h2 id="previewTitle">Anteprima</h2>
|
||||||
<button id="closeUnroutedPreviewBtn" class="secondary">Chiudi</button>
|
<div class="preview-header-actions">
|
||||||
|
<button id="clearPreviewBtn" class="danger">Pulisci cartella</button>
|
||||||
|
<button id="closePreviewBtn" class="secondary">Chiudi</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="preview-meta" id="unroutedPreviewMeta"></div>
|
<div class="preview-meta" id="previewMeta"></div>
|
||||||
<pre class="preview-list" id="unroutedPreviewList">Nessun dato.</pre>
|
<pre class="preview-list" id="previewList">Nessun dato.</pre>
|
||||||
</article>
|
</article>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
@@ -6,13 +6,17 @@ const destinationInput = document.getElementById('destinationInput');
|
|||||||
const browseDestinationBtn = document.getElementById('browseDestinationBtn');
|
const browseDestinationBtn = document.getElementById('browseDestinationBtn');
|
||||||
const saveDestinationBtn = document.getElementById('saveDestinationBtn');
|
const saveDestinationBtn = document.getElementById('saveDestinationBtn');
|
||||||
const openUnroutedBtn = document.getElementById('openUnroutedBtn');
|
const openUnroutedBtn = document.getElementById('openUnroutedBtn');
|
||||||
|
const openDuplicatesBtn = document.getElementById('openDuplicatesBtn');
|
||||||
const destinationStatus = document.getElementById('destinationStatus');
|
const destinationStatus = document.getElementById('destinationStatus');
|
||||||
const unroutedPreviewOverlay = document.getElementById('unroutedPreviewOverlay');
|
const previewOverlay = document.getElementById('previewOverlay');
|
||||||
const closeUnroutedPreviewBtn = document.getElementById('closeUnroutedPreviewBtn');
|
const closePreviewBtn = document.getElementById('closePreviewBtn');
|
||||||
const unroutedPreviewMeta = document.getElementById('unroutedPreviewMeta');
|
const clearPreviewBtn = document.getElementById('clearPreviewBtn');
|
||||||
const unroutedPreviewList = document.getElementById('unroutedPreviewList');
|
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';
|
const defaultDropZoneText = 'Trascina qui una cartella o un file .zip';
|
||||||
let isProcessing = false;
|
let isProcessing = false;
|
||||||
|
let currentPreviewKind = null;
|
||||||
|
|
||||||
function setLoading(isLoading) {
|
function setLoading(isLoading) {
|
||||||
folderBtn.disabled = isLoading;
|
folderBtn.disabled = isLoading;
|
||||||
@@ -24,6 +28,8 @@ function setDestinationLoading(isLoading) {
|
|||||||
browseDestinationBtn.disabled = isLoading;
|
browseDestinationBtn.disabled = isLoading;
|
||||||
saveDestinationBtn.disabled = isLoading;
|
saveDestinationBtn.disabled = isLoading;
|
||||||
openUnroutedBtn.disabled = isLoading;
|
openUnroutedBtn.disabled = isLoading;
|
||||||
|
openDuplicatesBtn.disabled = isLoading;
|
||||||
|
clearPreviewBtn.disabled = isLoading;
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatBytes(bytes) {
|
function formatBytes(bytes) {
|
||||||
@@ -34,20 +40,39 @@ function formatBytes(bytes) {
|
|||||||
return `${(value / (1024 * 1024 * 1024)).toFixed(1)} GB`;
|
return `${(value / (1024 * 1024 * 1024)).toFixed(1)} GB`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function showUnroutedPreview(payload) {
|
function showPreview(kind, title, payload, emptyMessage) {
|
||||||
const files = payload?.files || [];
|
const files = payload?.files || [];
|
||||||
const directory = payload?.directory || '';
|
const directory = payload?.directory || '';
|
||||||
const lines = files.length
|
const lines = files.length
|
||||||
? files.map((file) => `- ${file.relativePath} | ${formatBytes(file.size)}`).join('\n')
|
? 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}`;
|
currentPreviewKind = kind;
|
||||||
unroutedPreviewList.textContent = lines;
|
previewTitle.textContent = title;
|
||||||
unroutedPreviewOverlay.classList.add('visible');
|
previewMeta.textContent = `cartella: ${directory} | file totali: ${files.length}`;
|
||||||
|
previewList.textContent = lines;
|
||||||
|
previewOverlay.classList.add('visible');
|
||||||
}
|
}
|
||||||
|
|
||||||
function hideUnroutedPreview() {
|
function hidePreview() {
|
||||||
unroutedPreviewOverlay.classList.remove('visible');
|
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) {
|
function renderResult(title, result) {
|
||||||
@@ -64,6 +89,7 @@ function renderResult(title, result) {
|
|||||||
`copiati: ${result.copied ?? 0}`,
|
`copiati: ${result.copied ?? 0}`,
|
||||||
`saltati: ${result.skipped ?? 0}`,
|
`saltati: ${result.skipped ?? 0}`,
|
||||||
`non smistati: ${result.unrouted ?? 0}`,
|
`non smistati: ${result.unrouted ?? 0}`,
|
||||||
|
`duplicati: ${result.duplicates ?? 0}`,
|
||||||
'',
|
'',
|
||||||
'dettagli (max 20):',
|
'dettagli (max 20):',
|
||||||
detailsText,
|
detailsText,
|
||||||
@@ -202,7 +228,12 @@ openUnroutedBtn.addEventListener('click', async () => {
|
|||||||
destinationStatus.textContent = 'Caricamento anteprima non smistati...';
|
destinationStatus.textContent = 'Caricamento anteprima non smistati...';
|
||||||
|
|
||||||
const result = await window.api.listUnroutedFiles();
|
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).`;
|
destinationStatus.textContent = `Anteprima caricata (${result.files?.length || 0} file).`;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
destinationStatus.textContent = `Errore: ${error.message}`;
|
destinationStatus.textContent = `Errore: ${error.message}`;
|
||||||
@@ -211,16 +242,65 @@ openUnroutedBtn.addEventListener('click', async () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
closeUnroutedPreviewBtn.addEventListener('click', hideUnroutedPreview);
|
openDuplicatesBtn.addEventListener('click', async () => {
|
||||||
unroutedPreviewOverlay.addEventListener('click', (event) => {
|
try {
|
||||||
if (event.target === unroutedPreviewOverlay) {
|
setDestinationLoading(true);
|
||||||
hideUnroutedPreview();
|
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) => {
|
window.addEventListener('keydown', (event) => {
|
||||||
if (event.key === 'Escape' && unroutedPreviewOverlay.classList.contains('visible')) {
|
if (event.key === 'Escape' && previewOverlay.classList.contains('visible')) {
|
||||||
hideUnroutedPreview();
|
hidePreview();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user