211 lines
10 KiB
PHP
211 lines
10 KiB
PHP
<div class="netgescon-card">
|
|
<div class="netgescon-card-header flex justify-between items-center">
|
|
<h3 class="card-title mb-0"><i class="mdi mdi-city me-2"></i> Comuni (Legacy → Staging → NetGescon)</h3>
|
|
<div class="flex gap-2">
|
|
<button type="button" class="netgescon-btn netgescon-btn-sm netgescon-btn-outline-primary" onclick="openStagingPanel_comuni()">
|
|
<i class="mdi mdi-database-import"></i> Staging MDB
|
|
</button>
|
|
</div>
|
|
</div>
|
|
<div class="netgescon-card-body">
|
|
<p class="text-gray-500 text-sm">Importa i comuni da <code>/home/michele/netgescon/docs/02-architettura-laravel/Gescon/strutture/codici_comuni.mdb</code> nel DB di staging e mappa le colonne verso i campi bersaglio NetGescon.</p>
|
|
|
|
<x-netgescon.two-cards :left-title="'Campi Legacy (Comuni)'" :right-title="'Campi Target (NetGescon)'"><x-slot name="left">
|
|
<ul class="list-group">
|
|
<li class="list-group-item flex justify-between items-center">
|
|
<div>
|
|
<div class="fw-semibold">Codice Comune</div>
|
|
<small class="text-gray-500">codice_comune</small>
|
|
</div>
|
|
<div class="small font-monospace">—</div>
|
|
</li>
|
|
<li class="list-group-item flex justify-between items-center">
|
|
<div>
|
|
<div class="fw-semibold">Denominazione</div>
|
|
<small class="text-gray-500">denominazione</small>
|
|
</div>
|
|
<div class="small font-monospace">—</div>
|
|
</li>
|
|
<li class="list-group-item flex justify-between items-center">
|
|
<div>
|
|
<div class="fw-semibold">Provincia</div>
|
|
<small class="text-gray-500">provincia</small>
|
|
</div>
|
|
<div class="small font-monospace">—</div>
|
|
</li>
|
|
</ul>
|
|
</x-slot>
|
|
<x-slot name="right">
|
|
<div class="mb-3">
|
|
<label class="form-label">Codice → Target</label>
|
|
<select class="netgescon-input">
|
|
<option>— Seleziona —</option>
|
|
<option value="comune.cod">Comune → Codice</option>
|
|
<option value="comune.denominazione">Comune → Denominazione</option>
|
|
<option value="comune.provincia">Comune → Provincia</option>
|
|
</select>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label class="form-label">Denominazione → Target</label>
|
|
<select class="netgescon-input">
|
|
<option>— Seleziona —</option>
|
|
<option value="comune.denominazione">Comune → Denominazione</option>
|
|
<option value="comune.cod">Comune → Codice</option>
|
|
</select>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label class="form-label">Provincia → Target</label>
|
|
<select class="netgescon-input">
|
|
<option>— Seleziona —</option>
|
|
<option value="comune.provincia">Comune → Provincia</option>
|
|
<option value="comune.denominazione">Comune → Denominazione</option>
|
|
</select>
|
|
</div>
|
|
<div class="text-end">
|
|
<button type="button" class="netgescon-btn netgescon-btn-primary">Salva Mapping Comuni</button>
|
|
</div>
|
|
</x-slot></x-netgescon.two-cards>
|
|
<hr class="my-4"/>
|
|
<div class="netgescon-card mt-3">
|
|
<div class="netgescon-card-header flex justify-between items-center">
|
|
<strong><i class="mdi mdi-progress-check me-2"></i> Import Comuni da Staging → comuni_italiani</strong>
|
|
<small class="text-gray-500">Seleziona la tabella mdb_% di staging e avvia l'importazione a chunk con stato in tempo reale</small>
|
|
</div>
|
|
<div class="netgescon-card-body">
|
|
<div class="grid md:grid-cols-12 gap-3 items-end">
|
|
<div class="col-span-12 md:col-span-6">
|
|
<label class="form-label small">Tabella di staging</label>
|
|
<div class="flex gap-2">
|
|
<select id="comuni-staging-table" class="netgescon-input">
|
|
<option value="">— Carico… —</option>
|
|
</select>
|
|
<button type="button" class="netgescon-btn netgescon-btn-outline-secondary" id="btn-refresh-staging">Aggiorna</button>
|
|
</div>
|
|
</div>
|
|
<div class="col-span-6 md:col-span-3">
|
|
<label class="form-label small">Chunk size</label>
|
|
<input type="number" id="comuni-chunk" class="netgescon-input" value="500" min="50" max="2000" step="50"/>
|
|
</div>
|
|
<div class="col-span-6 md:col-span-3 text-right">
|
|
<div class="flex gap-2 justify-end">
|
|
<button type="button" class="netgescon-btn netgescon-btn-primary" id="btn-start-comuni">Avvia</button>
|
|
<button type="button" class="netgescon-btn netgescon-btn-outline-secondary" id="btn-pause-comuni" disabled>Pausa</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mt-3">
|
|
<div class="text-sm text-gray-500 mb-1">Avanzamento</div>
|
|
<div class="progress" style="height: 18px;">
|
|
<div id="comuni-progress-bar" class="progress-bar" role="progressbar" style="width: 0%;" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">0%</div>
|
|
</div>
|
|
<div class="flex justify-between text-sm mt-2">
|
|
<div>Processati: <span id="comuni-processed">0</span> / <span id="comuni-total">0</span></div>
|
|
<div>Stato: <span id="comuni-status" class="netgescon-badge netgescon-badge-secondary">idle</span></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
@include('admin.gescon-import.partials.staging-panel', [
|
|
'context' => 'comuni',
|
|
'title' => 'Staging MDB Comuni → DB (gescon_import)',
|
|
'defaultMdb' => '/home/michele/netgescon/docs/02-architettura-laravel/Gescon/strutture/codici_comuni.mdb'
|
|
])
|
|
|
|
<script>
|
|
let comuniTimer = null;
|
|
let comuniRunning = false;
|
|
|
|
async function comuniLoadStagingTables(){
|
|
try{
|
|
const res = await fetch(@json(route('admin.gescon-import.comuni.staging-tables')));
|
|
const j = await res.json();
|
|
const sel = document.getElementById('comuni-staging-table');
|
|
sel.innerHTML = '';
|
|
const tables = j.tables || [];
|
|
if (!tables.length){
|
|
const opt = document.createElement('option'); opt.value=''; opt.textContent='— Nessuna tabella mdb%comun% trovata —'; sel.appendChild(opt);
|
|
return;
|
|
}
|
|
tables.forEach(t=>{
|
|
const opt=document.createElement('option'); opt.value=t; opt.textContent=t; sel.appendChild(opt);
|
|
});
|
|
}catch(e){
|
|
console.error(e);
|
|
alert('Errore nel caricamento delle tabelle di staging');
|
|
}
|
|
}
|
|
|
|
async function comuniInit(){
|
|
const table = document.getElementById('comuni-staging-table').value;
|
|
if (!table){ alert('Seleziona una tabella di staging'); return false; }
|
|
const fd = new FormData(); fd.set('staging_table', table);
|
|
const res = await fetch(@json(route('admin.gescon-import.comuni.init')), { method:'POST', headers:{'X-CSRF-TOKEN': @json(csrf_token())}, body: fd });
|
|
const j = await res.json();
|
|
if (!j.ok){ alert(j.error||'Errore inizializzazione'); return false; }
|
|
comuniUpdateUI(j.progress);
|
|
return true;
|
|
}
|
|
|
|
async function comuniProcessTick(){
|
|
if (!comuniRunning) return;
|
|
const chunk = parseInt(document.getElementById('comuni-chunk').value||'500',10);
|
|
const fd = new FormData(); fd.set('chunk', String(chunk));
|
|
try{
|
|
const res = await fetch(@json(route('admin.gescon-import.comuni.process-chunk')), { method:'POST', headers:{'X-CSRF-TOKEN': @json(csrf_token())}, body: fd });
|
|
const j = await res.json();
|
|
if (j.ok){
|
|
comuniUpdateUI(j.progress);
|
|
if (j.progress.status === 'completed'){
|
|
comuniStop();
|
|
}
|
|
}
|
|
}catch(e){ console.error(e); comuniStop(); }
|
|
}
|
|
|
|
async function comuniPollProgress(){
|
|
try{
|
|
const res = await fetch(@json(route('admin.gescon-import.comuni.progress')));
|
|
const j = await res.json();
|
|
if (j.ok) comuniUpdateUI(j.progress);
|
|
}catch(e){ console.error(e); }
|
|
}
|
|
|
|
function comuniUpdateUI(p){
|
|
const pct = Math.max(0, Math.min(100, parseInt(p.percent||((p.processed||0)/(p.total||1)*100), 10)));
|
|
const bar = document.getElementById('comuni-progress-bar');
|
|
bar.style.width = pct+'%'; bar.setAttribute('aria-valuenow', String(pct)); bar.textContent = pct+'%';
|
|
document.getElementById('comuni-processed').textContent = String(p.processed||0);
|
|
document.getElementById('comuni-total').textContent = String(p.total||0);
|
|
const status = document.getElementById('comuni-status');
|
|
status.textContent = p.status||'idle';
|
|
status.className = 'netgescon-badge ' + (p.status==='completed' ? 'netgescon-badge-success' : (p.status==='running' ? 'netgescon-badge-primary' : 'netgescon-badge-secondary'));
|
|
}
|
|
|
|
function comuniStart(){
|
|
if (comuniRunning) return;
|
|
comuniRunning = true;
|
|
document.getElementById('btn-start-comuni').disabled = true;
|
|
document.getElementById('btn-pause-comuni').disabled = false;
|
|
comuniProcessTick();
|
|
comuniTimer = setInterval(comuniProcessTick, 800);
|
|
}
|
|
function comuniPause(){
|
|
comuniRunning = false;
|
|
document.getElementById('btn-start-comuni').disabled = false;
|
|
document.getElementById('btn-pause-comuni').disabled = true;
|
|
if (comuniTimer){ clearInterval(comuniTimer); comuniTimer = null; }
|
|
}
|
|
function comuniStop(){ comuniPause(); comuniPollProgress(); }
|
|
|
|
// Wire buttons
|
|
document.addEventListener('DOMContentLoaded', ()=>{
|
|
comuniLoadStagingTables();
|
|
document.getElementById('btn-refresh-staging').addEventListener('click', comuniLoadStagingTables);
|
|
document.getElementById('btn-start-comuni').addEventListener('click', async ()=>{ const ok = await comuniInit(); if (ok) comuniStart(); });
|
|
document.getElementById('btn-pause-comuni').addEventListener('click', comuniPause);
|
|
});
|
|
</script> |