Actualizar automatizaciones.html

This commit is contained in:
2026-02-15 21:41:00 +00:00
parent 675f331f16
commit 71ca6247a6

View File

@@ -28,7 +28,7 @@
<p class="text-sm text-gray-500">Servicios buscando operario vía WhatsApp</p> <p class="text-sm text-gray-500">Servicios buscando operario vía WhatsApp</p>
</div> </div>
<div class="bg-blue-100 text-blue-700 px-4 py-2 rounded-lg flex items-center gap-2 font-bold text-sm"> <div class="bg-blue-100 text-blue-700 px-4 py-2 rounded-lg flex items-center gap-2 font-bold text-sm">
<i data-lucide="refresh-cw" class="w-4 h-4 animate-spin text-left"></i> <i data-lucide="refresh-cw" class="w-4 h-4 animate-spin"></i>
En Vivo En Vivo
</div> </div>
</div> </div>
@@ -45,7 +45,7 @@
<tr class="bg-gray-50 text-[10px] font-black uppercase text-gray-400 border-b text-left"> <tr class="bg-gray-50 text-[10px] font-black uppercase text-gray-400 border-b text-left">
<th class="p-4 text-left">Expediente / Cliente</th> <th class="p-4 text-left">Expediente / Cliente</th>
<th class="p-4 text-left">Dirección y Contacto</th> <th class="p-4 text-left">Dirección y Contacto</th>
<th class="p-4 text-left">Motivo</th> <th class="p-4 text-left">Estado</th>
<th class="p-4 text-right text-left">Acción</th> <th class="p-4 text-right text-left">Acción</th>
</tr> </tr>
</thead> </thead>
@@ -61,36 +61,36 @@
<div class="bg-white rounded-[2rem] shadow-2xl w-full max-w-2xl flex flex-col max-h-[90vh] overflow-hidden border border-slate-200 fade-in text-left"> <div class="bg-white rounded-[2rem] shadow-2xl w-full max-w-2xl flex flex-col max-h-[90vh] overflow-hidden border border-slate-200 fade-in text-left">
<div class="px-6 py-4 border-b border-slate-100 flex justify-between items-center bg-slate-50/50 text-left"> <div class="px-6 py-4 border-b border-slate-100 flex justify-between items-center bg-slate-50/50 text-left">
<h3 class="font-black text-slate-800 uppercase tracking-tight flex items-center gap-2 text-left"> <h3 class="font-black text-slate-800 uppercase tracking-tight flex items-center gap-2 text-left">
<i data-lucide="life-buoy" class="text-red-500 w-5 h-5 text-left"></i> Rescate Manual: #<span id="resRef">--</span> <i data-lucide="life-buoy" class="text-red-500 w-5 h-5"></i> Rescate Manual: #<span id="resRef">--</span>
</h3> </h3>
<button onclick="closeRescueModal()" class="text-slate-400 hover:text-red-500 transition-colors text-left"><i data-lucide="x"></i></button> <button onclick="closeRescueModal()" class="text-slate-400 hover:text-red-500 transition-colors"><i data-lucide="x"></i></button>
</div> </div>
<div class="p-6 overflow-y-auto space-y-6 no-scrollbar text-left"> <div class="p-6 overflow-y-auto space-y-6 no-scrollbar text-left">
<div class="grid grid-cols-2 gap-4 text-left"> <div class="grid grid-cols-2 gap-4 text-left">
<div class="bg-blue-50/50 p-4 rounded-2xl border border-blue-100 relative text-left"> <div class="bg-blue-50/50 p-4 rounded-2xl border border-blue-100 relative text-left">
<span class="text-[9px] font-black text-blue-400 uppercase absolute top-2 left-4 text-left">Asegurado</span> <span class="text-[9px] font-black text-blue-400 uppercase absolute top-2 left-4">Asegurado</span>
<p id="resName" class="font-black text-slate-800 uppercase mt-2 text-sm text-left">--</p> <p id="resName" class="font-black text-slate-800 uppercase mt-2 text-sm">--</p>
<a id="resPhoneLink" href="#" class="text-emerald-600 font-black text-xs flex items-center gap-1 mt-1 text-left"><i data-lucide="phone" class="w-3 h-3 text-left"></i> <span id="resPhone">--</span></a> <a id="resPhoneLink" href="#" class="text-emerald-600 font-black text-xs flex items-center gap-1 mt-1"><i data-lucide="phone" class="w-3 h-3"></i> <span id="resPhone">--</span></a>
</div> </div>
<div class="bg-slate-50 p-4 rounded-2xl border border-slate-100 relative text-left"> <div class="bg-slate-50 p-4 rounded-2xl border border-slate-100 relative text-left">
<span class="text-[9px] font-black text-slate-400 uppercase absolute top-2 left-4 text-left">Ubicación</span> <span class="text-[9px] font-black text-slate-400 uppercase absolute top-2 left-4 text-left">Ubicación</span>
<p id="resAddr" class="font-bold text-slate-700 text-[11px] leading-tight mt-2 uppercase text-left">--</p> <p id="resAddr" class="font-bold text-slate-700 text-[11px] leading-tight mt-2 uppercase">--</p>
</div> </div>
</div> </div>
<div class="space-y-1 text-left"> <div class="space-y-1 text-left">
<label class="text-[10px] font-black text-slate-400 uppercase ml-2 text-left">Avería del Expediente</label> <label class="text-[10px] font-black text-slate-400 uppercase ml-2">Avería del Expediente</label>
<div id="resDesc" class="p-4 bg-slate-50 rounded-2xl text-xs font-medium text-slate-600 border border-slate-100 text-left">--</div> <div id="resDesc" class="p-4 bg-slate-50 rounded-2xl text-xs font-medium text-slate-600 border border-slate-100">--</div>
</div> </div>
<div class="space-y-3 text-left"> <div class="space-y-3 text-left">
<h4 class="text-[10px] font-black text-red-500 uppercase tracking-widest ml-2 text-left">Operarios que no cogieron (Llamar para forzar)</h4> <h4 class="text-[10px] font-black text-red-500 uppercase tracking-widest ml-2">Operarios contactados (Llamar para forzar)</h4>
<div id="resWorkersList" class="space-y-2 text-left"></div> <div id="resWorkersList" class="space-y-2 text-left"></div>
</div> </div>
</div> </div>
<div class="p-4 bg-slate-50 border-t border-slate-100 flex gap-3 text-left"> <div class="p-4 bg-slate-50 border-t border-slate-100 flex gap-3 text-left">
<button onclick="resetToManual()" class="bg-white border border-slate-200 text-slate-400 p-3 rounded-xl hover:text-amber-500 transition-colors text-left" title="Devolver a Manual"> <button onclick="resetToManual()" class="bg-white border border-slate-200 text-slate-400 p-3 rounded-xl hover:text-amber-500 transition-colors" title="Quitar de esta lista y volver a proveedores">
<i data-lucide="trash-2"></i> <i data-lucide="trash-2"></i>
</button> </button>
<button onclick="window.location.href='validar.html'" class="flex-1 bg-slate-900 text-white font-black py-4 rounded-2xl text-xs uppercase tracking-widest hover:bg-blue-600 transition-all text-left flex justify-center">Asignar Manualmente</button> <button onclick="window.location.href='validar.html'" class="flex-1 bg-slate-900 text-white font-black py-4 rounded-2xl text-xs uppercase tracking-widest hover:bg-blue-600 transition-all flex justify-center items-center">Asignar Manualmente</button>
</div> </div>
</div> </div>
</div> </div>
@@ -120,8 +120,16 @@
activeIntervals.forEach(clearInterval); activeIntervals.forEach(clearInterval);
activeIntervals = []; activeIntervals = [];
const inQueue = scrapedData.filter(s => s.automation_status === 'in_progress' && s.current_worker_name !== null); // FILTRO CORREGIDO: Solo mostramos lo que está en 'in_progress' o 'failed'
const failed = scrapedData.filter(s => s.automation_status === 'failed' || (s.automation_status === 'in_progress' && s.current_worker_name === null)); // Al pasarlo a 'manual' con el botón de la papelera, desaparece de ambos filtros
const inQueue = scrapedData.filter(s =>
s.automation_status === 'in_progress' && s.current_worker_name !== null
);
const failed = scrapedData.filter(s =>
s.automation_status === 'failed' ||
(s.automation_status === 'in_progress' && s.current_worker_name === null)
);
renderCards(inQueue); renderCards(inQueue);
renderFailedTable(failed); renderFailedTable(failed);
@@ -132,8 +140,8 @@
function renderCards(activeServices) { function renderCards(activeServices) {
const container = document.getElementById('automation-list'); const container = document.getElementById('automation-list');
if (activeServices.length === 0) { if (activeServices.length === 0) {
container.innerHTML = `<div class="col-span-full py-12 text-center border-2 border-dashed border-gray-200 rounded-2xl text-left"> container.innerHTML = `<div class="col-span-full py-12 text-center border-2 border-dashed border-gray-200 rounded-2xl">
<i data-lucide="ghost" class="w-12 h-12 text-gray-300 mx-auto mb-3 text-left"></i> <i data-lucide="ghost" class="w-12 h-12 text-gray-300 mx-auto mb-3"></i>
<p class="text-gray-400 font-bold uppercase text-xs">No hay automatismos en curso</p> <p class="text-gray-400 font-bold uppercase text-xs">No hay automatismos en curso</p>
</div>`; </div>`;
lucide.createIcons(); lucide.createIcons();
@@ -142,37 +150,36 @@
container.innerHTML = activeServices.map(s => { container.innerHTML = activeServices.map(s => {
const raw = s.raw_data; const raw = s.raw_data;
const cardId = `card-${s.id}`;
return ` return `
<div id="${cardId}" class="bg-white rounded-2xl border-2 border-blue-50 shadow-sm overflow-hidden flex flex-col fade-in text-left"> <div class="bg-white rounded-2xl border-2 border-blue-50 shadow-sm overflow-hidden flex flex-col fade-in">
<div class="p-5 border-b border-gray-50 bg-blue-50/30 text-left"> <div class="p-5 border-b border-gray-50 bg-blue-50/30 text-left">
<div class="flex justify-between items-start mb-2 text-left"> <div class="flex justify-between items-start mb-2">
<span class="text-[10px] font-black bg-blue-600 text-white px-2 py-0.5 rounded uppercase text-left">${s.provider}</span> <span class="text-[10px] font-black bg-blue-600 text-white px-2 py-0.5 rounded uppercase">${s.provider}</span>
<span class="text-xs font-black text-blue-600 text-left">Ref: ${s.service_ref}</span> <span class="text-xs font-black text-blue-600">Ref: ${s.service_ref}</span>
</div> </div>
<h4 class="font-black text-slate-800 uppercase truncate text-left">${raw["Nombre Cliente"] || raw["CLIENTE"] || 'Sin nombre'}</h4> <h4 class="font-black text-slate-800 uppercase truncate">${raw["Nombre Cliente"] || raw["CLIENTE"] || 'Sin nombre'}</h4>
<p class="text-[10px] text-gray-500 font-bold uppercase tracking-tighter text-left">📍 CP: ${raw["Código Postal"] || raw["C.P."] || '---'}</p> <p class="text-[10px] text-gray-500 font-bold uppercase tracking-tighter">📍 CP: ${raw["Código Postal"] || raw["C.P."] || '---'}</p>
</div> </div>
<div class="p-5 flex-1 space-y-4 text-left"> <div class="p-5 flex-1 space-y-4 text-left">
<div class="flex items-center gap-3 text-left"> <div class="flex items-center gap-3">
<div class="w-10 h-10 rounded-full bg-green-100 flex items-center justify-center text-green-600 text-left"><i data-lucide="user"></i></div> <div class="w-10 h-10 rounded-full bg-green-100 flex items-center justify-center text-green-600"><i data-lucide="user"></i></div>
<div class="text-left"> <div>
<p class="text-[10px] text-gray-400 font-bold uppercase leading-none text-left">Turno actual:</p> <p class="text-[10px] text-gray-400 font-bold uppercase leading-none">Turno actual:</p>
<p class="font-black text-slate-700 uppercase text-left">${s.current_worker_name || 'Buscando...'}</p> <p class="font-black text-slate-700 uppercase">${s.current_worker_name || 'Buscando...'}</p>
</div> </div>
</div> </div>
<div class="space-y-1 text-left"> <div class="space-y-1">
<div class="flex justify-between text-[10px] font-bold uppercase tracking-widest text-blue-500 text-left"> <div class="flex justify-between text-[10px] font-bold uppercase tracking-widest text-blue-500">
<span>Caduca en</span> <span>Caduca en</span>
<span id="timer-${s.id}">--:--</span> <span id="timer-${s.id}">--:--</span>
</div> </div>
<div class="w-full bg-gray-100 h-1.5 rounded-full overflow-hidden text-left"> <div class="w-full bg-gray-100 h-1.5 rounded-full overflow-hidden">
<div id="progress-${s.id}" class="bg-blue-500 h-full progress-bar text-left" style="width: 100%"></div> <div id="progress-${s.id}" class="bg-blue-500 h-full progress-bar" style="width: 100%"></div>
</div> </div>
</div> </div>
</div> </div>
<div class="p-3 bg-gray-50 flex gap-2 text-left"> <div class="p-3 bg-gray-50 flex gap-2">
<button onclick="stopAutomation(${s.id})" class="flex-1 bg-white border border-red-200 text-red-500 py-2 rounded-lg text-[10px] font-black uppercase hover:bg-red-50 transition-colors text-left flex justify-center">Abortar Rueda</button> <button onclick="stopAutomation(${s.id})" class="flex-1 bg-white border border-red-200 text-red-500 py-2 rounded-lg text-[10px] font-black uppercase hover:bg-red-50 transition-colors flex justify-center">Abortar Rueda</button>
</div> </div>
</div>`; </div>`;
}).join(''); }).join('');
@@ -207,29 +214,26 @@
function renderFailedTable(failedServices) { function renderFailedTable(failedServices) {
const tbody = document.getElementById('failed-list'); const tbody = document.getElementById('failed-list');
if (failedServices.length === 0) { if (failedServices.length === 0) {
tbody.innerHTML = `<tr><td colspan="4" class="p-8 text-center text-gray-400 italic text-left">No hay fallidos ahora.</td></tr>`; tbody.innerHTML = `<tr><td colspan="4" class="p-8 text-center text-gray-400 italic">No hay fallidos ahora.</td></tr>`;
return; return;
} }
tbody.innerHTML = failedServices.map(s => { tbody.innerHTML = failedServices.map(s => {
const raw = s.raw_data || {}; const raw = s.raw_data || {};
const name = raw["Nombre Cliente"] || raw["CLIENTE"] || "Asegurado Desconocido"; const name = raw["Nombre Cliente"] || raw["CLIENTE"] || "Asegurado Desconocido";
const address = raw["Dirección"] || raw["DOMICILIO"] || "Sin dirección";
return ` return `
<tr onclick="openRescue(${s.id})" class="border-b border-gray-50 hover:bg-slate-50 transition-all cursor-pointer text-left"> <tr onclick="openRescue(${s.id})" class="border-b border-gray-50 hover:bg-slate-50 transition-all cursor-pointer text-left">
<td class="p-4 text-left"> <td class="p-4 text-left">
<div class="flex flex-col text-left"> <div class="flex flex-col">
<span class="font-black text-slate-700 text-left">#${s.service_ref}</span> <span class="font-black text-slate-700">#${s.service_ref}</span>
<span class="text-[10px] text-blue-600 font-bold uppercase text-left">${name}</span> <span class="text-[10px] text-blue-600 font-bold uppercase">${name}</span>
</div> </div>
</td> </td>
<td class="p-4 text-left"> <td class="p-4 text-left text-xs font-bold text-slate-600 uppercase">
<div class="flex flex-col text-left"> ${raw["Dirección"] || 'S/D'} <br>
<span class="text-xs font-bold text-slate-600 text-left">${address}</span> <span class="text-[10px] text-gray-400 font-medium">${raw["Población"] || ''} ${raw["Código Postal"] || ''}</span>
<span class="text-[10px] text-gray-400 font-medium text-left">${raw["Población"] || ''} ${raw["Código Postal"] ? '| CP: '+raw["Código Postal"] : ''}</span>
</div>
</td> </td>
<td class="p-4 text-left"><span class="text-[10px] font-black text-red-500 uppercase bg-red-100 px-2 py-0.5 rounded text-left">Nadie respondió</span></td> <td class="p-4 text-left"><span class="text-[10px] font-black text-red-500 uppercase bg-red-100 px-2 py-0.5 rounded">Ronda Finalizada</span></td>
<td class="p-4 text-right text-left"><i data-lucide="chevron-right" class="inline text-slate-300 text-left"></i></td> <td class="p-4 text-right text-slate-300"><i data-lucide="chevron-right"></i></td>
</tr>`; </tr>`;
}).join(''); }).join('');
lucide.createIcons(); lucide.createIcons();
@@ -253,16 +257,16 @@
const workers = svc.attempted_workers_data || []; const workers = svc.attempted_workers_data || [];
if (workers.length === 0) { if (workers.length === 0) {
list.innerHTML = `<p class="text-[10px] text-slate-400 italic p-4 text-center border-2 border-dashed rounded-2xl text-left">Sin registros de intentos WhatsApp.</p>`; list.innerHTML = `<p class="text-[10px] text-slate-400 italic p-4 text-center border-2 border-dashed rounded-2xl">Sin registros de intentos WhatsApp.</p>`;
} else { } else {
list.innerHTML = workers.map(w => ` list.innerHTML = workers.map(w => `
<div class="flex items-center justify-between p-3 bg-white border border-red-100 rounded-xl shadow-sm text-left"> <div class="flex items-center justify-between p-3 bg-white border border-red-100 rounded-xl shadow-sm">
<div class="flex items-center gap-2 text-left"> <div class="flex items-center gap-2">
<div class="w-2 h-2 rounded-full bg-red-400 text-left"></div> <div class="w-2 h-2 rounded-full bg-red-400"></div>
<span class="text-xs font-black text-slate-700 uppercase text-left">${w.name}</span> <span class="text-xs font-black text-slate-700 uppercase">${w.name}</span>
</div> </div>
<a href="tel:${w.phone}" class="bg-red-50 text-red-600 px-3 py-1.5 rounded-lg text-[10px] font-black uppercase flex items-center gap-1 hover:bg-red-600 hover:text-white transition-all text-left"> <a href="tel:${w.phone}" class="bg-red-50 text-red-600 px-3 py-1.5 rounded-lg text-[10px] font-black uppercase flex items-center gap-1 hover:bg-red-600 hover:text-white transition-all">
<i data-lucide="phone" class="w-3 h-3 text-left"></i> Llamar <i data-lucide="phone" class="w-3 h-3"></i> Llamar
</a> </a>
</div> </div>
`).join(''); `).join('');
@@ -275,14 +279,18 @@
function closeRescueModal() { document.getElementById('rescueModal').classList.add('hidden'); } function closeRescueModal() { document.getElementById('rescueModal').classList.add('hidden'); }
async function resetToManual() { async function resetToManual() {
if(!confirm("¿Deseas quitar este servicio de automatización y devolverlo al Buzón de Proveedores?")) return; if(!confirm("¿Deseas devolver este servicio a Proveedores? (Desaparecerá de esta lista)")) return;
try { try {
const res = await fetch(`${API_URL}/providers/scraped/${currentRescueId}`, { const res = await fetch(`${API_URL}/providers/scraped/${currentRescueId}`, {
method: 'PUT', method: 'PUT',
headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` }, headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
body: JSON.stringify({ automation_status: 'manual' }) body: JSON.stringify({ automation_status: 'manual' })
}); });
if (res.ok) { closeRescueModal(); loadAutomations(); showToast("Enviado al Buzón de Proveedores"); } if (res.ok) {
closeRescueModal();
loadAutomations(); // Esto recarga y aplica el filtro nuevo
showToast("Devuelto al Buzón de Proveedores");
}
} catch(e) { showToast("Error al resetear", true); } } catch(e) { showToast("Error al resetear", true); }
} }