From 347e0173ae70bca04d7912916c1688eaaa42e7cd Mon Sep 17 00:00:00 2001 From: marsalva Date: Sun, 22 Feb 2026 12:43:55 +0000 Subject: [PATCH] Actualizar agenda.html --- agenda.html | 110 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 80 insertions(+), 30 deletions(-) diff --git a/agenda.html b/agenda.html index a6c3d05..a0de5b8 100644 --- a/agenda.html +++ b/agenda.html @@ -109,15 +109,31 @@ +
+
+
+ +
+
+

Filtrar por Mes

+

Busca bloqueos pasados o futuros

+
+
+
+ + +
+
+

- Bloqueos Activos + Bloqueos Activos a Futuro

Cargando...

- Bloqueos Pasados / Caducados + Historial Pasado

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}

-
- -
- `; - }).join(''); lucide.createIcons(); - } catch(e) { container.innerHTML = "Error"; } + } catch(e) { + activeContainer.innerHTML = "Error cargando"; + pastContainer.innerHTML = "Error cargando"; + } + } + + // Helper visual para pintar la tarjeta segĂșn sea activa o caducada + function buildBlockHtml(b, isPast) { + const badge = b.guild_name + ? `Solo ${b.guild_name}` + : `Bloqueo Total`; + + return ` +
+
+
+

+ ${b.worker_name} +

+ ${badge} +
+

${b.date} | ${b.time} (${b.duration} min)

+

${b.reason || 'Sin motivo especificado'}

+
+ +
+ `; } async function deleteBlock(id) {