feat: unifica lo smistamento CAD su destinazione unica configurabile da UI
This commit is contained in:
@@ -1,13 +1,22 @@
|
||||
const folderBtn = document.getElementById('folderBtn');
|
||||
const zipBtn = document.getElementById('zipBtn');
|
||||
const output = document.getElementById('output');
|
||||
const configInfo = document.getElementById('configInfo');
|
||||
const destinationInput = document.getElementById('destinationInput');
|
||||
const browseDestinationBtn = document.getElementById('browseDestinationBtn');
|
||||
const saveDestinationBtn = document.getElementById('saveDestinationBtn');
|
||||
const destinationStatus = document.getElementById('destinationStatus');
|
||||
|
||||
function setLoading(isLoading) {
|
||||
folderBtn.disabled = isLoading;
|
||||
zipBtn.disabled = isLoading;
|
||||
}
|
||||
|
||||
function setDestinationLoading(isLoading) {
|
||||
destinationInput.disabled = isLoading;
|
||||
browseDestinationBtn.disabled = isLoading;
|
||||
saveDestinationBtn.disabled = isLoading;
|
||||
}
|
||||
|
||||
function renderResult(title, result) {
|
||||
const details = (result.details || []).slice(0, 20);
|
||||
const detailsText = details.length
|
||||
@@ -50,6 +59,55 @@ async function handleAction(actionName, actionFn) {
|
||||
folderBtn.addEventListener('click', () => handleAction('Process Folder', window.api.selectFolder));
|
||||
zipBtn.addEventListener('click', () => handleAction('Process ZIP', window.api.selectZip));
|
||||
|
||||
window.api.getConfigPath().then(({ configPath }) => {
|
||||
configInfo.textContent = `Config utente: ${configPath}`;
|
||||
browseDestinationBtn.addEventListener('click', async () => {
|
||||
try {
|
||||
setDestinationLoading(true);
|
||||
destinationStatus.textContent = 'Seleziona una cartella...';
|
||||
|
||||
const result = await window.api.selectDestinationFolder();
|
||||
if (!result || result.canceled) {
|
||||
destinationStatus.textContent = 'Selezione annullata.';
|
||||
return;
|
||||
}
|
||||
|
||||
destinationInput.value = result.path;
|
||||
destinationStatus.textContent = 'Cartella selezionata. Premi Salva.';
|
||||
} catch (error) {
|
||||
destinationStatus.textContent = `Errore: ${error.message}`;
|
||||
} finally {
|
||||
setDestinationLoading(false);
|
||||
}
|
||||
});
|
||||
|
||||
saveDestinationBtn.addEventListener('click', async () => {
|
||||
const destination = destinationInput.value.trim();
|
||||
if (!destination) {
|
||||
destinationStatus.textContent = 'Inserisci una destinazione valida.';
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
setDestinationLoading(true);
|
||||
destinationStatus.textContent = 'Salvataggio in corso...';
|
||||
|
||||
const result = await window.api.updateDestination(destination);
|
||||
destinationInput.value = result.destination;
|
||||
destinationStatus.textContent = 'Destinazione salvata.';
|
||||
} catch (error) {
|
||||
destinationStatus.textContent = `Errore: ${error.message}`;
|
||||
} finally {
|
||||
setDestinationLoading(false);
|
||||
}
|
||||
});
|
||||
|
||||
async function initConfigUI() {
|
||||
try {
|
||||
const destinationResult = await window.api.getDestination();
|
||||
destinationInput.value = destinationResult.destination || '';
|
||||
destinationStatus.textContent = '';
|
||||
} catch (error) {
|
||||
destinationStatus.textContent = 'Impossibile caricare la destinazione.';
|
||||
}
|
||||
}
|
||||
|
||||
initConfigUI();
|
||||
|
||||
Reference in New Issue
Block a user