Actualizar proveedores.html
This commit is contained in:
@@ -206,7 +206,7 @@
|
||||
<script>
|
||||
let allGuilds = [];
|
||||
let scrapedData = [];
|
||||
let pollingInterval = null; // Variable para controlar el refresco automático
|
||||
let pollingInterval = null;
|
||||
|
||||
const companyLogos = {
|
||||
'REPSOL': 'https://cdn.sanity.io/images/rn4tswnp/production/1bc5be0207b732bd18dd0fc38e063d5701267068-1000x832.png?rect=6,0,994,832&h=320&auto=format&dpr=2',
|
||||
@@ -234,30 +234,23 @@
|
||||
return keyFound ? companyLogos[keyFound] : companyLogos['DEFAULT'];
|
||||
}
|
||||
|
||||
// CARGA INICIAL Y CONFIGURACIÓN DEL REFRESCO
|
||||
document.addEventListener("DOMContentLoaded", async () => {
|
||||
if (!localStorage.getItem("token")) window.location.href = "index.html";
|
||||
|
||||
// Carga inicial
|
||||
setTimeout(async () => {
|
||||
await loadGuilds();
|
||||
await loadInbox();
|
||||
}, 200);
|
||||
|
||||
// INICIAR REFRESCO AUTOMÁTICO CADA 30 SEGUNDOS
|
||||
startPolling();
|
||||
});
|
||||
|
||||
function startPolling() {
|
||||
if (pollingInterval) clearInterval(pollingInterval);
|
||||
pollingInterval = setInterval(async () => {
|
||||
// Solo actualizamos si el usuario NO está editando un expediente (modal cerrado)
|
||||
const modal = document.getElementById('importModal');
|
||||
if (modal.classList.contains('hidden')) {
|
||||
console.log("Actualizando buzón automáticamente...");
|
||||
await loadInbox();
|
||||
}
|
||||
}, 30000); // 30 segundos
|
||||
}, 30000);
|
||||
}
|
||||
|
||||
async function loadGuilds() {
|
||||
@@ -288,7 +281,6 @@
|
||||
const dataSvc = await resSvc.json();
|
||||
scrapedData = dataSvc.services || [];
|
||||
|
||||
// Actualizar select de compañías solo si es necesario (para no romper el filtro actual)
|
||||
const compSelect = document.getElementById('filterCompany');
|
||||
const currentVal = compSelect.value;
|
||||
const uniqueCompanies = [...new Set(scrapedData.map(s => {
|
||||
@@ -300,7 +292,6 @@
|
||||
uniqueCompanies.forEach(c => compSelect.innerHTML += `<option value="${c}">${c}</option>`);
|
||||
compSelect.value = currentVal;
|
||||
|
||||
// Actualizar contadores
|
||||
const active = scrapedData.filter(s => s.status === 'pending').length;
|
||||
const archived = scrapedData.filter(s => s.status === 'archived').length;
|
||||
document.getElementById('countActive').innerText = active;
|
||||
@@ -357,7 +348,7 @@
|
||||
let isLocked = false;
|
||||
let lockedMsg = '';
|
||||
|
||||
// LÓGICA DE ACTUALIZACIÓN DE ESTADO ROBUSTA
|
||||
// LA LÓGICA TOTALMENTE MODIFICADA CON EL CHIVATO DE DEPURACIÓN
|
||||
const autoStatus = (svc.automation_status || '').toLowerCase();
|
||||
const sysStatus = (svc.status || '').toLowerCase();
|
||||
const linkedStatus = (raw['estado'] || raw['status'] || '').toLowerCase();
|
||||
@@ -373,7 +364,7 @@
|
||||
<span class="bg-orange-100 text-orange-700 px-3 py-1 rounded-full text-[10px] font-black uppercase flex items-center gap-1.5 border border-orange-200 shadow-sm">
|
||||
<span class="w-1.5 h-1.5 bg-orange-500 rounded-full pulse-slow"></span> En Bolsa
|
||||
</span>
|
||||
<span class="text-[9px] font-bold text-slate-500 max-w-[120px] truncate text-right">Sin Asignar</span>
|
||||
<span class="text-[9px] font-bold text-slate-500 max-w-[120px] truncate text-right">Buscando operario...</span>
|
||||
</div>`;
|
||||
}
|
||||
// 2. ASIGNADO A UN OPERARIO
|
||||
@@ -402,7 +393,19 @@
|
||||
<span class="text-[9px] font-bold text-slate-500 max-w-[120px] truncate text-right">Esperando acción</span>
|
||||
</div>`;
|
||||
}
|
||||
// 4. NUEVO EN EL BUZÓN (Gris)
|
||||
// 4. FALLO DE ASIGNACIÓN (Se acaban los operarios en cola)
|
||||
else if (autoStatus === 'failed') {
|
||||
bgClass = 'bg-red-50/40 border-red-200 hover:border-red-400';
|
||||
isLocked = false;
|
||||
badgeEstado = `
|
||||
<div class="flex flex-col items-end gap-1">
|
||||
<span class="bg-red-100 text-red-700 px-3 py-1 rounded-full text-[10px] font-black uppercase flex items-center gap-1.5 border border-red-200 shadow-sm">
|
||||
<i data-lucide="alert-triangle" class="w-3 h-3"></i> Fallo Bolsa
|
||||
</span>
|
||||
<span class="text-[8px] font-bold text-red-400">Nadie aceptó</span>
|
||||
</div>`;
|
||||
}
|
||||
// 5. NUEVO EN EL BUZÓN (Gris)
|
||||
else {
|
||||
bgClass = 'bg-white border-slate-200';
|
||||
badgeEstado = `
|
||||
@@ -410,10 +413,17 @@
|
||||
<span class="bg-slate-100 text-slate-500 px-3 py-1 rounded-full text-[10px] font-black uppercase flex items-center gap-1.5 border border-slate-200">
|
||||
<i data-lucide="user-minus" class="w-3 h-3"></i> Sin Asignar
|
||||
</span>
|
||||
<span class="text-[8px] font-bold text-slate-300 uppercase tracking-widest mt-0.5">sys:${sysStatus}|auto:${autoStatus}</span>
|
||||
</div>`;
|
||||
}
|
||||
} else {
|
||||
bgClass = 'bg-gray-50 border-gray-200 archived';
|
||||
badgeEstado = `
|
||||
<div class="flex flex-col items-end gap-1">
|
||||
<span class="bg-gray-200 text-gray-500 px-3 py-1 rounded-full text-[10px] font-black uppercase flex items-center gap-1.5 border border-gray-300">
|
||||
<i data-lucide="archive" class="w-3 h-3"></i> Archivado
|
||||
</span>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
const card = document.createElement('div');
|
||||
|
||||
Reference in New Issue
Block a user