@@ -268,6 +268,7 @@
let systemGuilds = [];
let currentWeekStart = new Date();
let selectedDateStr = "";
+ let activeNotifications = []; // Variable global para guardar IDs con mensajes
async function applyTheme() {
try {
@@ -324,8 +325,32 @@
loadStatuses();
await loadGuilds();
refreshData();
+
+ // Comprobar notificaciones al cargar y cada 30 segundos
+ checkNotifications();
+ setInterval(checkNotifications, 30000);
});
+ async function checkNotifications() {
+ try {
+ const res = await fetch(`${API_URL}/worker/notifications`, {
+ headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` }
+ });
+ const data = await res.json();
+ if (data.ok) {
+ activeNotifications = data.serviceIds;
+ const badge = document.getElementById('topNotificationBadge');
+ if (data.unreadCount > 0) {
+ badge.classList.remove('hidden');
+ badge.innerText = data.unreadCount;
+ } else {
+ badge.classList.add('hidden');
+ }
+ renderServices(); // Refrescamos para pintar los iconos en las tarjetas
+ }
+ } catch (e) {}
+ }
+
async function loadGuilds() {
try {
const res = await fetch(`${API_URL}/guilds`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
@@ -449,6 +474,10 @@
container.innerHTML = dayServices.map(s => {
const raw = s.raw_data || {};
const time = raw.scheduled_time || "--:--";
+
+ // ¿Tiene este siniestro un mensaje nuevo?
+ const hasNewMessage = activeNotifications.includes(s.id);
+
if (s.provider === 'SYSTEM_BLOCK') {
return `
${time}
BLOQUEADO
${raw["Descripción"] || ""}
`;
}
@@ -473,7 +502,14 @@
const cMap = colorMap[stColor] || colorMap['gray'];
return `
-
+
+
+ ${hasNewMessage ? `
+
+ MENSAJE
+
+ ` : ''}
+
${s.is_urgent ? '
Urgente
' : ''}
@@ -825,7 +861,6 @@
}
data.messages.forEach(msg => {
- // Ocultar notas internas si por alguna razón el server las mandara
if (msg.is_internal) return;
const isMe = msg.sender_role === 'operario' || msg.sender_role === 'operario_cerrado';