|
|
@@ -1,670 +0,0 @@
|
|
|
-<nav class="top-0 z-[1000] fixed w-full bg-gradient-to-br from-blue-800 to-blue-900 shadow-lg border-b border-white/10 backdrop-blur-md transition-transform duration-300" x-data="{ mobileMenuOpen: false }">
|
|
|
- <!-- UNIFIED CONTAINER WITH THE REST -->
|
|
|
- <div class="w-full px-4 sm:px-6 lg:px-8">
|
|
|
- <div class="max-w-7xl mx-auto flex items-center justify-between py-4 h-[64px]">
|
|
|
- <!-- Brand/Logo Section -->
|
|
|
- <div class="flex items-center gap-3 font-bold text-xl text-white no-underline">
|
|
|
- <spam class="font-extrabold text-transparent bg-clip-text bg-gradient-to-r from-white to-blue-300">{{ _("SquidStats") }}</spam>
|
|
|
- </div>
|
|
|
- <!-- Container for mobile icons (notifications + hamburger) -->
|
|
|
- <div class="lg:hidden flex items-center gap-3">
|
|
|
- <!-- Mobile Notifications Button -->
|
|
|
- <div class="relative" x-data="{ open: false }">
|
|
|
- <button @click="open = !open" class="flex items-center gap-2 px-4 py-2 text-gray-200 rounded-lg font-medium text-sm transition-all duration-300 relative hover:text-white hover:bg-white/10 hover:-translate-y-0.5" data-tooltip="{{ _("Notificaciones") }}">
|
|
|
- <i class="fas fa-bell"></i>
|
|
|
- <span class="notification-badge absolute -top-2 -right-2 flex items-center justify-center w-5 h-5 bg-gradient-to-r from-red-500 to-red-600 text-white text-xs font-semibold rounded-full border-2 border-white shadow-lg hidden">0</span>
|
|
|
- </button>
|
|
|
- <!-- Mobile notifications dropdown -->
|
|
|
- <div x-show="open"
|
|
|
- @click.away="open = false"
|
|
|
- @keydown.escape.window="open = false"
|
|
|
- x-transition:enter="transition ease-out duration-200"
|
|
|
- x-transition:enter-start="opacity-0 scale-95"
|
|
|
- x-transition:enter-end="opacity-100 scale-100"
|
|
|
- x-transition:leave="transition ease-in duration-150"
|
|
|
- x-transition:leave-start="opacity-100 scale-100"
|
|
|
- x-transition:leave-end="opacity-0 scale-95"
|
|
|
- class="origin-top-right absolute right-0 mt-2 w-80 rounded-lg shadow-lg bg-white ring-1 ring-black ring-opacity-5 z-50"
|
|
|
- style="display: none">
|
|
|
- <div class="py-2 px-4 border-b border-gray-200 flex items-center justify-between">
|
|
|
- <span class="font-semibold text-gray-800">{{ _("Notificaciones") }}</span>
|
|
|
- <button @click="open = false" class="text-gray-400 hover:text-gray-600 focus:outline-none">
|
|
|
- <i class="fas fa-times"></i>
|
|
|
- </button>
|
|
|
- </div>
|
|
|
- <ul class="max-h-72 overflow-y-auto divide-y divide-gray-100 notifications-mobile">
|
|
|
- <li class="px-4 py-3 text-gray-500 text-center">
|
|
|
- {{ _("Cargando notificaciones...") }}
|
|
|
- </li>
|
|
|
- </ul>
|
|
|
- <div class="py-2 px-4 text-center border-t border-gray-200">
|
|
|
- <a href="/all-notifications" class="text-sm text-blue-600 hover:underline">{{ _("Ver todas las notificaciones") }}</a>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- <!-- Hamburger Button for Mobile -->
|
|
|
- <button @click="mobileMenuOpen = !mobileMenuOpen" class="flex flex-col w-8 h-8 justify-center items-center gap-1.5 text-white focus:outline-none z-[1001]" aria-label="{{ _("Toggle menu") }}">
|
|
|
- <span class="w-6 h-0.5 bg-white transition-all" :class="{'rotate-45 translate-y-2': mobileMenuOpen}"></span>
|
|
|
- <span class="w-6 h-0.5 bg-white transition-all" :class="{'opacity-0': mobileMenuOpen}"></span>
|
|
|
- <span class="w-6 h-0.5 bg-white transition-all" :class="{'-rotate-45 -translate-y-2': mobileMenuOpen}"></span>
|
|
|
- </button>
|
|
|
- </div>
|
|
|
- <!-- Navigation Links - Desktop -->
|
|
|
- <div class="hidden lg:flex items-center gap-2">
|
|
|
- <a href="/" class="flex items-center gap-2 px-4 py-2 text-gray-200 rounded-lg font-medium text-sm transition-all duration-300 relative hover:text-white hover:bg-white/10 hover:-translate-y-0.5" data-tooltip="{{ _("Panel principal con conexiones activas") }}">
|
|
|
- <i class="fas fa-home text-base"></i>
|
|
|
- <span class="font-medium">{{ _("Inicio") }}</span>
|
|
|
- </a>
|
|
|
- <a href="/stats" class="flex items-center gap-2 px-4 py-2 text-gray-200 rounded-lg font-medium text-sm transition-all duration-300 relative hover:text-white hover:bg-white/10 hover:-translate-y-0.5" data-tooltip="{{ _("Estadísticas de rendimiento del cache") }}">
|
|
|
- <i class="fas fa-chart-bar text-base"></i>
|
|
|
- <span class="font-medium">{{ _("Estadísticas") }}</span>
|
|
|
- </a>
|
|
|
- <a href="/logs" class="flex items-center gap-2 px-4 py-2 text-gray-200 rounded-lg font-medium text-sm transition-all duration-300 relative hover:text-white hover:bg-white/10 hover:-translate-y-0.5" data-tooltip="{{ _("Actividad y logs de usuarios") }}">
|
|
|
- <i class="fas fa-user-friends text-base"></i>
|
|
|
- <span class="font-medium">{{ _("Usuarios") }}</span>
|
|
|
- </a>
|
|
|
- <a href="/reports" class="flex items-center gap-2 px-4 py-2 text-gray-200 rounded-lg font-medium text-sm transition-all duration-300 relative hover:text-white hover:bg-white/10 hover:-translate-y-0.5" data-tooltip="{{ _("Reportes y gráficas avanzadas") }}">
|
|
|
- <i class="fas fa-chart-simple text-base"></i>
|
|
|
- <span class="font-medium">{{ _("Reportes") }}</span>
|
|
|
- </a>
|
|
|
- <a href="/blacklist" class="flex items-center gap-2 px-4 py-2 text-gray-200 rounded-lg font-medium text-sm transition-all duration-300 relative hover:text-white hover:bg-white/10 hover:-translate-y-0.5" data-tooltip="{{ _("Sitios bloqueados y actividad restringida") }}">
|
|
|
- <i class="fas fa-ban text-base"></i>
|
|
|
- <span class="font-medium">{{ _("Blacklist") }}</span>
|
|
|
- </a>
|
|
|
- <a href="/auditoria" class="flex items-center gap-2 px-4 py-2 text-gray-200 rounded-lg font-medium text-sm transition-all duration-300 relative hover:text-white hover:bg-white/10 hover:-translate-y-0.5" data-tooltip="{{ _("Auditoría de actividad por usuario y fecha") }}">
|
|
|
- <i class="fas fa-magnifying-glass text-base"></i>
|
|
|
- <span class="font-medium">{{ _("Auditoría") }}</span>
|
|
|
- </a>
|
|
|
- </div>
|
|
|
- <!-- Desktop Notifications -->
|
|
|
- <div class="hidden lg:flex items-center gap-3">
|
|
|
- <div class="relative" x-data="{ open: false }">
|
|
|
- <!-- Desktop Notifications Button -->
|
|
|
- <button @click="open = !open" class="flex items-center gap-2 px-4 py-2 text-gray-200 rounded-lg font-medium text-sm transition-all duration-300 relative hover:text-white hover:bg-white/10 hover:-translate-y-0.5" data-tooltip="{{ _("Notificaciones") }}">
|
|
|
- <i class="fas fa-bell"></i>
|
|
|
- <span class="notification-badge absolute -top-2 -right-2 flex items-center justify-center w-5 h-5 bg-gradient-to-r from-red-500 to-red-600 text-white text-xs font-semibold rounded-full border-2 border-white shadow-lg hidden">0</span>
|
|
|
- </button>
|
|
|
- <!-- Desktop notifications dropdown -->
|
|
|
- <div x-show="open"
|
|
|
- @click.away="open = false"
|
|
|
- @keydown.escape.window="open = false"
|
|
|
- x-transition:enter="transition ease-out duration-200"
|
|
|
- x-transition:enter-start="opacity-0 scale-95"
|
|
|
- x-transition:enter-end="opacity-100 scale-100"
|
|
|
- x-transition:leave="transition ease-in duration-150"
|
|
|
- x-transition:leave-start="opacity-100 scale-100"
|
|
|
- x-transition:leave-end="opacity-0 scale-95"
|
|
|
- class="origin-top-right absolute right-0 mt-2 w-80 rounded-lg shadow-lg bg-white ring-1 ring-black ring-opacity-5 z-50"
|
|
|
- style="display: none">
|
|
|
- <div class="py-2 px-4 border-b border-gray-200 flex items-center justify-between">
|
|
|
- <span class="font-semibold text-gray-800">{{ _("Notificaciones") }}</span>
|
|
|
- <button @click="open = false" class="text-gray-400 hover:text-gray-600 focus:outline-none">
|
|
|
- <i class="fas fa-times"></i>
|
|
|
- </button>
|
|
|
- </div>
|
|
|
- <ul class="max-h-72 overflow-y-auto divide-y divide-gray-100 notifications">
|
|
|
- <li class="px-4 py-3 text-gray-500 text-center">
|
|
|
- {{ _("Cargando notificaciones...") }}
|
|
|
- </li>
|
|
|
- </ul>
|
|
|
- <div class="py-2 px-4 text-center border-t border-gray-200">
|
|
|
- <a href="/all-notifications" class="text-sm text-blue-600 hover:underline">{{ _("Ver todas las notificaciones") }}</a>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- <!-- Action Buttons - Desktop -->
|
|
|
- <div class="flex items-center gap-3">
|
|
|
- {% if session.user and session.user.role == "admin" %}
|
|
|
- <a href="/admin" class="action-btn flex items-center gap-2 px-4 py-2 rounded-lg font-semibold text-sm bg-gradient-to-r from-blue-600 to-blue-500 text-white shadow hover:from-blue-700 hover:to-blue-600 hover:-translate-y-0.5 transition-all duration-300" data-tooltip="{{ _("Panel de administración del sistema") }}">
|
|
|
- <i class="fas fa-cog"></i>
|
|
|
- <span>{{ _("Admin") }}</span>
|
|
|
- </a>
|
|
|
- {% endif %}
|
|
|
-
|
|
|
- <button onclick="confirmSquidUpdate()" class="action-btn flex items-center gap-2 px-4 py-2 rounded-lg font-semibold text-sm bg-gradient-to-r from-emerald-600 to-emerald-400 text-white shadow hover:from-emerald-700 hover:to-emerald-600 hover:-translate-y-0.5 transition-all duration-300" data-tooltip="{{ _("Actualizar paquetes y configuración de Squid") }}">
|
|
|
- <i class="fas fa-sync-alt"></i>
|
|
|
- <span>{{ _("Squid") }}</span>
|
|
|
- </button>
|
|
|
-
|
|
|
- <button onclick="confirmWebUpdate()" class="action-btn flex items-center gap-2 px-4 py-2 rounded-lg font-semibold text-sm bg-gradient-to-r from-purple-600 to-purple-400 text-white shadow hover:from-purple-700 hover:to-purple-600 hover:-translate-y-0.5 transition-all duration-300" data-tooltip="{{ _("Actualizar aplicación web SquidStats") }}">
|
|
|
- <i class="fas fa-cloud-download-alt"></i>
|
|
|
- <span>{{ _("Web") }}</span>
|
|
|
- </button>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- <!-- Mobile Menu Overlay -->
|
|
|
- <div x-show="mobileMenuOpen" @click="mobileMenuOpen = false" class="fixed inset-0 bg-black bg-opacity-50 z-[999] lg:hidden" style="display: none;">
|
|
|
- </div>
|
|
|
- <!-- Mobile Menu Content -->
|
|
|
- <div x-show="mobileMenuOpen"
|
|
|
- x-transition:enter="transition ease-out duration-300"
|
|
|
- x-transition:enter-start="opacity-0 transform -translate-y-4"
|
|
|
- x-transition:enter-end="opacity-100 transform translate-y-0"
|
|
|
- x-transition:leave="transition ease-in duration-200"
|
|
|
- x-transition:leave-start="opacity-100 transform translate-y-0"
|
|
|
- x-transition:leave-end="opacity-0 transform -translate-y-4"
|
|
|
- class="absolute top-full left-0 right-0 bg-gradient-to-b from-blue-800 to-blue-900 shadow-2xl z-[1000] lg:hidden overflow-y-auto border-t border-white/10"
|
|
|
- style="display: none;">
|
|
|
- <div class="p-6">
|
|
|
- <!-- Mobile Navigation Links -->
|
|
|
- <div class="flex flex-col gap-2 mb-8">
|
|
|
- <a href="/" @click="mobileMenuOpen = false" class="flex items-center gap-3 px-4 py-3 text-gray-200 rounded-lg font-medium text-base transition-all duration-300 hover:text-white hover:bg-white/10">
|
|
|
- <i class="fas fa-home text-lg"></i>
|
|
|
- <span>{{ _("Inicio") }}</span>
|
|
|
- </a>
|
|
|
- <a
|
|
|
- href="/stats" @click="mobileMenuOpen = false"
|
|
|
- class="flex items-center gap-3 px-4 py-3 text-gray-200 rounded-lg font-medium text-base transition-all duration-300 hover:text-white hover:bg-white/10">
|
|
|
- <i class="fas fa-chart-bar text-lg"></i>
|
|
|
- <span>{{ _("Estadísticas") }}</span>
|
|
|
- </a>
|
|
|
- <a href="/logs" @click="mobileMenuOpen = false" class="flex items-center gap-3 px-4 py-3 text-gray-200 rounded-lg font-medium text-base transition-all duration-300 hover:text-white hover:bg-white/10">
|
|
|
- <i class="fas fa-user-friends text-lg"></i>
|
|
|
- <span>{{ _("Usuarios") }}</span>
|
|
|
- </a>
|
|
|
- <a href="/reports" @click="mobileMenuOpen = false" class="flex items-center gap-3 px-4 py-3 text-gray-200 rounded-lg font-medium text-base transition-all duration-300 hover:text-white hover:bg-white/10">
|
|
|
- <i class="fas fa-chart-simple text-lg"></i>
|
|
|
- <span>{{ _("Reportes") }}</span>
|
|
|
- </a>
|
|
|
- <a href="/blacklist" @click="mobileMenuOpen = false" class="flex items-center gap-3 px-4 py-3 text-gray-200 rounded-lg font-medium text-base transition-all duration-300 hover:text-white hover:bg-white/10">
|
|
|
- <i class="fas fa-ban text-lg"></i>
|
|
|
- <span>{{ _("Blacklist") }}</span>
|
|
|
- </a>
|
|
|
- <a href="/auditoria" @click="mobileMenuOpen = false" class="flex items-center gap-3 px-4 py-3 text-gray-200 rounded-lg font-medium text-base transition-all duration-300 hover:text-white hover:bg-white/10">
|
|
|
- <i class="fas fa-magnifying-glass text-lg"></i>
|
|
|
- <span>{{ _("Auditoría") }}</span>
|
|
|
- </a>
|
|
|
- </div>
|
|
|
- <!-- Botones Squid y Web en fila -->
|
|
|
- <div class="flex flex-row gap-3 mb-8">
|
|
|
- <div class="flex flex-1 gap-2">
|
|
|
- <button onclick="confirmSquidUpdate(); mobileMenuOpen = false" class="flex-1 flex items-center justify-center gap-2 px-3 py-3 rounded-lg font-semibold text-sm bg-gradient-to-r from-emerald-600 to-emerald-400 text-white shadow hover:from-emerald-700 hover:to-emerald-600 transition-all duration-300">
|
|
|
- <i class="fas fa-sync-alt"></i>
|
|
|
- <span>{{ _("Squid") }}</span>
|
|
|
- </button>
|
|
|
- <button onclick="confirmWebUpdate(); mobileMenuOpen = false" class="flex-1 flex items-center justify-center gap-2 px-3 py-3 rounded-lg font-semibold text-sm bg-gradient-to-r from-purple-600 to-purple-400 text-white shadow hover:from-purple-700 hover:to-purple-600 transition-all duration-300">
|
|
|
- <i class="fas fa-cloud-download-alt"></i>
|
|
|
- <span>{{ _("Web") }}</span>
|
|
|
- </button>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
-</nav>
|
|
|
-
|
|
|
-<!-- Custom Confirm Modal -->
|
|
|
-{% include 'components/confirm_modal.html' %}
|
|
|
-
|
|
|
-<!-- Scripts -->
|
|
|
-<script src="{{ url_for('static', filename='src/tailwind.min.js') }}"></script>
|
|
|
-<script defer src="{{ url_for('static', filename='src/alpine.min.js') }}"></script>
|
|
|
-<script src="{{ url_for('static', filename='js/confirm_modal.js') }}"></script>
|
|
|
-<script>
|
|
|
- window.__NAV_I18N__ = {
|
|
|
- noNewNotifications: "{{ _('No hay notificaciones nuevas') }}",
|
|
|
- systemSource: "{{ _('Sistema') }}",
|
|
|
- errorHttp: "{{ _('Error HTTP:') }}",
|
|
|
- serverMarkReadError: "{{ _('Error del servidor al marcar como leída:') }}",
|
|
|
- markReadError: "{{ _('Error al marcar notificación como leída:') }}",
|
|
|
- unknownError: "{{ _('Error desconocido') }}",
|
|
|
- fetchNotificationsError: "{{ _('Error al obtener notificaciones:') }}",
|
|
|
- errorUpdateSquid: "{{ _('Error al actualizar Squid') }}",
|
|
|
- errorConnection: "{{ _('Error de conexión') }}",
|
|
|
- errorUpdateWeb: "{{ _('Error al actualizar la aplicación web') }}",
|
|
|
- confirmUpdateSquid: "{{ _('¿Estás seguro de que deseas actualizar el servicio Squid? Guarda tu configuración antes de continuar, el servicio se reiniciará automáticamente.') }}",
|
|
|
- confirmUpdateWeb: "{{ _('¿Estás seguro de que deseas actualizar SquidStats? Se actualizará la interfaz web, funcionalidades y correcciones de seguridad.') }}"
|
|
|
- };
|
|
|
-</script>
|
|
|
-<script>
|
|
|
- // Enhanced Navbar Functionality with Real-time Notifications
|
|
|
- document.addEventListener("DOMContentLoaded", function () {
|
|
|
- const i18n = window.__NAV_I18N__ || {};
|
|
|
- // Tooltip functionality
|
|
|
- function initTooltips() {
|
|
|
- const elements = document.querySelectorAll('[data-tooltip]');
|
|
|
- elements.forEach(element => {
|
|
|
- const tooltipText = element.getAttribute('data-tooltip');
|
|
|
- const tooltip = document.createElement('div');
|
|
|
- tooltip.className = 'absolute invisible bg-gray-900 text-white text-xs rounded py-1 px-2 top-full left-1/2 transform -translate-x-1/2 mt-2 whitespace-nowrap z-50 opacity-0 transition-opacity duration-200';
|
|
|
- tooltip.textContent = tooltipText;
|
|
|
- element.appendChild(tooltip);
|
|
|
-
|
|
|
- element.addEventListener('mouseenter', function() {
|
|
|
- tooltip.classList.remove('invisible', 'opacity-0');
|
|
|
- tooltip.classList.add('visible', 'opacity-100');
|
|
|
- });
|
|
|
-
|
|
|
- element.addEventListener('mouseleave', function() {
|
|
|
- tooltip.classList.remove('visible', 'opacity-100');
|
|
|
- tooltip.classList.add('invisible', 'opacity-0');
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- // Navbar scroll effect
|
|
|
- function initNavbarScroll() {
|
|
|
- const navbar = document.querySelector('nav');
|
|
|
- let lastScrollY = window.scrollY;
|
|
|
-
|
|
|
- window.addEventListener('scroll', () => {
|
|
|
- if (window.scrollY > lastScrollY && window.scrollY > 100) {
|
|
|
- navbar.style.transform = 'translateY(-100%)';
|
|
|
- } else {
|
|
|
- navbar.style.transform = 'translateY(0)';
|
|
|
- }
|
|
|
- lastScrollY = window.scrollY;
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- // Active link highlighting
|
|
|
- function setActiveLink() {
|
|
|
- const currentPath = window.location.pathname;
|
|
|
- const links = document.querySelectorAll('nav a[href]');
|
|
|
-
|
|
|
- links.forEach(link => {
|
|
|
- if (link.getAttribute('href') === currentPath) {
|
|
|
- link.classList.add('text-white', 'bg-white/20');
|
|
|
- link.classList.remove('text-gray-200', 'hover:bg-white/10');
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- // Función para obtener el token CSRF de forma segura
|
|
|
- function getCSRFToken() {
|
|
|
- const metaTag = document.querySelector('meta[name="csrf-token"]');
|
|
|
- if (metaTag) {
|
|
|
- return metaTag.getAttribute('content');
|
|
|
- }
|
|
|
- console.warn('CSRF token meta tag no encontrado');
|
|
|
- return '';
|
|
|
- }
|
|
|
-
|
|
|
- // Enhanced Notifications System with WebSocket
|
|
|
- function initNotifications() {
|
|
|
- let notificationSocket = null;
|
|
|
- let notificationsData = {
|
|
|
- unread_count: 0,
|
|
|
- notifications: []
|
|
|
- };
|
|
|
-
|
|
|
- // Conectar WebSocket
|
|
|
- function connectWebSocket() {
|
|
|
- // Flask-SocketIO se conecta automáticamente al host actual
|
|
|
- notificationSocket = io();
|
|
|
-
|
|
|
- notificationSocket.on('connect', function() {
|
|
|
- console.log('Conectado al servidor de notificaciones Squid');
|
|
|
- });
|
|
|
-
|
|
|
- notificationSocket.on('new_notification', function(data) {
|
|
|
- addNewNotification(data.notification);
|
|
|
- updateNotificationBadges(data.unread_count);
|
|
|
- showNotificationToast(data.notification);
|
|
|
- });
|
|
|
-
|
|
|
- notificationSocket.on('notification_updated', function(data) {
|
|
|
- updateExistingNotification(data.notification);
|
|
|
- updateNotificationBadges(data.unread_count);
|
|
|
- showNotificationToast(data.notification);
|
|
|
- });
|
|
|
-
|
|
|
- notificationSocket.on('disconnect', function() {
|
|
|
- // Reconectar después de 5 segundos
|
|
|
- setTimeout(connectWebSocket, 5000);
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- function addNewNotification(notification) {
|
|
|
- // Evitar duplicados por ID
|
|
|
- const existingIndex = notificationsData.notifications.findIndex(n => n.id === notification.id);
|
|
|
- if (existingIndex === -1) {
|
|
|
- notificationsData.notifications.unshift(notification);
|
|
|
- if (!notification.read) {
|
|
|
- notificationsData.unread_count++;
|
|
|
- }
|
|
|
-
|
|
|
- // Actualizar ambas listas (desktop y móvil)
|
|
|
- updateNotificationLists();
|
|
|
- updateNotificationBadges(notificationsData.unread_count);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- function updateExistingNotification(notification) {
|
|
|
- // Buscar y actualizar la notificación existente
|
|
|
- const existingIndex = notificationsData.notifications.findIndex(n => n.id === notification.id);
|
|
|
- if (existingIndex !== -1) {
|
|
|
- // Actualizar la notificación existente
|
|
|
- notificationsData.notifications[existingIndex] = notification;
|
|
|
- // Moverla al principio de la lista
|
|
|
- const updated = notificationsData.notifications.splice(existingIndex, 1)[0];
|
|
|
- notificationsData.notifications.unshift(updated);
|
|
|
- } else {
|
|
|
- // Si no existe, agregarla como nueva
|
|
|
- notificationsData.notifications.unshift(notification);
|
|
|
- }
|
|
|
-
|
|
|
- // Actualizar ambas listas (desktop y móvil)
|
|
|
- updateNotificationLists();
|
|
|
- }
|
|
|
-
|
|
|
- function showNotificationToast(notification) {
|
|
|
- if (!window.toastr) return;
|
|
|
-
|
|
|
- // Construir el título con la fuente
|
|
|
- const source = notification.source === 'squid' ? 'Squid' :
|
|
|
- notification.source === 'git' ? 'Git' : (i18n.systemSource || 'Sistema');
|
|
|
- const title = notification.count && notification.count > 1 ?
|
|
|
- `${source} (×${notification.count})` : source;
|
|
|
-
|
|
|
- // Mostrar notificación según el tipo
|
|
|
- if (notification.type === 'error') {
|
|
|
- toastr.error(notification.message, title);
|
|
|
- } else if (notification.type === 'warning') {
|
|
|
- toastr.warning(notification.message, title);
|
|
|
- } else if (notification.type === 'success') {
|
|
|
- toastr.success(notification.message, title);
|
|
|
- } else {
|
|
|
- toastr.info(notification.message, title);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- function updateNotificationLists() {
|
|
|
- const desktopUl = document.querySelector(".notifications");
|
|
|
- const mobileUl = document.querySelector(".notifications-mobile");
|
|
|
-
|
|
|
- const renderNotificationList = (ul, notifications) => {
|
|
|
- if (!ul) return;
|
|
|
-
|
|
|
- ul.innerHTML = "";
|
|
|
-
|
|
|
- // Usar el estado local actual - SOLO notificaciones no leídas
|
|
|
- const unreadNotifications = notificationsData.notifications.filter(n => !n.read);
|
|
|
- const notificationsToShow = unreadNotifications.slice(0, 10);
|
|
|
-
|
|
|
- if (notificationsToShow.length > 0) {
|
|
|
- notificationsToShow.forEach((notification) => {
|
|
|
- let bgColor, textColor;
|
|
|
-
|
|
|
- switch(notification.type) {
|
|
|
- case 'success':
|
|
|
- bgColor = 'bg-green-100';
|
|
|
- textColor = 'text-green-600';
|
|
|
- break;
|
|
|
- case 'warning':
|
|
|
- bgColor = 'bg-yellow-100';
|
|
|
- textColor = 'text-yellow-600';
|
|
|
- break;
|
|
|
- case 'error':
|
|
|
- bgColor = 'bg-red-100';
|
|
|
- textColor = 'text-red-600';
|
|
|
- break;
|
|
|
- case 'info':
|
|
|
- default:
|
|
|
- bgColor = 'bg-blue-100';
|
|
|
- textColor = 'text-blue-600';
|
|
|
- }
|
|
|
-
|
|
|
- // Create list item safely
|
|
|
- const li = document.createElement('li');
|
|
|
- li.className = `px-4 py-3 flex items-start hover:bg-gray-50 cursor-pointer notification-item ${
|
|
|
- notification.read ? 'opacity-60' : ''
|
|
|
- }`;
|
|
|
- li.dataset.id = notification.id;
|
|
|
-
|
|
|
- const iconSpan = document.createElement('span');
|
|
|
- iconSpan.className = `inline-flex items-center justify-center h-8 w-8 rounded-full ${bgColor} ${textColor} mr-3`;
|
|
|
- const icon = document.createElement('i');
|
|
|
- icon.className = `fas ${notification.icon}`;
|
|
|
- iconSpan.appendChild(icon);
|
|
|
-
|
|
|
- const contentDiv = document.createElement('div');
|
|
|
- contentDiv.className = 'flex-1';
|
|
|
-
|
|
|
- const sourceP = document.createElement('p');
|
|
|
- sourceP.className = 'text-sm font-medium text-gray-900';
|
|
|
- sourceP.textContent = notification.source === 'squid' ? 'Squid' :
|
|
|
- notification.source === 'git' ? 'Git' : (i18n.systemSource || 'Sistema');
|
|
|
-
|
|
|
- const messageP = document.createElement('p');
|
|
|
- messageP.className = 'text-sm text-gray-700 mt-1';
|
|
|
- messageP.textContent = notification.message;
|
|
|
-
|
|
|
- const timeSpan = document.createElement('span');
|
|
|
- timeSpan.className = 'text-xs text-gray-400 mt-1';
|
|
|
- timeSpan.textContent = notification.time;
|
|
|
-
|
|
|
- contentDiv.appendChild(sourceP);
|
|
|
- contentDiv.appendChild(messageP);
|
|
|
- contentDiv.appendChild(timeSpan);
|
|
|
-
|
|
|
- li.appendChild(iconSpan);
|
|
|
- li.appendChild(contentDiv);
|
|
|
-
|
|
|
- if (!notification.read) {
|
|
|
- const badge = document.createElement('span');
|
|
|
- badge.className = 'w-2 h-2 bg-blue-500 rounded-full mt-2 flex-shrink-0';
|
|
|
- li.appendChild(badge);
|
|
|
- }
|
|
|
-
|
|
|
- ul.appendChild(li);
|
|
|
- });
|
|
|
- } else {
|
|
|
- ul.innerHTML = `
|
|
|
- <li class='px-4 py-3 text-gray-500 text-center'>
|
|
|
- ${i18n.noNewNotifications || 'No hay notificaciones nuevas'}
|
|
|
- </li>
|
|
|
- `;
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- renderNotificationList(desktopUl, notificationsData.notifications);
|
|
|
- renderNotificationList(mobileUl, notificationsData.notifications);
|
|
|
- }
|
|
|
-
|
|
|
- function updateNotificationBadges(count) {
|
|
|
- const badges = document.querySelectorAll('.notification-badge');
|
|
|
- badges.forEach(badge => {
|
|
|
- if (count > 0) {
|
|
|
- badge.textContent = count > 99 ? '99+' : count.toString();
|
|
|
- badge.classList.remove('hidden');
|
|
|
- } else {
|
|
|
- badge.classList.add('hidden');
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- function markAsRead(notificationIds) {
|
|
|
- const csrfToken = getCSRFToken();
|
|
|
- fetch('/api/notifications/mark-read', {
|
|
|
- method: 'POST',
|
|
|
- headers: {
|
|
|
- 'Content-Type': 'application/json',
|
|
|
- 'X-CSRF-Token': csrfToken,
|
|
|
- },
|
|
|
- body: JSON.stringify({
|
|
|
- ids: notificationIds
|
|
|
- })
|
|
|
- })
|
|
|
- .then(response => {
|
|
|
- if (!response.ok) {
|
|
|
- throw new Error(`${i18n.errorHttp || 'Error HTTP:'} ${response.status}`);
|
|
|
- }
|
|
|
- return response.json();
|
|
|
- })
|
|
|
- .then(data => {
|
|
|
- if (data.success) {
|
|
|
- // CORRECCIÓN: Filtrar notificaciones marcadas del estado local
|
|
|
- notificationsData.notifications = notificationsData.notifications.filter(
|
|
|
- notification => !notificationIds.includes(notification.id)
|
|
|
- );
|
|
|
-
|
|
|
- notificationsData.unread_count = data.unread_count;
|
|
|
- updateNotificationBadges(data.unread_count);
|
|
|
- updateNotificationLists();
|
|
|
- } else {
|
|
|
- console.error(`${i18n.serverMarkReadError || 'Error del servidor al marcar como leída:'} ${data.error}`);
|
|
|
- showNotificationToast({
|
|
|
- type: 'error',
|
|
|
- message: `${i18n.markReadError || 'Error al marcar notificación como leída: '} ${data.error || i18n.unknownError || 'Error desconocido'}`
|
|
|
- });
|
|
|
- }
|
|
|
- })
|
|
|
- .catch(error => {
|
|
|
- showNotificationToast({
|
|
|
- type: 'error',
|
|
|
- message: `${i18n.markReadError || 'Error al marcar notificación como leída: '} ${error.message}`
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- function fetchInitialNotifications() {
|
|
|
- fetch("/api/notifications")
|
|
|
- .then((res) => {
|
|
|
- if (!res.ok) {
|
|
|
- throw new Error(`${i18n.errorHttp || 'Error HTTP:'} ${res.status}`);
|
|
|
- }
|
|
|
- return res.json();
|
|
|
- })
|
|
|
- .then((data) => {
|
|
|
- // REEMPLAZAR completamente el estado local
|
|
|
- notificationsData.notifications = data.notifications || [];
|
|
|
- notificationsData.unread_count = data.unread_count || 0;
|
|
|
- updateNotificationLists();
|
|
|
- updateNotificationBadges(data.unread_count);
|
|
|
- })
|
|
|
- .catch((error) => {
|
|
|
- console.error(`${i18n.fetchNotificationsError || 'Error fetching notifications:'} ${error}`);
|
|
|
- notificationsData.notifications = [];
|
|
|
- notificationsData.unread_count = 0;
|
|
|
- updateNotificationLists();
|
|
|
- updateNotificationBadges(0);
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- // Event listeners para marcar como leído
|
|
|
- document.addEventListener('click', function(e) {
|
|
|
- const notificationItem = e.target.closest('.notification-item');
|
|
|
- if (notificationItem) {
|
|
|
- const notificationId = parseInt(notificationItem.dataset.id);
|
|
|
- markAsRead([notificationId]);
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- // Inicializar
|
|
|
- fetchInitialNotifications();
|
|
|
- connectWebSocket();
|
|
|
- }
|
|
|
-
|
|
|
- // Initialize all functionality
|
|
|
- initTooltips();
|
|
|
- initNavbarScroll();
|
|
|
- setActiveLink();
|
|
|
- initNotifications();
|
|
|
- });
|
|
|
-
|
|
|
- // Close modals when clicking outside
|
|
|
- document.addEventListener("click", function (e) {
|
|
|
- if (e.target.classList.contains("modal-overlay")) {
|
|
|
- const modals = document.querySelectorAll("[x-show]");
|
|
|
- modals.forEach((modal) => {
|
|
|
- const alpineData = Alpine.$data(modal);
|
|
|
- if (alpineData) {
|
|
|
- alpineData.showSquidModal = false;
|
|
|
- alpineData.showWebModal = false;
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- // Add escape key handling for modals
|
|
|
- document.addEventListener("keydown", function (e) {
|
|
|
- if (e.key === "Escape") {
|
|
|
- const modals = document.querySelectorAll("[x-show]");
|
|
|
- modals.forEach((modal) => {
|
|
|
- const alpineData = Alpine.$data(modal);
|
|
|
- if (alpineData) {
|
|
|
- alpineData.showSquidModal = false;
|
|
|
- alpineData.showWebModal = false;
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- // Mobile menu close on outside click
|
|
|
- document.addEventListener('click', function(event) {
|
|
|
- const mobileMenu = document.querySelector('[x-data]');
|
|
|
- const hamburger = document.querySelector('.lg\\:hidden');
|
|
|
- const mobileMenuContent = document.querySelector('.absolute.top-full');
|
|
|
-
|
|
|
- if (mobileMenuContent && mobileMenuContent.style.display !== 'none') {
|
|
|
- const isClickInside = hamburger.contains(event.target) || mobileMenuContent.contains(event.target);
|
|
|
-
|
|
|
- if (!isClickInside) {
|
|
|
- const alpineData = Alpine.$data(mobileMenu);
|
|
|
- if (alpineData) {
|
|
|
- alpineData.mobileMenuOpen = false;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- // Función para obtener el token CSRF
|
|
|
- function getCSRFToken() {
|
|
|
- const metaTag = document.querySelector('meta[name="csrf-token"]');
|
|
|
- return metaTag ? metaTag.getAttribute('content') : '';
|
|
|
- }
|
|
|
-
|
|
|
- // Funciones de confirmación para actualizaciones
|
|
|
- function confirmSquidUpdate() {
|
|
|
- showCustomConfirm(
|
|
|
- i18n.confirmUpdateSquid || '¿Estás seguro de que deseas actualizar el servicio Squid? Guarda tu configuración antes de continuar, el servicio se reiniciará automáticamente.',
|
|
|
- async () => {
|
|
|
- try {
|
|
|
- const response = await fetch('/install', {
|
|
|
- method: 'POST',
|
|
|
- headers: {
|
|
|
- 'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
- 'X-CSRFToken': getCSRFToken()
|
|
|
- },
|
|
|
- body: new URLSearchParams({ csrf_token: getCSRFToken() })
|
|
|
- });
|
|
|
- if (response.ok) {
|
|
|
- window.location.reload();
|
|
|
- } else {
|
|
|
- alert(i18n.errorUpdateSquid || 'Error al actualizar Squid');
|
|
|
- }
|
|
|
- } catch (error) {
|
|
|
- alert(i18n.errorConnection || 'Error de conexión');
|
|
|
- }
|
|
|
- }
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- function confirmWebUpdate() {
|
|
|
- showCustomConfirm(
|
|
|
- i18n.confirmUpdateWeb || '¿Estás seguro de que deseas actualizar SquidStats? Se actualizará la interfaz web, funcionalidades y correcciones de seguridad.',
|
|
|
- async () => {
|
|
|
- try {
|
|
|
- const response = await fetch('/update', {
|
|
|
- method: 'POST',
|
|
|
- headers: {
|
|
|
- 'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
- 'X-CSRFToken': getCSRFToken()
|
|
|
- },
|
|
|
- body: new URLSearchParams({ csrf_token: getCSRFToken() })
|
|
|
- });
|
|
|
- if (response.ok) {
|
|
|
- window.location.reload();
|
|
|
- } else {
|
|
|
- alert(i18n.errorUpdateWeb || 'Error al actualizar la aplicación web');
|
|
|
- }
|
|
|
- } catch (error) {
|
|
|
- alert(i18n.errorConnection || 'Error de conexión');
|
|
|
- }
|
|
|
- }
|
|
|
- );
|
|
|
- }
|
|
|
-</script>
|