diff --git a/agenda.html b/agenda.html index a6c3d05..a0de5b8 100644 --- a/agenda.html +++ b/agenda.html @@ -109,15 +109,31 @@ +
Busca bloqueos pasados o futuros
+Cargando...
Cargando...
@@ -371,44 +387,78 @@ } async function loadActiveBlocks() { - const container = document.getElementById('blocksList'); + const activeContainer = document.getElementById('blocksList'); + const pastContainer = document.getElementById('pastBlocksList'); + + // Leemos el valor del filtro de mes (Ej: "2026-02") + const monthFilter = document.getElementById('blockMonthFilter').value; + try { const res = await fetch(`${API_URL}/agenda/blocks`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } }); const data = await res.json(); - if (!data.ok || data.blocks.length === 0) { - container.innerHTML = `No hay bloqueos activos a futuro.
`; - return; + if (!data.ok) throw new Error("Error fetching blocks"); + + let allBlocks = data.blocks; + + // APLICAMOS EL FILTRO POR MES SI HAY ALGUNO SELECCIONADO + if (monthFilter) { + // Nos quedamos solo con los bloqueos cuya fecha empiece por "YYYY-MM" + allBlocks = allBlocks.filter(b => b.date.startsWith(monthFilter)); } - container.innerHTML = data.blocks.map(b => { - // Etiqueta visual si es de un gremio concreto o total - const badge = b.guild_name - ? `Solo ${b.guild_name}` - : `Bloqueo Total`; + // Sacamos la fecha de hoy (YYYY-MM-DD) para comparar + const todayStr = new Date().toISOString().split('T')[0]; + + const activeBlocks = allBlocks.filter(b => b.date >= todayStr).reverse(); + const pastBlocks = allBlocks.filter(b => b.date < todayStr); + + // Pintar Activos + if (activeBlocks.length === 0) { + activeContainer.innerHTML = `No hay bloqueos activos en este periodo.
`; + } else { + activeContainer.innerHTML = activeBlocks.map(b => buildBlockHtml(b, false)).join(''); + } + + // Pintar Caducados + if (pastBlocks.length === 0) { + pastContainer.innerHTML = `No hay bloqueos antiguos en este periodo.
`; + } else { + pastContainer.innerHTML = pastBlocks.map(b => buildBlockHtml(b, true)).join(''); + } - return ` -- ${b.worker_name} -
- ${badge} -${b.date} | ${b.time} (${b.duration} min)
-${b.reason}
-+ ${b.worker_name} +
+ ${badge} +${b.date} | ${b.time} (${b.duration} min)
+${b.reason || 'Sin motivo especificado'}
+