diff --git a/automatizaciones.html b/automatizaciones.html index 32597e0..94e8a4c 100644 --- a/automatizaciones.html +++ b/automatizaciones.html @@ -69,21 +69,33 @@ setInterval(loadAutomations, 20000); }); - async function loadAutomations() { - try { - const res = await fetch(`${API_URL}/providers/scraped`, { - headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } - }); - const data = await res.json(); - if (data.ok) { - activeIntervals.forEach(clearInterval); - activeIntervals = []; + async function loadAutomations() { + try { + const res = await fetch(`${API_URL}/providers/scraped`, { + headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } + }); + const data = await res.json(); + if (data.ok) { + activeIntervals.forEach(clearInterval); + activeIntervals = []; - renderCards(data.services.filter(s => s.automation_status === 'in_progress')); - renderFailedTable(data.services.filter(s => s.automation_status === 'failed')); - } - } catch (e) { console.error(e); } + // Solo mostramos arriba los que están en progreso Y TIENEN un operario con el turno activo + const inQueue = data.services.filter(s => + s.automation_status === 'in_progress' && s.current_worker_name !== null + ); + + // Se consideran fallidos los que están marcados como 'failed' + // O los que están 'in_progress' pero ya no tienen a nadie en turno (ronda terminada) + const failed = data.services.filter(s => + s.automation_status === 'failed' || + (s.automation_status === 'in_progress' && s.current_worker_name === null) + ); + + renderCards(inQueue); + renderFailedTable(failed); } + } catch (e) { console.error(e); } +} function renderCards(activeServices) { const container = document.getElementById('automation-list');