From 91be2c848e478f675063a1179ecb076e6bf78477 Mon Sep 17 00:00:00 2001 From: marsalva Date: Sat, 7 Mar 2026 18:30:22 +0000 Subject: [PATCH] Actualizar menu.html --- menu.html | 54 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/menu.html b/menu.html index bfe11dc..73a9836 100644 --- a/menu.html +++ b/menu.html @@ -42,7 +42,6 @@ - @@ -69,6 +68,9 @@
+ + +
@@ -83,7 +85,7 @@

Buscar
Servicio

- +
@@ -91,6 +93,14 @@

Ranking
y Estadísticas

+ +
+
+ +
+

Mi
Configuración

+
+
@@ -103,7 +113,6 @@ let userGuilds = []; let systemStatuses = []; - // --- SISTEMA DE TEMA DINÁMICO --- async function applyTheme() { try { let theme = JSON.parse(localStorage.getItem('app_theme')); @@ -144,8 +153,23 @@ await loadStatuses(); await fetchUserData(); fetchBadges(); + fetchChatNotifications(); // <-- Nueva función }); + async function fetchChatNotifications() { + try { + const res = await fetch(`${API_URL}/worker/notifications`, { + headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } + }); + const data = await res.json(); + if (data.ok && data.unreadCount > 0) { + const badge = document.getElementById('badgeChat'); + badge.innerText = data.unreadCount; + badge.classList.remove('hidden'); + } + } catch (e) {} + } + async function loadStatuses() { try { const res = await fetch(`${API_URL}/statuses`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } }); @@ -160,8 +184,6 @@ const data = await res.json(); if (data.ok && data.user) { userZones = Array.isArray(data.user.zones) ? data.user.zones.map(z => z.cps) : []; - - // Necesitamos cargar los gremios const resG = await fetch(`${API_URL}/admin/users`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } }); const dataG = await resG.json(); if(dataG.ok) { @@ -175,30 +197,19 @@ async function fetchBadges() { try { const headers = { "Authorization": `Bearer ${localStorage.getItem("token")}` }; - - // 1. Cargar servicios activos del operario y peticiones const resActive = await fetch(`${API_URL}/services/active`, { headers }); const dataActive = await resActive.json(); - const resReqs = await fetch(`${API_URL}/agenda/requests`, { headers }); const dataReqs = await resReqs.json(); if (dataActive.ok && dataReqs.ok) { let sinCitaCount = 0; - - // Sumamos las peticiones pendientes sinCitaCount += dataReqs.requests.length; - - // Filtramos y contamos la lista normal dataActive.services.forEach(s => { if (s.provider === 'SYSTEM_BLOCK') return; - const raw = s.raw_data || {}; - if (raw.appointment_status === 'pending') return; // Ya las contamos arriba - - // Si no tiene fecha, lo evaluamos + if (raw.appointment_status === 'pending') return; if (!raw.scheduled_date || raw.scheduled_date.trim() === "") { - // Validar que el estado no sea finalizado/anulado (ej: "Terminado sin fecha") if (raw.status_operativo) { const st = systemStatuses.find(x => String(x.id) === String(raw.status_operativo)); if (st && st.is_final) return; @@ -206,7 +217,6 @@ sinCitaCount++; } }); - if (sinCitaCount > 0) { const b1 = document.getElementById('badgeAsignados'); b1.innerText = `${sinCitaCount} pendiente${sinCitaCount > 1 ? 's' : ''}`; @@ -214,31 +224,24 @@ } } - // 2. Pedimos la "Bolsa de Trabajo" SOLO SI TIENE PERMISO (operario_cerrado NO cuenta bolsa) if (localStorage.getItem("role") === 'operario') { const resScraped = await fetch(`${API_URL}/providers/scraped`, { headers }); const dataScraped = await resScraped.json(); - if (dataScraped.ok) { let bolsaCount = 0; dataScraped.services.forEach(s => { if(s.assigned_to || s.provider === 'SYSTEM_BLOCK') return; - const raw = s.raw_data || {}; const dbStatus = raw.status_operativo; if(s.status === 'archived' || (dbStatus && ['anulado', 'terminado', 'finalizado'].includes(dbStatus.toLowerCase()))) return; - const sGuild = String(s.guild_id || raw.guild_id); const sCp = String(raw['Código Postal'] || raw['CP'] || "").trim(); - const matchGuild = userGuilds.includes(Number(sGuild)) || userGuilds.includes(String(sGuild)); const matchZone = userZones.some(z => sCp.startsWith(z)); - if((userGuilds.length === 0 || matchGuild) && (userZones.length === 0 || matchZone)) { bolsaCount++; } }); - if (bolsaCount > 0) { const b2 = document.getElementById('badgeBolsa'); b2.innerText = `${bolsaCount} libre${bolsaCount > 1 ? 's' : ''}`; @@ -246,7 +249,6 @@ } } } - } catch (e) { console.log("Error cargando badges"); } }