From 76c1ec167c9a5f8ae32bd8847335e2dce496e513 Mon Sep 17 00:00:00 2001 From: marsalva Date: Sun, 22 Feb 2026 12:31:08 +0000 Subject: [PATCH] Actualizar agenda.html --- agenda.html | 120 +++++++++++++--------------------------------------- 1 file changed, 29 insertions(+), 91 deletions(-) diff --git a/agenda.html b/agenda.html index a4d399f..a6c3d05 100644 --- a/agenda.html +++ b/agenda.html @@ -122,35 +122,7 @@

Cargando...

-
-
-
- -
-
-

Filtrar por Mes

-

Busca bloqueos pasados o futuros

-
-
-
- - -
-
-

- Bloqueos Activos a Futuro -

-
-

Cargando...

-
- -

- Historial Pasado -

-
-

Cargando...

-
@@ -398,79 +370,45 @@ } catch(e) { alert("Error de conexión"); } } - async function loadActiveBlocks() { - 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; - + async function loadActiveBlocks() { + const container = document.getElementById('blocksList'); try { const res = await fetch(`${API_URL}/agenda/blocks`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } }); const data = await res.json(); - 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)); + if (!data.ok || data.blocks.length === 0) { + container.innerHTML = `

No hay bloqueos activos a futuro.

`; + return; } - // Sacamos la fecha de hoy (YYYY-MM-DD) para comparar - const todayStr = new Date().toISOString().split('T')[0]; + 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`; - 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(''); - } - - lucide.createIcons(); - } 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} + return ` +
+
+
+

+ ${b.worker_name} +

+ ${badge} +
+

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

+

${b.reason}

+
+
-

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

-

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

-
- -
- `; + `; + }).join(''); + lucide.createIcons(); + } catch(e) { container.innerHTML = "Error"; } } async function deleteBlock(id) {