Actualizar automatizaciones.html
This commit is contained in:
@@ -3,26 +3,185 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Automatizaciones - IntegraReparaPro</title>
|
||||
<title>Automatismos - IntegraRepara</title>
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<script src="https://unpkg.com/lucide@latest"></script>
|
||||
<style>
|
||||
.fade-in { animation: fadeIn 0.5s ease-in-out; }
|
||||
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
|
||||
.no-scrollbar::-webkit-scrollbar { display: none; }
|
||||
.progress-bar { transition: width 1s linear; }
|
||||
</style>
|
||||
</head>
|
||||
<body class="bg-gray-50 text-gray-800 font-sans antialiased overflow-hidden text-left">
|
||||
<div class="flex h-screen overflow-hidden text-left">
|
||||
<body class="bg-gray-50 text-gray-800 font-sans antialiased">
|
||||
|
||||
<div class="flex h-screen overflow-hidden">
|
||||
<div id="sidebar-container" class="h-full shrink-0"></div>
|
||||
|
||||
<div class="flex-1 flex flex-col overflow-hidden relative">
|
||||
<div id="header-container"></div>
|
||||
<main class="flex-1 overflow-x-hidden overflow-y-auto bg-gray-50 p-6 relative">
|
||||
<div class="fade-in max-w-6xl mx-auto">
|
||||
<h2 class="text-2xl font-black text-slate-800 flex items-center gap-3">
|
||||
<span class="bg-blue-600 p-2.5 rounded-xl text-white shadow-lg"><i data-lucide="zap"></i></span>
|
||||
Centro de Automatizaciones
|
||||
</h2>
|
||||
<p class="text-sm text-slate-500 mt-1 font-medium">Próximamente nuevas funciones...</p>
|
||||
|
||||
<main class="flex-1 overflow-x-hidden overflow-y-auto p-4 md:p-8 fade-in">
|
||||
<div class="flex justify-between items-center mb-8">
|
||||
<div>
|
||||
<h2 class="text-2xl font-bold text-gray-800">Cola de Asignación Automática</h2>
|
||||
<p class="text-sm text-gray-500">Servicios buscando operario vía WhatsApp</p>
|
||||
</div>
|
||||
<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"></i>
|
||||
Actualizando cada 30s
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="automation-list" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||
<div class="animate-pulse bg-white h-48 rounded-xl border border-gray-200"></div>
|
||||
</div>
|
||||
|
||||
<div class="mt-12">
|
||||
<h3 class="font-bold text-gray-400 uppercase text-xs tracking-widest mb-4">Automatismos Fallidos (Sin respuesta)</h3>
|
||||
<div class="bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden">
|
||||
<table class="w-full text-left border-collapse">
|
||||
<thead>
|
||||
<tr class="bg-gray-50 text-[10px] font-black uppercase text-gray-400 border-b">
|
||||
<th class="p-4">Expediente</th>
|
||||
<th class="p-4">Zona / Gremio</th>
|
||||
<th class="p-4">Motivo</th>
|
||||
<th class="p-4 text-right">Acción</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="failed-list" class="divide-y divide-gray-50 text-sm">
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="toast" class="fixed bottom-5 right-5 bg-slate-800 text-white px-6 py-3 rounded-lg shadow-2xl transform translate-y-20 opacity-0 transition-all duration-300 z-50 flex items-center gap-3"><span id="toastMsg">Mensaje</span></div>
|
||||
|
||||
<script src="js/layout.js"></script>
|
||||
<script>
|
||||
const API_URL = "https://integrarepara-api.integrarepara.es"; // Cambia a tu URL real
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
if (!localStorage.getItem("token")) { window.location.href = "index.html"; return; }
|
||||
loadAutomations();
|
||||
setInterval(loadAutomations, 30000); // Recarga cada 30 seg
|
||||
});
|
||||
|
||||
async function loadAutomations() {
|
||||
try {
|
||||
// Obtenemos los servicios en estado 'in_progress' o 'failed'
|
||||
const res = await fetch(`${API_URL}/providers/scraped`, {
|
||||
headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` }
|
||||
});
|
||||
const data = await res.json();
|
||||
if (data.ok) {
|
||||
renderCards(data.services.filter(s => s.automation_status === 'in_progress'));
|
||||
renderFailedTable(data.services.filter(s => s.automation_status === 'failed'));
|
||||
}
|
||||
} catch (e) { console.error(e); }
|
||||
}
|
||||
|
||||
function renderCards(activeServices) {
|
||||
const container = document.getElementById('automation-list');
|
||||
if (activeServices.length === 0) {
|
||||
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"></i>
|
||||
<p class="text-gray-400 font-bold uppercase text-xs">No hay automatismos en curso ahora</p>
|
||||
</div>`;
|
||||
lucide.createIcons();
|
||||
return;
|
||||
}
|
||||
|
||||
container.innerHTML = activeServices.map(s => {
|
||||
const raw = s.raw_data;
|
||||
return `
|
||||
<div class="bg-white rounded-2xl border-2 border-blue-50 shadow-sm overflow-hidden flex flex-col">
|
||||
<div class="p-5 border-b border-gray-50 bg-blue-50/30">
|
||||
<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">${s.provider}</span>
|
||||
<span class="text-xs font-black text-blue-600">Ref: ${s.service_ref}</span>
|
||||
</div>
|
||||
<h4 class="font-black text-slate-800 uppercase truncate">${raw["Nombre Cliente"] || 'Sin nombre'}</h4>
|
||||
<p class="text-[10px] text-gray-500 font-bold uppercase tracking-tighter">📍 CP: ${raw["Código Postal"]} | ${raw["Gremio"] || 'Gremio'}</p>
|
||||
</div>
|
||||
|
||||
<div class="p-5 flex-1 space-y-4">
|
||||
<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">
|
||||
<i data-lucide="user"></i>
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-[10px] text-gray-400 font-bold uppercase leading-none">Turno actual:</p>
|
||||
<p class="font-black text-slate-700 uppercase">Marco Rincón</p> </div>
|
||||
</div>
|
||||
|
||||
<div class="space-y-1">
|
||||
<div class="flex justify-between text-[10px] font-bold uppercase tracking-widest text-blue-500">
|
||||
<span>Tiempo de espera</span>
|
||||
<span>5m</span>
|
||||
</div>
|
||||
<div class="w-full bg-gray-100 h-1.5 rounded-full overflow-hidden">
|
||||
<div class="bg-blue-500 h-full progress-bar" style="width: 45%"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<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">
|
||||
Detener rueda
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}).join('');
|
||||
lucide.createIcons();
|
||||
}
|
||||
|
||||
function renderFailedTable(failedServices) {
|
||||
const tbody = document.getElementById('failed-list');
|
||||
tbody.innerHTML = failedServices.map(s => {
|
||||
return `
|
||||
<tr class="hover:bg-red-50/30 transition">
|
||||
<td class="p-4 font-bold text-slate-700">${s.service_ref}</td>
|
||||
<td class="p-4 text-xs font-medium text-gray-500">CP: ${s.raw_data["Código Postal"]}</td>
|
||||
<td class="p-4"><span class="text-[10px] font-black text-red-500 uppercase bg-red-100 px-2 py-0.5 rounded">Nadie respondió</span></td>
|
||||
<td class="p-4 text-right">
|
||||
<button onclick="window.location.href='proveedores.html'" class="text-blue-600 font-black text-[10px] uppercase hover:underline">Asignar Manual</button>
|
||||
</td>
|
||||
</tr>
|
||||
`;
|
||||
}).join('');
|
||||
}
|
||||
|
||||
async function stopAutomation(id) {
|
||||
if(!confirm("¿Seguro que quieres detener el proceso automático para este servicio?")) return;
|
||||
try {
|
||||
// Endpoint para volver el estado a manual
|
||||
const res = await fetch(`${API_URL}/providers/scraped/${id}`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": `Bearer ${localStorage.getItem("token")}`
|
||||
},
|
||||
body: JSON.stringify({ automation_status: 'manual' })
|
||||
});
|
||||
if (await res.json()) {
|
||||
showToast("Proceso detenido");
|
||||
loadAutomations();
|
||||
}
|
||||
} catch(e) { showToast("Error al detener", true); }
|
||||
}
|
||||
|
||||
function showToast(msg, err=false){
|
||||
const t=document.getElementById('toast'), m=document.getElementById('toastMsg');
|
||||
t.className=`fixed bottom-5 right-5 px-6 py-3 rounded-xl shadow-2xl transition-all duration-300 z-50 flex items-center gap-3 font-bold ${err?'bg-red-600':'bg-slate-900'} text-white`;
|
||||
m.innerText=msg; t.classList.remove('translate-y-20','opacity-0');
|
||||
setTimeout(()=>t.classList.add('translate-y-20','opacity-0'),3000);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user