Actualizar proveedores.html
This commit is contained in:
@@ -206,7 +206,7 @@
|
|||||||
<script>
|
<script>
|
||||||
let allGuilds = [];
|
let allGuilds = [];
|
||||||
let scrapedData = [];
|
let scrapedData = [];
|
||||||
let pollingInterval = null; // Variable para controlar el refresco automático
|
let pollingInterval = null;
|
||||||
|
|
||||||
const companyLogos = {
|
const companyLogos = {
|
||||||
'REPSOL': 'https://cdn.sanity.io/images/rn4tswnp/production/1bc5be0207b732bd18dd0fc38e063d5701267068-1000x832.png?rect=6,0,994,832&h=320&auto=format&dpr=2',
|
'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'];
|
return keyFound ? companyLogos[keyFound] : companyLogos['DEFAULT'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// CARGA INICIAL Y CONFIGURACIÓN DEL REFRESCO
|
|
||||||
document.addEventListener("DOMContentLoaded", async () => {
|
document.addEventListener("DOMContentLoaded", async () => {
|
||||||
if (!localStorage.getItem("token")) window.location.href = "index.html";
|
if (!localStorage.getItem("token")) window.location.href = "index.html";
|
||||||
|
|
||||||
// Carga inicial
|
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
await loadGuilds();
|
await loadGuilds();
|
||||||
await loadInbox();
|
await loadInbox();
|
||||||
}, 200);
|
}, 200);
|
||||||
|
|
||||||
// INICIAR REFRESCO AUTOMÁTICO CADA 30 SEGUNDOS
|
|
||||||
startPolling();
|
startPolling();
|
||||||
});
|
});
|
||||||
|
|
||||||
function startPolling() {
|
function startPolling() {
|
||||||
if (pollingInterval) clearInterval(pollingInterval);
|
if (pollingInterval) clearInterval(pollingInterval);
|
||||||
pollingInterval = setInterval(async () => {
|
pollingInterval = setInterval(async () => {
|
||||||
// Solo actualizamos si el usuario NO está editando un expediente (modal cerrado)
|
|
||||||
const modal = document.getElementById('importModal');
|
const modal = document.getElementById('importModal');
|
||||||
if (modal.classList.contains('hidden')) {
|
if (modal.classList.contains('hidden')) {
|
||||||
console.log("Actualizando buzón automáticamente...");
|
|
||||||
await loadInbox();
|
await loadInbox();
|
||||||
}
|
}
|
||||||
}, 30000); // 30 segundos
|
}, 30000);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadGuilds() {
|
async function loadGuilds() {
|
||||||
@@ -288,7 +281,6 @@
|
|||||||
const dataSvc = await resSvc.json();
|
const dataSvc = await resSvc.json();
|
||||||
scrapedData = dataSvc.services || [];
|
scrapedData = dataSvc.services || [];
|
||||||
|
|
||||||
// Actualizar select de compañías solo si es necesario (para no romper el filtro actual)
|
|
||||||
const compSelect = document.getElementById('filterCompany');
|
const compSelect = document.getElementById('filterCompany');
|
||||||
const currentVal = compSelect.value;
|
const currentVal = compSelect.value;
|
||||||
const uniqueCompanies = [...new Set(scrapedData.map(s => {
|
const uniqueCompanies = [...new Set(scrapedData.map(s => {
|
||||||
@@ -300,7 +292,6 @@
|
|||||||
uniqueCompanies.forEach(c => compSelect.innerHTML += `<option value="${c}">${c}</option>`);
|
uniqueCompanies.forEach(c => compSelect.innerHTML += `<option value="${c}">${c}</option>`);
|
||||||
compSelect.value = currentVal;
|
compSelect.value = currentVal;
|
||||||
|
|
||||||
// Actualizar contadores
|
|
||||||
const active = scrapedData.filter(s => s.status === 'pending').length;
|
const active = scrapedData.filter(s => s.status === 'pending').length;
|
||||||
const archived = scrapedData.filter(s => s.status === 'archived').length;
|
const archived = scrapedData.filter(s => s.status === 'archived').length;
|
||||||
document.getElementById('countActive').innerText = active;
|
document.getElementById('countActive').innerText = active;
|
||||||
@@ -357,7 +348,7 @@
|
|||||||
let isLocked = false;
|
let isLocked = false;
|
||||||
let lockedMsg = '';
|
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 autoStatus = (svc.automation_status || '').toLowerCase();
|
||||||
const sysStatus = (svc.status || '').toLowerCase();
|
const sysStatus = (svc.status || '').toLowerCase();
|
||||||
const linkedStatus = (raw['estado'] || raw['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="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 class="w-1.5 h-1.5 bg-orange-500 rounded-full pulse-slow"></span> En Bolsa
|
||||||
</span>
|
</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>`;
|
</div>`;
|
||||||
}
|
}
|
||||||
// 2. ASIGNADO A UN OPERARIO
|
// 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>
|
<span class="text-[9px] font-bold text-slate-500 max-w-[120px] truncate text-right">Esperando acción</span>
|
||||||
</div>`;
|
</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 {
|
else {
|
||||||
bgClass = 'bg-white border-slate-200';
|
bgClass = 'bg-white border-slate-200';
|
||||||
badgeEstado = `
|
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">
|
<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
|
<i data-lucide="user-minus" class="w-3 h-3"></i> Sin Asignar
|
||||||
</span>
|
</span>
|
||||||
|
<span class="text-[8px] font-bold text-slate-300 uppercase tracking-widest mt-0.5">sys:${sysStatus}|auto:${autoStatus}</span>
|
||||||
</div>`;
|
</div>`;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bgClass = 'bg-gray-50 border-gray-200 archived';
|
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');
|
const card = document.createElement('div');
|
||||||
|
|||||||
Reference in New Issue
Block a user