1
0
mirror of https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git synced 2025-08-14 00:25:46 +02:00

add websockets suppor9

This commit is contained in:
MoonTestUse1
2025-01-05 02:31:16 +06:00
parent 7f94d3e7f8
commit 82a554068e
2 changed files with 30 additions and 9 deletions

View File

@@ -2,7 +2,6 @@ from fastapi import WebSocket
from typing import Dict, List
import json
import logging
import asyncio
logger = logging.getLogger(__name__)
@@ -26,14 +25,20 @@ class NotificationManager:
async def broadcast_to_admins(self, message: dict):
"""Отправка сообщения всем подключенным админам"""
logger.info(f"Broadcasting to admins: {message}")
logger.info(f"Number of admin connections: {len(self.active_connections['admin'])}")
if not self.active_connections["admin"]:
logger.warning("No admin connections available")
return
disconnected = []
for connection in self.active_connections["admin"]:
try:
await connection.send_json(message)
logger.info("Message sent successfully")
logger.info("Message sent successfully to admin")
except Exception as e:
logger.error(f"Error sending message: {e}")
logger.error(f"Error sending message to admin: {e}")
disconnected.append(connection)
continue
@@ -44,14 +49,20 @@ class NotificationManager:
async def broadcast_to_employees(self, employee_id: int, message: dict):
"""Отправка сообщения конкретному сотруднику"""
logger.info(f"Broadcasting to employee {employee_id}: {message}")
logger.info(f"Number of employee connections: {len(self.active_connections['employee'])}")
if not self.active_connections["employee"]:
logger.warning("No employee connections available")
return
disconnected = []
for connection in self.active_connections["employee"]:
try:
await connection.send_json(message)
logger.info("Message sent successfully")
logger.info("Message sent successfully to employee")
except Exception as e:
logger.error(f"Error sending message: {e}")
logger.error(f"Error sending message to employee: {e}")
disconnected.append(connection)
continue

View File

@@ -94,10 +94,15 @@ const fetchData = async () => {
requests.value = requestsResponse.data
console.log('AdminDashboard: Received statistics:', statsResponse.data)
// Принудительно обновляем реактивное состояние
// Обновляем статистику
statistics.value = {
total: statsResponse.data.total,
by_status: statsResponse.data.by_status || {}
by_status: {
new: statsResponse.data.by_status?.new || 0,
in_progress: statsResponse.data.by_status?.in_progress || 0,
completed: statsResponse.data.by_status?.completed || 0,
rejected: statsResponse.data.by_status?.rejected || 0
}
}
} catch (error) {
console.error('Error fetching data:', error)
@@ -113,10 +118,15 @@ const handleWebSocketMessage = (data: any) => {
console.log('AdminDashboard: Old statistics:', statistics.value)
console.log('AdminDashboard: Updating statistics:', data.statistics)
// Принудительно обновляем реактивное состояние
// Обновляем статистику
statistics.value = {
total: data.statistics.total,
by_status: data.statistics.by_status || {}
by_status: {
new: data.statistics.by_status?.new || 0,
in_progress: data.statistics.by_status?.in_progress || 0,
completed: data.statistics.by_status?.completed || 0,
rejected: data.statistics.by_status?.rejected || 0
}
}
console.log('AdminDashboard: New statistics:', statistics.value)