Linking backend data to frontend
This commit is contained in:
6
.gitignore
vendored
6
.gitignore
vendored
@@ -92,4 +92,8 @@ docker-compose.override.yml
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
# Cached mesh data files
|
# Cached mesh data files
|
||||||
frontend/data/*.json
|
frontend/data/*.json
|
||||||
|
|
||||||
|
# Demo seed data: ignore demo mux outputs and the seeding command
|
||||||
|
backend/api/management/commands/seed_demo_data.py
|
||||||
|
backend/data/multiplexors/DemoMux.csv
|
||||||
@@ -6,12 +6,28 @@ import Sidebar from '../../../components/ui/Sidebar'
|
|||||||
import useNavigationStore from '../../store/navigationStore'
|
import useNavigationStore from '../../store/navigationStore'
|
||||||
import DetectorList from '../../../components/alerts/DetectorList'
|
import DetectorList from '../../../components/alerts/DetectorList'
|
||||||
import ExportMenu from '../../../components/ui/ExportMenu'
|
import ExportMenu from '../../../components/ui/ExportMenu'
|
||||||
|
import { useSession } from 'next-auth/react'
|
||||||
|
|
||||||
const AlertsPage: React.FC = () => {
|
const AlertsPage: React.FC = () => {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const searchParams = useSearchParams()
|
const searchParams = useSearchParams()
|
||||||
const { currentObject, setCurrentObject } = useNavigationStore()
|
const { currentObject, setCurrentObject } = useNavigationStore()
|
||||||
const [selectedDetectors, setSelectedDetectors] = useState<number[]>([])
|
const [selectedDetectors, setSelectedDetectors] = useState<number[]>([])
|
||||||
|
const { data: session } = useSession()
|
||||||
|
|
||||||
|
type AlertItem = {
|
||||||
|
id: number
|
||||||
|
type: string
|
||||||
|
message: string
|
||||||
|
timestamp: string
|
||||||
|
acknowledged: boolean
|
||||||
|
priority: string
|
||||||
|
detector_id?: number
|
||||||
|
detector_name?: string
|
||||||
|
location?: string
|
||||||
|
object?: string
|
||||||
|
}
|
||||||
|
const [alerts, setAlerts] = useState<AlertItem[]>([])
|
||||||
|
|
||||||
const urlObjectId = searchParams.get('objectId')
|
const urlObjectId = searchParams.get('objectId')
|
||||||
const urlObjectTitle = searchParams.get('objectTitle')
|
const urlObjectTitle = searchParams.get('objectTitle')
|
||||||
@@ -24,6 +40,30 @@ const AlertsPage: React.FC = () => {
|
|||||||
}
|
}
|
||||||
}, [urlObjectId, urlObjectTitle, currentObject.id, setCurrentObject])
|
}, [urlObjectId, urlObjectTitle, currentObject.id, setCurrentObject])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const loadAlerts = async () => {
|
||||||
|
try {
|
||||||
|
const params = new URLSearchParams()
|
||||||
|
if (currentObject.id) params.set('objectId', currentObject.id)
|
||||||
|
const res = await fetch(`/api/get-alerts?${params.toString()}`, { cache: 'no-store' })
|
||||||
|
if (!res.ok) return
|
||||||
|
const payload = await res.json()
|
||||||
|
console.log('[AlertsPage] GET /api/get-alerts', {
|
||||||
|
url: `/api/get-alerts?${params.toString()}`,
|
||||||
|
status: res.status,
|
||||||
|
payload,
|
||||||
|
})
|
||||||
|
const data = Array.isArray(payload?.data) ? payload.data : (payload?.data?.alerts || [])
|
||||||
|
console.log('[AlertsPage] parsed alerts:', data)
|
||||||
|
setAlerts(data as AlertItem[])
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Failed to load alerts:', e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
loadAlerts()
|
||||||
|
|
||||||
|
}, [currentObject.id])
|
||||||
|
|
||||||
const handleBackClick = () => {
|
const handleBackClick = () => {
|
||||||
router.push('/dashboard')
|
router.push('/dashboard')
|
||||||
}
|
}
|
||||||
@@ -36,13 +76,39 @@ const AlertsPage: React.FC = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleExport = (format: 'csv' | 'pdf') => {
|
const handleExport = async (format: 'csv' | 'pdf', hours: number) => {
|
||||||
// TODO: добавить функционал по экспорту
|
try {
|
||||||
console.log(`Exporting ${selectedDetectors.length} items as ${format}`)
|
const res = await fetch(`/api/get-reports`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
...(session?.accessToken ? { Authorization: `Bearer ${session.accessToken}` } : {}),
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ format: format, hours }),
|
||||||
|
credentials: 'include',
|
||||||
|
})
|
||||||
|
if (!res.ok) {
|
||||||
|
const errText = await res.text()
|
||||||
|
throw new Error(`Export failed: ${res.status} ${errText}`)
|
||||||
|
}
|
||||||
|
const blob = await res.blob()
|
||||||
|
const contentDisposition = res.headers.get('Content-Disposition') || res.headers.get('content-disposition')
|
||||||
|
const filenameMatch = contentDisposition?.match(/filename="(.+)"/)
|
||||||
|
const timestamp = new Date().toISOString().replace(/[:.]/g, '-').replace(/T/g, '_')
|
||||||
|
const filename = filenameMatch ? filenameMatch[1] : `alerts_report_${timestamp}.${format}`
|
||||||
|
const url = window.URL.createObjectURL(blob)
|
||||||
|
const link = document.createElement('a')
|
||||||
|
link.href = url
|
||||||
|
link.download = filename
|
||||||
|
document.body.appendChild(link)
|
||||||
|
link.click()
|
||||||
|
document.body.removeChild(link)
|
||||||
|
window.URL.revokeObjectURL(url)
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error:', error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex h-screen bg-[#0e111a]">
|
<div className="flex h-screen bg-[#0e111a]">
|
||||||
<Sidebar
|
<Sidebar
|
||||||
@@ -77,7 +143,6 @@ const AlertsPage: React.FC = () => {
|
|||||||
<h1 className="text-white text-2xl font-semibold">Уведомления и тревоги</h1>
|
<h1 className="text-white text-2xl font-semibold">Уведомления и тревоги</h1>
|
||||||
|
|
||||||
<div className="flex items-center gap-4">
|
<div className="flex items-center gap-4">
|
||||||
{/* Кол-во выбранных объектов */}
|
|
||||||
{selectedDetectors.length > 0 && (
|
{selectedDetectors.length > 0 && (
|
||||||
<span className="text-gray-300 text-sm">
|
<span className="text-gray-300 text-sm">
|
||||||
Выбрано: <span className="text-white font-medium">{selectedDetectors.length}</span>
|
Выбрано: <span className="text-white font-medium">{selectedDetectors.length}</span>
|
||||||
@@ -93,6 +158,81 @@ const AlertsPage: React.FC = () => {
|
|||||||
selectedDetectors={selectedDetectors}
|
selectedDetectors={selectedDetectors}
|
||||||
onDetectorSelect={handleDetectorSelect}
|
onDetectorSelect={handleDetectorSelect}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
{/* История тревог */}
|
||||||
|
<div className="mt-6 bg-[#161824] rounded-[20px] p-6">
|
||||||
|
<div className="mb-4 flex items-center justify-between">
|
||||||
|
<h2 className="text-xl font-semibold text-white">История тревог</h2>
|
||||||
|
<span className="text-sm text-gray-400">Всего: {alerts.length}</span>
|
||||||
|
</div>
|
||||||
|
<div className="overflow-x-auto">
|
||||||
|
<table className="w-full">
|
||||||
|
<thead>
|
||||||
|
<tr className="border-b border-gray-700">
|
||||||
|
<th className="text-left text-white font-medium py-3">Детектор</th>
|
||||||
|
<th className="text-left text-white font-medium py-3">Статус</th>
|
||||||
|
<th className="text-left text-white font-medium py-3">Сообщение</th>
|
||||||
|
<th className="text-left text-white font-medium py-3">Местоположение</th>
|
||||||
|
<th className="text-left text-white font-medium py-3">Приоритет</th>
|
||||||
|
<th className="text-left text-white font-medium py-3">Подтверждено</th>
|
||||||
|
<th className="text-left text-white font-medium py-3">Время</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{alerts.map((item) => (
|
||||||
|
<tr key={item.id} className="border-b border-gray-700 hover:bg-gray-800/50 transition-colors">
|
||||||
|
<td className="py-4">
|
||||||
|
<div className="text-sm font-medium text-white">{item.detector_name || 'Детектор'}</div>
|
||||||
|
{item.detector_id ? (
|
||||||
|
<div className="text-sm text-gray-400">ID: {item.detector_id}</div>
|
||||||
|
) : null}
|
||||||
|
</td>
|
||||||
|
<td className="py-4">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<div
|
||||||
|
className="w-3 h-3 rounded-full"
|
||||||
|
style={{ backgroundColor: item.type === 'critical' ? '#b3261e' : item.type === 'warning' ? '#fd7c22' : '#00ff00' }}
|
||||||
|
></div>
|
||||||
|
<span className="text-sm text-gray-300">
|
||||||
|
{item.type === 'critical' ? 'Критический' : item.type === 'warning' ? 'Предупреждение' : 'Информация'}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td className="py-4">
|
||||||
|
<div className="text-sm text-white">{item.message}</div>
|
||||||
|
</td>
|
||||||
|
<td className="py-4">
|
||||||
|
<div className="text-sm text-white">{item.location || '-'}</div>
|
||||||
|
</td>
|
||||||
|
<td className="py-4">
|
||||||
|
<span
|
||||||
|
className="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium text-white"
|
||||||
|
style={{ backgroundColor: item.priority === 'high' ? '#b3261e' : item.priority === 'medium' ? '#fd7c22' : '#00ff00' }}
|
||||||
|
>
|
||||||
|
{item.priority === 'high' ? 'Высокий' : item.priority === 'medium' ? 'Средний' : 'Низкий'}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td className="py-4">
|
||||||
|
<span className={`inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium ${
|
||||||
|
item.acknowledged ? 'bg-green-100 text-green-800' : 'bg-red-100 text-red-800'
|
||||||
|
}`}>
|
||||||
|
{item.acknowledged ? 'Да' : 'Нет'}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td className="py-4">
|
||||||
|
<div className="text-sm text-gray-300">{new Date(item.timestamp).toLocaleString('ru-RU')}</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
{alerts.length === 0 && (
|
||||||
|
<tr>
|
||||||
|
<td colSpan={7} className="py-8 text-center text-gray-400">Записей не найдено</td>
|
||||||
|
</tr>
|
||||||
|
)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import React, { useEffect, useCallback } from 'react'
|
import React, { useEffect, useCallback, useState } from 'react'
|
||||||
import { useRouter, useSearchParams } from 'next/navigation'
|
import { useRouter, useSearchParams } from 'next/navigation'
|
||||||
import Sidebar from '../../../components/ui/Sidebar'
|
import Sidebar from '../../../components/ui/Sidebar'
|
||||||
import useNavigationStore from '../../store/navigationStore'
|
import useNavigationStore from '../../store/navigationStore'
|
||||||
@@ -9,8 +9,16 @@ import FloorNavigation from '../../../components/navigation/FloorNavigation'
|
|||||||
import DetectorMenu from '../../../components/navigation/DetectorMenu'
|
import DetectorMenu from '../../../components/navigation/DetectorMenu'
|
||||||
import Notifications from '../../../components/notifications/Notifications'
|
import Notifications from '../../../components/notifications/Notifications'
|
||||||
import NotificationDetectorInfo from '../../../components/notifications/NotificationDetectorInfo'
|
import NotificationDetectorInfo from '../../../components/notifications/NotificationDetectorInfo'
|
||||||
import ModelViewer from '../../../components/model/ModelViewer'
|
import dynamic from 'next/dynamic'
|
||||||
import detectorsData from '../../../data/detectors.json'
|
|
||||||
|
const ModelViewer = dynamic(() => import('../../../components/model/ModelViewer'), {
|
||||||
|
ssr: false,
|
||||||
|
loading: () => (
|
||||||
|
<div className="w-full h-full flex items-center justify-center bg-[#0e111a]">
|
||||||
|
<div className="text-gray-300 animate-pulse">Загрузка 3D-модуля…</div>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
})
|
||||||
|
|
||||||
interface DetectorType {
|
interface DetectorType {
|
||||||
detector_id: number
|
detector_id: number
|
||||||
@@ -66,7 +74,10 @@ const NavigationPage: React.FC = () => {
|
|||||||
setSelectedNotification,
|
setSelectedNotification,
|
||||||
setShowNotificationDetectorInfo
|
setShowNotificationDetectorInfo
|
||||||
} = useNavigationStore()
|
} = useNavigationStore()
|
||||||
|
|
||||||
|
const [detectorsData, setDetectorsData] = useState<{ detectors: Record<string, DetectorType> }>({ detectors: {} })
|
||||||
|
const [detectorsError, setDetectorsError] = useState<string | null>(null)
|
||||||
|
|
||||||
const urlObjectId = searchParams.get('objectId')
|
const urlObjectId = searchParams.get('objectId')
|
||||||
const urlObjectTitle = searchParams.get('objectTitle')
|
const urlObjectTitle = searchParams.get('objectTitle')
|
||||||
const objectId = currentObject.id || urlObjectId
|
const objectId = currentObject.id || urlObjectId
|
||||||
@@ -85,6 +96,27 @@ const NavigationPage: React.FC = () => {
|
|||||||
}
|
}
|
||||||
}, [urlObjectId, urlObjectTitle, currentObject.id, setCurrentObject])
|
}, [urlObjectId, urlObjectTitle, currentObject.id, setCurrentObject])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const loadDetectors = async () => {
|
||||||
|
try {
|
||||||
|
setDetectorsError(null)
|
||||||
|
const res = await fetch('/api/get-detectors', { cache: 'no-store' })
|
||||||
|
const text = await res.text()
|
||||||
|
let payload: any
|
||||||
|
try { payload = JSON.parse(text) } catch { payload = text }
|
||||||
|
console.log('[NavigationPage] GET /api/get-detectors', { status: res.status, payload })
|
||||||
|
if (!res.ok) throw new Error(typeof payload === 'string' ? payload : (payload?.error || 'Не удалось получить детекторов'))
|
||||||
|
const data = payload?.data ?? payload
|
||||||
|
const detectors = (data?.detectors ?? {}) as Record<string, DetectorType>
|
||||||
|
setDetectorsData({ detectors })
|
||||||
|
} catch (e: any) {
|
||||||
|
console.error('Ошибка загрузки детекторов:', e)
|
||||||
|
setDetectorsError(e?.message || 'Ошибка при загрузке детекторов')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
loadDetectors()
|
||||||
|
}, [])
|
||||||
|
|
||||||
const handleBackClick = () => {
|
const handleBackClick = () => {
|
||||||
router.push('/dashboard')
|
router.push('/dashboard')
|
||||||
}
|
}
|
||||||
@@ -170,6 +202,9 @@ const NavigationPage: React.FC = () => {
|
|||||||
onNotificationClick={handleNotificationClick}
|
onNotificationClick={handleNotificationClick}
|
||||||
onClose={closeNotifications}
|
onClose={closeNotifications}
|
||||||
/>
|
/>
|
||||||
|
{detectorsError && (
|
||||||
|
<div className="mt-2 text-sm text-red-400">{detectorsError}</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@@ -225,7 +260,7 @@ const NavigationPage: React.FC = () => {
|
|||||||
<div className="flex-1 overflow-hidden">
|
<div className="flex-1 overflow-hidden">
|
||||||
<div className="h-full">
|
<div className="h-full">
|
||||||
<ModelViewer
|
<ModelViewer
|
||||||
modelPath='/models/AerBIM-Monitor_ASM-HT-Viewer_Expo2017Astana_20250908_L_+1430.glb'
|
modelPath='/static-models/AerBIM_Monitor_ASM_HT_Viewer_Expo2017Astana_Level_+1430_custom_prop.glb'
|
||||||
onModelLoaded={handleModelLoaded}
|
onModelLoaded={handleModelLoaded}
|
||||||
onError={handleModelError}
|
onError={handleModelError}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -4,39 +4,21 @@ import React, { useState, useEffect } from 'react'
|
|||||||
import ObjectGallery from '../../../components/objects/ObjectGallery'
|
import ObjectGallery from '../../../components/objects/ObjectGallery'
|
||||||
import { ObjectData } from '../../../components/objects/ObjectCard'
|
import { ObjectData } from '../../../components/objects/ObjectCard'
|
||||||
import Sidebar from '../../../components/ui/Sidebar'
|
import Sidebar from '../../../components/ui/Sidebar'
|
||||||
import detectorsData from '../../../data/detectors.json'
|
|
||||||
|
|
||||||
// Интерфейс для данных объекта из JSON
|
// Универсальная функция для преобразования объекта из бэкенда в ObjectData
|
||||||
interface RawObjectData {
|
const transformRawToObjectData = (raw: any): ObjectData => {
|
||||||
name: string
|
const rawId = raw?.id ?? raw?.object_id ?? raw?.uuid ?? raw?.name
|
||||||
title: string
|
const object_id = typeof rawId === 'number' ? `object_${rawId}` : String(rawId ?? '')
|
||||||
description: string
|
|
||||||
image?: string
|
|
||||||
location: string
|
|
||||||
address: string
|
|
||||||
floors: number
|
|
||||||
area: number
|
|
||||||
type?: string
|
|
||||||
status?: string
|
|
||||||
zones: Array<{
|
|
||||||
zone_id: string
|
|
||||||
name: string
|
|
||||||
detectors: number[]
|
|
||||||
}>
|
|
||||||
}
|
|
||||||
|
|
||||||
// Функция для преобразования данных объекта из JSON
|
|
||||||
const transformObjectToObjectData = (objectId: string, objectData: RawObjectData): ObjectData => {
|
|
||||||
return {
|
return {
|
||||||
object_id: objectId,
|
object_id,
|
||||||
title: objectData.title || `Объект ${objectId}`,
|
title: raw?.title ?? `Объект ${object_id}`,
|
||||||
description: objectData.description || `Описание объекта ${objectData.title || objectId}`,
|
description: raw?.description ?? `Описание объекта ${raw?.title ?? object_id}`,
|
||||||
image: objectData.image || '/images/default-object.jpg',
|
image: raw?.image ?? '/images/test_image.png',
|
||||||
location: objectData.location || 'Не указано',
|
location: raw?.location ?? raw?.address ?? 'Не указано',
|
||||||
floors: objectData.floors,
|
floors: Number(raw?.floors ?? 0),
|
||||||
area: objectData.area.toString(),
|
area: String(raw?.area ?? ''),
|
||||||
type: objectData.type || 'object',
|
type: raw?.type ?? 'object',
|
||||||
status: objectData.status || 'active'
|
status: raw?.status ?? 'active',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,21 +29,37 @@ const ObjectsPage: React.FC = () => {
|
|||||||
const [selectedObjectId, setSelectedObjectId] = useState<string | null>(null)
|
const [selectedObjectId, setSelectedObjectId] = useState<string | null>(null)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const loadData = () => {
|
const loadData = async () => {
|
||||||
|
setLoading(true)
|
||||||
|
setError(null)
|
||||||
try {
|
try {
|
||||||
setLoading(true)
|
const url = '/api/get-objects'
|
||||||
|
const res = await fetch(url, { cache: 'no-store' })
|
||||||
if (detectorsData.objects) {
|
const payloadText = await res.text()
|
||||||
const transformedObjects = Object.entries(detectorsData.objects).map(
|
let payload: any
|
||||||
([objectId, objectData]) => transformObjectToObjectData(objectId, objectData)
|
try { payload = JSON.parse(payloadText) } catch { payload = payloadText }
|
||||||
)
|
console.log('[ObjectsPage] GET /api/get-objects', { status: res.status, payload })
|
||||||
setObjects(transformedObjects)
|
|
||||||
} else {
|
if (!res.ok) {
|
||||||
throw new Error('Не удалось получить данные объектов')
|
throw new Error(typeof payload === 'string' ? payload : (payload?.error || 'Не удалось получить данные объектов'))
|
||||||
}
|
}
|
||||||
} catch (err) {
|
|
||||||
console.error('Ошибка при загрузке данных:', err)
|
const data = (payload?.data ?? payload) as any
|
||||||
setError(err instanceof Error ? err.message : 'Произошла неизвестная ошибка')
|
let rawObjectsArray: any[] = []
|
||||||
|
if (Array.isArray(data)) {
|
||||||
|
rawObjectsArray = data
|
||||||
|
} else if (Array.isArray(data?.objects)) {
|
||||||
|
rawObjectsArray = data.objects
|
||||||
|
} else if (data && typeof data === 'object') {
|
||||||
|
// если приходит как map { id: obj }
|
||||||
|
rawObjectsArray = Object.values(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
const transformedObjects = rawObjectsArray.map(transformRawToObjectData)
|
||||||
|
setObjects(transformedObjects)
|
||||||
|
} catch (err: any) {
|
||||||
|
console.error('Ошибка при загрузке данных объектов:', err)
|
||||||
|
setError(err?.message || 'Произошла неизвестная ошибка')
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,21 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import React, { useEffect } from 'react'
|
import React, { useEffect, useState } from 'react'
|
||||||
import { useRouter, useSearchParams } from 'next/navigation'
|
import { useRouter, useSearchParams } from 'next/navigation'
|
||||||
import Sidebar from '../../../components/ui/Sidebar'
|
import Sidebar from '../../../components/ui/Sidebar'
|
||||||
import useNavigationStore from '../../store/navigationStore'
|
import useNavigationStore from '../../store/navigationStore'
|
||||||
import ReportsList from '../../../components/reports/ReportsList'
|
import ReportsList from '../../../components/reports/ReportsList'
|
||||||
import ExportMenu from '../../../components/ui/ExportMenu'
|
import ExportMenu from '../../../components/ui/ExportMenu'
|
||||||
import detectorsData from '../../../data/detectors.json'
|
import { useSession } from 'next-auth/react'
|
||||||
import axios from 'axios'
|
import DetectorList from '../../../components/alerts/DetectorList'
|
||||||
|
|
||||||
const ReportsPage: React.FC = () => {
|
const ReportsPage: React.FC = () => {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const searchParams = useSearchParams()
|
const searchParams = useSearchParams()
|
||||||
|
const { data: session } = useSession()
|
||||||
const { currentObject, setCurrentObject } = useNavigationStore()
|
const { currentObject, setCurrentObject } = useNavigationStore()
|
||||||
|
const [selectedDetectors, setSelectedDetectors] = useState<number[]>([])
|
||||||
|
const [detectorsData, setDetectorsData] = useState<any>({ detectors: {} })
|
||||||
|
|
||||||
const urlObjectId = searchParams.get('objectId')
|
const urlObjectId = searchParams.get('objectId')
|
||||||
const urlObjectTitle = searchParams.get('objectTitle')
|
const urlObjectTitle = searchParams.get('objectTitle')
|
||||||
@@ -25,36 +28,70 @@ const ReportsPage: React.FC = () => {
|
|||||||
}
|
}
|
||||||
}, [urlObjectId, urlObjectTitle, currentObject.id, setCurrentObject])
|
}, [urlObjectId, urlObjectTitle, currentObject.id, setCurrentObject])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const loadDetectors = async () => {
|
||||||
|
try {
|
||||||
|
const params = new URLSearchParams()
|
||||||
|
if (currentObject.id) params.set('objectId', currentObject.id)
|
||||||
|
const res = await fetch(`/api/get-detectors?${params.toString()}`, { cache: 'no-store' })
|
||||||
|
if (!res.ok) return
|
||||||
|
const payload = await res.json()
|
||||||
|
const data = payload?.data || { detectors: {} }
|
||||||
|
console.log('[ReportsPage] GET /api/get-detectors', {
|
||||||
|
url: `/api/get-detectors?${params.toString()}`,
|
||||||
|
status: res.status,
|
||||||
|
payload,
|
||||||
|
parsed: data,
|
||||||
|
})
|
||||||
|
setDetectorsData(data)
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Failed to load detectors data:', e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
loadDetectors()
|
||||||
|
|
||||||
|
}, [currentObject.id])
|
||||||
|
|
||||||
const handleBackClick = () => {
|
const handleBackClick = () => {
|
||||||
router.push('/dashboard')
|
router.push('/dashboard')
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleExport = async (format: 'csv' | 'pdf') => {
|
const handleDetectorSelect = (detectorId: number, selected: boolean) => {
|
||||||
try {
|
if (selected) {
|
||||||
const response = await axios.post(
|
setSelectedDetectors(prev => [...prev, detectorId])
|
||||||
`${process.env.NEXT_PUBLIC_API_URL}/account/get-reports/`,
|
} else {
|
||||||
{ report_format: format },
|
setSelectedDetectors(prev => prev.filter(id => id !== detectorId))
|
||||||
{
|
}
|
||||||
responseType: 'blob',
|
}
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
const contentDisposition = response.headers['content-disposition']
|
const handleExport = async (format: 'csv' | 'pdf', hours: number) => {
|
||||||
|
try {
|
||||||
|
const res = await fetch(`/api/get-reports`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
...(session?.accessToken ? { Authorization: `Bearer ${session.accessToken}` } : {}),
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ format: format, hours }),
|
||||||
|
credentials: 'include',
|
||||||
|
})
|
||||||
|
if (!res.ok) {
|
||||||
|
const errText = await res.text()
|
||||||
|
console.error('[ReportsPage] POST /api/get-reports failed', { status: res.status, body: errText })
|
||||||
|
throw new Error(`Export failed: ${res.status} ${errText}`)
|
||||||
|
}
|
||||||
|
console.log('[ReportsPage] POST /api/get-reports success', { status: res.status, headers: Object.fromEntries(res.headers.entries()) })
|
||||||
|
const blob = await res.blob()
|
||||||
|
const contentDisposition = res.headers.get('Content-Disposition') || res.headers.get('content-disposition')
|
||||||
const filenameMatch = contentDisposition?.match(/filename="(.+)"/)
|
const filenameMatch = contentDisposition?.match(/filename="(.+)"/)
|
||||||
const timestamp = new Date().toISOString().replace(/[:.]/g, '-').replace(/T/g, '_')
|
const timestamp = new Date().toISOString().replace(/[:.]/g, '-').replace(/T/g, '_')
|
||||||
const filename = filenameMatch ? filenameMatch[1] : `alerts_report_${timestamp}.${format}`
|
const filename = filenameMatch ? filenameMatch[1] : `detectors_report_${timestamp}.${format}`
|
||||||
|
const url = window.URL.createObjectURL(blob)
|
||||||
const url = window.URL.createObjectURL(new Blob([response.data]))
|
|
||||||
const link = document.createElement('a')
|
const link = document.createElement('a')
|
||||||
link.href = url
|
link.href = url
|
||||||
link.download = filename
|
link.download = filename
|
||||||
|
|
||||||
document.body.appendChild(link)
|
document.body.appendChild(link)
|
||||||
link.click()
|
link.click()
|
||||||
|
|
||||||
document.body.removeChild(link)
|
document.body.removeChild(link)
|
||||||
window.URL.revokeObjectURL(url)
|
window.URL.revokeObjectURL(url)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -63,12 +100,12 @@ const ReportsPage: React.FC = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex h-screen bg-[#0e111a]">
|
<div className="flex h-screen bg-[#0e111a]">
|
||||||
<Sidebar
|
<Sidebar
|
||||||
activeItem={9} // Reports
|
activeItem={9} // Отчёты
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div className="flex flex-1 flex-col">
|
<div className="flex-1 flex flex-col">
|
||||||
<header className="border-b border-gray-700 bg-[#161824] px-6 py-4">
|
<header className="border-b border-gray-700 bg-[#161824] px-6 py-4">
|
||||||
<div className="flex items-center gap-4">
|
<div className="flex items-center gap-4">
|
||||||
<button
|
<button
|
||||||
@@ -103,7 +140,15 @@ const ReportsPage: React.FC = () => {
|
|||||||
<ExportMenu onExport={handleExport} />
|
<ExportMenu onExport={handleExport} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ReportsList objectId={objectId || undefined} detectorsData={detectorsData} />
|
{/* Selection table to choose detectors to include in the report */}
|
||||||
|
<div className="mb-6">
|
||||||
|
<DetectorList objectId={objectId || undefined} selectedDetectors={selectedDetectors} onDetectorSelect={handleDetectorSelect} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Existing notifications-based list */}
|
||||||
|
<div className="mt-6">
|
||||||
|
<ReportsList detectorsData={detectorsData} />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
27
frontend/app/api/big-models/[...path]/route.ts
Normal file
27
frontend/app/api/big-models/[...path]/route.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
export const dynamic = 'force-static';
|
||||||
|
|
||||||
|
import fs from 'fs';
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
|
export async function GET(
|
||||||
|
request: Request,
|
||||||
|
{ params }: { params: Promise<{ path: string[] }> }
|
||||||
|
) {
|
||||||
|
const { path: pathParts } = await params;
|
||||||
|
const fileName = pathParts.join('/');
|
||||||
|
const filePath = path.join(process.cwd(), 'assets', 'big-models', fileName);
|
||||||
|
|
||||||
|
if (!fs.existsSync(filePath)) {
|
||||||
|
return new Response('Not Found', { status: 404 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const stat = fs.statSync(filePath);
|
||||||
|
const stream = fs.createReadStream(filePath);
|
||||||
|
|
||||||
|
return new Response(stream as unknown as ReadableStream, {
|
||||||
|
headers: {
|
||||||
|
'Content-Length': stat.size.toString(),
|
||||||
|
'Content-Type': 'model/gltf-binary',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
114
frontend/app/api/get-alerts/route.ts
Normal file
114
frontend/app/api/get-alerts/route.ts
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
import { NextResponse, NextRequest } from 'next/server'
|
||||||
|
import { getServerSession } from 'next-auth'
|
||||||
|
import { authOptions } from '@/lib/auth'
|
||||||
|
import { getToken } from 'next-auth/jwt'
|
||||||
|
|
||||||
|
export async function GET(req: NextRequest) {
|
||||||
|
try {
|
||||||
|
const session = await getServerSession(authOptions)
|
||||||
|
const authHeader = req.headers.get('authorization') || req.headers.get('Authorization')
|
||||||
|
const bearer = authHeader && authHeader.toLowerCase().startsWith('bearer ') ? authHeader.slice(7) : undefined
|
||||||
|
const secret = process.env.NEXTAUTH_SECRET
|
||||||
|
const token = await getToken({ req, secret }).catch(() => null)
|
||||||
|
|
||||||
|
let accessToken = session?.accessToken || bearer || (token as any)?.accessToken
|
||||||
|
const refreshToken = session?.refreshToken || (token as any)?.refreshToken
|
||||||
|
|
||||||
|
if (!accessToken && refreshToken) {
|
||||||
|
try {
|
||||||
|
const refreshRes = await fetch(`${process.env.BACKEND_URL}/auth/refresh/`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ refresh: refreshToken }),
|
||||||
|
})
|
||||||
|
if (refreshRes.ok) {
|
||||||
|
const refreshed = await refreshRes.json()
|
||||||
|
accessToken = refreshed.access
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!accessToken) {
|
||||||
|
return NextResponse.json({ success: false, error: 'Unauthorized' }, { status: 401 })
|
||||||
|
}
|
||||||
|
|
||||||
|
const backendUrl = process.env.BACKEND_URL
|
||||||
|
if (!backendUrl) {
|
||||||
|
return NextResponse.json({ success: false, error: 'BACKEND_URL is not configured' }, { status: 500 })
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = new URL(req.url)
|
||||||
|
const objectId = url.searchParams.get('objectId')
|
||||||
|
|
||||||
|
const objectsRes = await fetch(`${backendUrl}/account/get-objects/`, {
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Authorization: `Bearer ${accessToken}`,
|
||||||
|
},
|
||||||
|
cache: 'no-store',
|
||||||
|
})
|
||||||
|
|
||||||
|
const alertsRes = await fetch(`${backendUrl}/account/get-alerts/`, {
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Authorization: `Bearer ${accessToken}`,
|
||||||
|
},
|
||||||
|
cache: 'no-store',
|
||||||
|
})
|
||||||
|
|
||||||
|
const payloadText = await alertsRes.text()
|
||||||
|
let payload: any
|
||||||
|
try { payload = JSON.parse(payloadText) } catch { payload = payloadText }
|
||||||
|
|
||||||
|
if (!alertsRes.ok) {
|
||||||
|
const err = typeof payload === 'string' ? payload : JSON.stringify(payload)
|
||||||
|
return NextResponse.json({ success: false, error: `Backend alerts error: ${err}` }, { status: alertsRes.status })
|
||||||
|
}
|
||||||
|
|
||||||
|
const objectsText = await objectsRes.text()
|
||||||
|
let objectsPayload: any
|
||||||
|
try { objectsPayload = JSON.parse(objectsText) } catch { objectsPayload = [] }
|
||||||
|
|
||||||
|
const titleToIdMap: Record<string, string> = {}
|
||||||
|
if (Array.isArray(objectsPayload)) {
|
||||||
|
for (const obj of objectsPayload) {
|
||||||
|
if (obj && typeof obj.title === 'string' && typeof obj.id === 'number') {
|
||||||
|
titleToIdMap[obj.title] = `object_${obj.id}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const list: any[] = Array.isArray(payload) ? payload : []
|
||||||
|
const filtered = objectId ? list.filter(a => {
|
||||||
|
if (a.object && typeof a.object === 'string') {
|
||||||
|
const mappedId = titleToIdMap[a.object] || a.object
|
||||||
|
return mappedId === objectId
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}) : list
|
||||||
|
|
||||||
|
const transformed = filtered.map((a) => ({
|
||||||
|
id: a.id,
|
||||||
|
detector_name: a.name,
|
||||||
|
message: a.message,
|
||||||
|
type: a.severity,
|
||||||
|
location: a.object,
|
||||||
|
priority: a.severity,
|
||||||
|
acknowledged: a.resolved,
|
||||||
|
timestamp: a.created_at,
|
||||||
|
}))
|
||||||
|
|
||||||
|
return NextResponse.json({ success: true, data: transformed })
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching alerts data:', error)
|
||||||
|
return NextResponse.json(
|
||||||
|
{
|
||||||
|
success: false,
|
||||||
|
error: 'Failed to fetch alerts data',
|
||||||
|
},
|
||||||
|
{ status: 500 }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
import { NextResponse } from 'next/server'
|
|
||||||
import { readFile } from 'fs/promises'
|
|
||||||
import { join } from 'path'
|
|
||||||
|
|
||||||
export async function GET() {
|
|
||||||
try {
|
|
||||||
// Имитация полученных данных в формате json (данные в data/detectors.json)
|
|
||||||
const filePath = join(process.cwd(), 'frontend', 'data', 'detectors.json')
|
|
||||||
const fileContent = await readFile(filePath, 'utf8')
|
|
||||||
const allData = JSON.parse(fileContent)
|
|
||||||
|
|
||||||
return NextResponse.json({
|
|
||||||
success: true,
|
|
||||||
data: allData,
|
|
||||||
objectsCount: Object.keys(allData.objects || {}).length,
|
|
||||||
detectorsCount: Object.keys(allData.detectors || {}).length
|
|
||||||
})
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error fetching detectors data:', error)
|
|
||||||
return NextResponse.json(
|
|
||||||
{
|
|
||||||
success: false,
|
|
||||||
error: 'Failed to fetch detectors data'
|
|
||||||
},
|
|
||||||
{ status: 500 }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
88
frontend/app/api/get-detectors/route.ts
Normal file
88
frontend/app/api/get-detectors/route.ts
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
import { NextResponse } from 'next/server'
|
||||||
|
import { getServerSession } from 'next-auth'
|
||||||
|
import { authOptions } from '@/lib/auth'
|
||||||
|
|
||||||
|
export async function GET() {
|
||||||
|
try {
|
||||||
|
const session = await getServerSession(authOptions)
|
||||||
|
if (!session?.accessToken) {
|
||||||
|
return NextResponse.json({ success: false, error: 'Unauthorized' }, { status: 401 })
|
||||||
|
}
|
||||||
|
|
||||||
|
const backendUrl = process.env.BACKEND_URL
|
||||||
|
|
||||||
|
const [detectorsRes, objectsRes] = await Promise.all([
|
||||||
|
fetch(`${backendUrl}/account/get-detectors/`, {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Authorization: `Bearer ${session.accessToken}`,
|
||||||
|
},
|
||||||
|
cache: 'no-store',
|
||||||
|
}),
|
||||||
|
fetch(`${backendUrl}/account/get-objects/`, {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Authorization: `Bearer ${session.accessToken}`,
|
||||||
|
},
|
||||||
|
cache: 'no-store',
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
|
||||||
|
if (!detectorsRes.ok) {
|
||||||
|
const err = await detectorsRes.text()
|
||||||
|
return NextResponse.json({ success: false, error: `Backend detectors error: ${err}` }, { status: detectorsRes.status })
|
||||||
|
}
|
||||||
|
if (!objectsRes.ok) {
|
||||||
|
const err = await objectsRes.text()
|
||||||
|
return NextResponse.json({ success: false, error: `Backend objects error: ${err}` }, { status: objectsRes.status })
|
||||||
|
}
|
||||||
|
|
||||||
|
const detectorsPayload = await detectorsRes.json()
|
||||||
|
const objectsPayload = await objectsRes.json()
|
||||||
|
|
||||||
|
const titleToIdMap: Record<string, string> = {}
|
||||||
|
if (Array.isArray(objectsPayload)) {
|
||||||
|
for (const obj of objectsPayload) {
|
||||||
|
if (obj && typeof obj.title === 'string' && typeof obj.id === 'number') {
|
||||||
|
titleToIdMap[obj.title] = `object_${obj.id}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const statusToColor: Record<string, string> = {
|
||||||
|
critical: '#b3261e',
|
||||||
|
warning: '#fd7c22',
|
||||||
|
normal: '#00ff00',
|
||||||
|
}
|
||||||
|
|
||||||
|
const transformedDetectors: Record<string, any> = {}
|
||||||
|
const detectorsObj = detectorsPayload?.detectors ?? {}
|
||||||
|
for (const [key, sensor] of Object.entries<any>(detectorsObj)) {
|
||||||
|
const color = statusToColor[sensor.status] ?? '#00ff00'
|
||||||
|
const objectId = titleToIdMap[sensor.object] || sensor.object
|
||||||
|
transformedDetectors[key] = {
|
||||||
|
...sensor,
|
||||||
|
status: color,
|
||||||
|
object: objectId,
|
||||||
|
checked: sensor.checked ?? false,
|
||||||
|
location: sensor.zone ?? '',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
success: true,
|
||||||
|
data: { detectors: transformedDetectors },
|
||||||
|
objectsCount: Array.isArray(objectsPayload) ? objectsPayload.length : 0,
|
||||||
|
detectorsCount: Object.keys(transformedDetectors).length,
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching detectors data:', error)
|
||||||
|
return NextResponse.json(
|
||||||
|
{
|
||||||
|
success: false,
|
||||||
|
error: 'Failed to fetch detectors data',
|
||||||
|
},
|
||||||
|
{ status: 500 }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
71
frontend/app/api/get-objects/route.ts
Normal file
71
frontend/app/api/get-objects/route.ts
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
import { NextResponse, NextRequest } from 'next/server'
|
||||||
|
import { getServerSession } from 'next-auth'
|
||||||
|
import { authOptions } from '@/lib/auth'
|
||||||
|
import { getToken } from 'next-auth/jwt'
|
||||||
|
|
||||||
|
export async function GET(req: NextRequest) {
|
||||||
|
try {
|
||||||
|
const session = await getServerSession(authOptions)
|
||||||
|
|
||||||
|
const authHeader = req.headers.get('authorization') || req.headers.get('Authorization')
|
||||||
|
const bearer = authHeader && authHeader.toLowerCase().startsWith('bearer ') ? authHeader.slice(7) : undefined
|
||||||
|
|
||||||
|
const secret = process.env.NEXTAUTH_SECRET
|
||||||
|
const token = secret ? (await getToken({ req, secret }).catch(() => null)) : null
|
||||||
|
|
||||||
|
let accessToken: string | undefined = session?.accessToken || bearer || (token as any)?.accessToken
|
||||||
|
const refreshToken: string | undefined = session?.refreshToken || (token as any)?.refreshToken
|
||||||
|
|
||||||
|
if (!accessToken && refreshToken) {
|
||||||
|
try {
|
||||||
|
const refreshRes = await fetch(`${process.env.BACKEND_URL}/auth/refresh/`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ refresh: refreshToken }),
|
||||||
|
})
|
||||||
|
if (refreshRes.ok) {
|
||||||
|
const refreshed = await refreshRes.json()
|
||||||
|
accessToken = refreshed.access
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!accessToken) {
|
||||||
|
return NextResponse.json({ success: false, error: 'Unauthorized' }, { status: 401 })
|
||||||
|
}
|
||||||
|
|
||||||
|
const backendUrl = process.env.BACKEND_URL
|
||||||
|
if (!backendUrl) {
|
||||||
|
return NextResponse.json({ success: false, error: 'BACKEND_URL is not configured' }, { status: 500 })
|
||||||
|
}
|
||||||
|
|
||||||
|
const objectsRes = await fetch(`${backendUrl}/account/get-objects/`, {
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Authorization: `Bearer ${accessToken}`,
|
||||||
|
},
|
||||||
|
cache: 'no-store',
|
||||||
|
})
|
||||||
|
|
||||||
|
const payloadText = await objectsRes.text()
|
||||||
|
let payload: any
|
||||||
|
try { payload = JSON.parse(payloadText) } catch { payload = payloadText }
|
||||||
|
|
||||||
|
if (!objectsRes.ok) {
|
||||||
|
const err = typeof payload === 'string' ? payload : JSON.stringify(payload)
|
||||||
|
return NextResponse.json({ success: false, error: `Backend objects error: ${err}` }, { status: objectsRes.status })
|
||||||
|
}
|
||||||
|
|
||||||
|
return NextResponse.json({ success: true, data: payload })
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching objects data:', error)
|
||||||
|
return NextResponse.json(
|
||||||
|
{
|
||||||
|
success: false,
|
||||||
|
error: 'Failed to fetch objects data',
|
||||||
|
},
|
||||||
|
{ status: 500 }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
109
frontend/app/api/get-reports/route.ts
Normal file
109
frontend/app/api/get-reports/route.ts
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
import { getServerSession } from 'next-auth'
|
||||||
|
import { authOptions } from '@/lib/auth'
|
||||||
|
import { NextRequest } from 'next/server'
|
||||||
|
import { getToken } from 'next-auth/jwt'
|
||||||
|
|
||||||
|
export async function POST(req: NextRequest) {
|
||||||
|
try {
|
||||||
|
const session = await getServerSession(authOptions)
|
||||||
|
|
||||||
|
const authHeader = req.headers.get('authorization') || req.headers.get('Authorization')
|
||||||
|
const bearer = authHeader && authHeader.toLowerCase().startsWith('bearer ') ? authHeader.slice(7) : undefined
|
||||||
|
|
||||||
|
const secret = process.env.NEXTAUTH_SECRET
|
||||||
|
const token = await getToken({ req, secret }).catch(() => null)
|
||||||
|
|
||||||
|
let accessToken = session?.accessToken || bearer || (token as any)?.accessToken
|
||||||
|
const refreshToken = session?.refreshToken || (token as any)?.refreshToken
|
||||||
|
|
||||||
|
if (!accessToken && refreshToken) {
|
||||||
|
try {
|
||||||
|
const refreshRes = await fetch(`${process.env.BACKEND_URL}/auth/refresh/`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ refresh: refreshToken }),
|
||||||
|
})
|
||||||
|
if (refreshRes.ok) {
|
||||||
|
const refreshed = await refreshRes.json()
|
||||||
|
accessToken = refreshed.access
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!accessToken) {
|
||||||
|
return new Response(JSON.stringify({ success: false, error: 'Unauthorized' }), {
|
||||||
|
status: 401,
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const backendUrl = process.env.BACKEND_URL
|
||||||
|
if (!backendUrl) {
|
||||||
|
return new Response(JSON.stringify({ success: false, error: 'BACKEND_URL is not configured' }), {
|
||||||
|
status: 500,
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const body = await req.json().catch(() => ({ })) as { format?: 'csv' | 'pdf', hours?: number }
|
||||||
|
const reportFormat = (body.format || '').toLowerCase()
|
||||||
|
|
||||||
|
const url = new URL(req.url)
|
||||||
|
const qpFormat = (url.searchParams.get('format') || '').toLowerCase()
|
||||||
|
const qpHoursRaw = url.searchParams.get('hours')
|
||||||
|
const qpHours = qpHoursRaw ? Number(qpHoursRaw) : undefined
|
||||||
|
const finalFormat = reportFormat || qpFormat
|
||||||
|
const finalHours = typeof body.hours === 'number' ? body.hours : (typeof qpHours === 'number' && !Number.isNaN(qpHours) ? qpHours : 168)
|
||||||
|
|
||||||
|
let backendRes = await fetch(`${backendUrl}/account/get-reports/`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Authorization: `Bearer ${accessToken}`,
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ report_format: finalFormat, hours: finalHours }),
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!backendRes.ok && backendRes.status === 404) {
|
||||||
|
backendRes = await fetch(`${backendUrl}/account/get-report/`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Authorization: `Bearer ${accessToken}`,
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ report_format: finalFormat, hours: finalHours }),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!backendRes.ok) {
|
||||||
|
const errText = await backendRes.text().catch(() => '')
|
||||||
|
const contentType = backendRes.headers.get('Content-Type') || 'text/plain'
|
||||||
|
return new Response(errText || 'Error generating report', {
|
||||||
|
status: backendRes.status,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': contentType,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const arrayBuffer = await backendRes.arrayBuffer()
|
||||||
|
const contentType = backendRes.headers.get('Content-Type') || 'application/octet-stream'
|
||||||
|
const contentDisposition = backendRes.headers.get('Content-Disposition') || backendRes.headers.get('content-disposition')
|
||||||
|
|
||||||
|
const headers: Record<string, string> = { 'Content-Type': contentType }
|
||||||
|
if (contentDisposition) {
|
||||||
|
headers['Content-Disposition'] = contentDisposition
|
||||||
|
} else if (finalFormat) {
|
||||||
|
const timestamp = new Date().toISOString().replace(/[:.]/g, '-').replace(/T/g, '_')
|
||||||
|
headers['Content-Disposition'] = `attachment; filename="alerts_report_${timestamp}.${finalFormat}"`
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Response(arrayBuffer, { status: 200, headers })
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error proxying report export:', error)
|
||||||
|
return new Response(JSON.stringify({ success: false, error: 'Failed to export report' }), {
|
||||||
|
status: 500,
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -32,7 +32,7 @@ export function useClientFetch<TData = unknown, TVariables = void, TError = Axio
|
|||||||
: MutationResult<TData, TVariables, TError> {
|
: MutationResult<TData, TVariables, TError> {
|
||||||
const { method = 'GET', config = {}, queryOptions = {}, mutationOptions = {} } = options
|
const { method = 'GET', config = {}, queryOptions = {}, mutationOptions = {} } = options
|
||||||
|
|
||||||
const API_URL = process.env.NEXT_PUBLIC_API_URL
|
const API_URL = process.env.NEXT_PUBLIC_API_URL ?? `${window.location.origin}/api/v1`
|
||||||
const fullUrl = url.startsWith('http') ? url : `${API_URL}${url}`
|
const fullUrl = url.startsWith('http') ? url : `${API_URL}${url}`
|
||||||
|
|
||||||
// всегда вызываем оба хука
|
// всегда вызываем оба хука
|
||||||
|
|||||||
@@ -15,20 +15,29 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
|
|||||||
setAuthenticated(false)
|
setAuthenticated(false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const API_URL = process.env.NEXT_PUBLIC_API_URL
|
const base = process.env.NEXT_PUBLIC_API_URL || '/api/v1'
|
||||||
|
const baseClean = base.replace(/\/+$/, '')
|
||||||
|
const url = `${baseClean}/account/user/`
|
||||||
|
console.log('[AuthProvider] Fetching user from:', url)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${API_URL}/account/user/`, {
|
const response = await fetch(url, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${session.accessToken}`,
|
Authorization: `Bearer ${session.accessToken}`,
|
||||||
'Content-Type': 'application/json',
|
Accept: 'application/json',
|
||||||
},
|
},
|
||||||
|
cache: 'no-store',
|
||||||
|
redirect: 'follow',
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const errorText = await response.text()
|
const errorText = await response.text()
|
||||||
console.error('Error response:', errorText)
|
console.error('Error fetching user data:', {
|
||||||
|
status: response.status,
|
||||||
|
url: url,
|
||||||
|
body: errorText,
|
||||||
|
})
|
||||||
throw new Error(`Error fetching user data: ${response.status} ${errorText}`)
|
throw new Error(`Error fetching user data: ${response.status} ${errorText}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +48,7 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
|
|||||||
name: userData.name || session.user.name || '',
|
name: userData.name || session.user.name || '',
|
||||||
surname: userData.surname || '',
|
surname: userData.surname || '',
|
||||||
email: userData.email || session.user.email || '',
|
email: userData.email || session.user.email || '',
|
||||||
image: userData.image,
|
image: userData.imageURL || userData.image,
|
||||||
account_type: userData.account_type,
|
account_type: userData.account_type,
|
||||||
login: userData.login,
|
login: userData.login,
|
||||||
uuid: userData.uuid,
|
uuid: userData.uuid,
|
||||||
@@ -47,6 +56,8 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
|
|||||||
setAuthenticated(true)
|
setAuthenticated(true)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error in fetchUserData:', error)
|
console.error('Error in fetchUserData:', error)
|
||||||
|
setAuthenticated(false)
|
||||||
|
setUser(null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
9
frontend/app/types.ts
Normal file
9
frontend/app/types.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
export interface ValidationRules {
|
||||||
|
required?: boolean
|
||||||
|
minLength?: number
|
||||||
|
pattern?: RegExp
|
||||||
|
}
|
||||||
|
export type ValidationErrors = Record<string, string>
|
||||||
|
|
||||||
|
export type User = object
|
||||||
|
export type UserState = object
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import React, { useState, useEffect } from 'react'
|
import React, { useState, useEffect } from 'react'
|
||||||
import detectorsData from '../../data/detectors.json'
|
|
||||||
|
|
||||||
interface Detector {
|
interface Detector {
|
||||||
detector_id: number
|
detector_id: number
|
||||||
@@ -45,12 +44,31 @@ const DetectorList: React.FC<DetectorListProps> = ({ objectId, selectedDetectors
|
|||||||
const [searchTerm, setSearchTerm] = useState<string>('')
|
const [searchTerm, setSearchTerm] = useState<string>('')
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const detectorsArray = Object.values(detectorsData.detectors).filter(
|
const loadDetectors = async () => {
|
||||||
(detector: RawDetector) => objectId ? detector.object === objectId : true
|
try {
|
||||||
)
|
const res = await fetch('/api/get-detectors', { cache: 'no-store' })
|
||||||
setDetectors(detectorsArray as Detector[])
|
if (!res.ok) return
|
||||||
|
const payload = await res.json()
|
||||||
|
const detectorsData: Record<string, RawDetector> = payload?.data?.detectors ?? {}
|
||||||
|
const rawArray: RawDetector[] = Object.values(detectorsData).filter(
|
||||||
|
(detector) => (objectId ? detector.object === objectId : true)
|
||||||
|
)
|
||||||
|
const normalized: Detector[] = rawArray.map((d) => ({
|
||||||
|
detector_id: d.detector_id,
|
||||||
|
name: d.name,
|
||||||
|
location: d.location,
|
||||||
|
status: d.status,
|
||||||
|
object: d.object,
|
||||||
|
floor: d.floor,
|
||||||
|
checked: false,
|
||||||
|
}))
|
||||||
|
console.log('[DetectorList] Payload:', payload)
|
||||||
|
setDetectors(normalized)
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Failed to load detectors:', e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
loadDetectors()
|
||||||
}, [objectId])
|
}, [objectId])
|
||||||
|
|
||||||
const filteredDetectors = detectors.filter(detector => {
|
const filteredDetectors = detectors.filter(detector => {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import React from 'react'
|
import React, { useEffect, useState } from 'react'
|
||||||
import { useRouter } from 'next/navigation'
|
import { useRouter } from 'next/navigation'
|
||||||
import Sidebar from '../ui/Sidebar'
|
import Sidebar from '../ui/Sidebar'
|
||||||
import useNavigationStore from '../../app/store/navigationStore'
|
import useNavigationStore from '../../app/store/navigationStore'
|
||||||
@@ -8,14 +8,34 @@ import ChartCard from './ChartCard'
|
|||||||
import AreaChart from './AreaChart'
|
import AreaChart from './AreaChart'
|
||||||
import BarChart from './BarChart'
|
import BarChart from './BarChart'
|
||||||
import DetectorChart from './DetectorChart'
|
import DetectorChart from './DetectorChart'
|
||||||
import detectorsData from '../../data/detectors.json'
|
|
||||||
|
|
||||||
const Dashboard: React.FC = () => {
|
const Dashboard: React.FC = () => {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const { currentObject, setCurrentSubmenu, closeMonitoring, closeFloorNavigation, closeNotifications } = useNavigationStore()
|
const { currentObject, setCurrentSubmenu, closeMonitoring, closeFloorNavigation, closeNotifications } = useNavigationStore()
|
||||||
const objectId = currentObject?.id
|
const objectId = currentObject?.id
|
||||||
const objectTitle = currentObject?.title
|
const objectTitle = currentObject?.title
|
||||||
|
|
||||||
|
const [detectorsArray, setDetectorsArray] = useState<any[]>([])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const loadDetectors = async () => {
|
||||||
|
try {
|
||||||
|
const res = await fetch('/api/get-detectors', { cache: 'no-store' })
|
||||||
|
if (!res.ok) return
|
||||||
|
const payload = await res.json()
|
||||||
|
console.log('[Dashboard] GET /api/get-detectors', { status: res.status, payload })
|
||||||
|
const detectorsData = payload?.data?.detectors ?? {}
|
||||||
|
const arr = Object.values(detectorsData).filter(
|
||||||
|
(detector: any) => (objectId ? detector.object === objectId : true)
|
||||||
|
)
|
||||||
|
setDetectorsArray(arr as any[])
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Failed to load detectors:', e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
loadDetectors()
|
||||||
|
}, [objectId])
|
||||||
|
|
||||||
const handleBackClick = () => {
|
const handleBackClick = () => {
|
||||||
router.push('/objects')
|
router.push('/objects')
|
||||||
}
|
}
|
||||||
@@ -39,10 +59,6 @@ const Dashboard: React.FC = () => {
|
|||||||
}>
|
}>
|
||||||
}
|
}
|
||||||
|
|
||||||
const detectorsArray = Object.values(detectorsData.detectors).filter(
|
|
||||||
(detector: DetectorData) => objectId ? detector.object === objectId : true
|
|
||||||
)
|
|
||||||
|
|
||||||
// Статусы
|
// Статусы
|
||||||
const statusCounts = detectorsArray.reduce((acc: { critical: number; warning: number; normal: number }, detector: DetectorData) => {
|
const statusCounts = detectorsArray.reduce((acc: { critical: number; warning: number; normal: number }, detector: DetectorData) => {
|
||||||
if (detector.status === '#b3261e') acc.critical++
|
if (detector.status === '#b3261e') acc.critical++
|
||||||
|
|||||||
@@ -152,11 +152,32 @@ const ModelViewer: React.FC<ModelViewerProps> = ({
|
|||||||
setLoadingProgress(100)
|
setLoadingProgress(100)
|
||||||
|
|
||||||
console.log('GLTF Model loaded successfully!')
|
console.log('GLTF Model loaded successfully!')
|
||||||
console.log('\n=== Complete Model Object ===')
|
console.log('\n=== IfcSensor Meshes ===')
|
||||||
console.log(result)
|
const sensorMeshes = (result.meshes || []).filter(m => (m.id ?? '').includes('IfcSensor'))
|
||||||
console.log('\n=== Structure Overview ===')
|
console.log('IfcSensor Mesh count:', sensorMeshes.length)
|
||||||
console.log('Meshes:', result.meshes?.length || 0)
|
sensorMeshes.forEach(m => {
|
||||||
console.log('Transform Nodes:', result.transformNodes?.length || 0)
|
const meta: any = (m as any).metadata
|
||||||
|
const extras = meta?.extras ?? meta?.gltf?.extras
|
||||||
|
console.group(`IfcSensor Mesh: ${m.id || m.name}`)
|
||||||
|
console.log('id:', m.id)
|
||||||
|
console.log('name:', m.name)
|
||||||
|
console.log('uniqueId:', m.uniqueId)
|
||||||
|
console.log('class:', typeof (m as any).getClassName === 'function' ? (m as any).getClassName() : 'Mesh')
|
||||||
|
console.log('material:', m.material?.name)
|
||||||
|
console.log('parent:', m.parent?.name)
|
||||||
|
console.log('metadata:', meta)
|
||||||
|
if (extras) console.log('extras:', extras)
|
||||||
|
const bi = m.getBoundingInfo?.()
|
||||||
|
const bb = bi?.boundingBox
|
||||||
|
if (bb) {
|
||||||
|
console.log('bounding.center:', bb.center)
|
||||||
|
console.log('bounding.extendSize:', bb.extendSize)
|
||||||
|
}
|
||||||
|
const verts = (m as any).getTotalVertices?.()
|
||||||
|
if (typeof verts === 'number') console.log('vertices:', verts)
|
||||||
|
console.groupEnd()
|
||||||
|
})
|
||||||
|
|
||||||
if (result.meshes.length > 0) {
|
if (result.meshes.length > 0) {
|
||||||
|
|
||||||
const boundingBox = result.meshes[0].getHierarchyBoundingVectors()
|
const boundingBox = result.meshes[0].getHierarchyBoundingVectors()
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { ButtonProps } from '@/app/types'
|
import { ButtonProps } from '@/types'
|
||||||
|
|
||||||
const Button = ({
|
const Button = ({
|
||||||
onClick,
|
onClick,
|
||||||
|
|||||||
@@ -3,14 +3,15 @@
|
|||||||
import React, { useState } from 'react'
|
import React, { useState } from 'react'
|
||||||
|
|
||||||
interface ExportMenuProps {
|
interface ExportMenuProps {
|
||||||
onExport: (format: 'csv' | 'pdf') => void
|
onExport: (format: 'csv' | 'pdf', hours: number) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const ExportMenu: React.FC<ExportMenuProps> = ({ onExport }) => {
|
const ExportMenu: React.FC<ExportMenuProps> = ({ onExport }) => {
|
||||||
const [selectedFormat, setSelectedFormat] = useState<'csv' | 'pdf'>('csv')
|
const [selectedFormat, setSelectedFormat] = useState<'csv' | 'pdf'>('csv')
|
||||||
|
const [selectedHours, setSelectedHours] = useState<number>(168) // default: week
|
||||||
|
|
||||||
const handleExport = () => {
|
const handleExport = () => {
|
||||||
onExport(selectedFormat)
|
onExport(selectedFormat, selectedHours)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -40,6 +41,20 @@ const ExportMenu: React.FC<ExportMenuProps> = ({ onExport }) => {
|
|||||||
<span className="text-gray-300 text-sm">PDF</span>
|
<span className="text-gray-300 text-sm">PDF</span>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="flex items-center gap-2 ml-4">
|
||||||
|
<span className="text-gray-300 text-sm">Период:</span>
|
||||||
|
<select
|
||||||
|
className="bg-[#0e111a] text-gray-200 border border-gray-700 rounded px-2 py-1 text-sm"
|
||||||
|
value={selectedHours}
|
||||||
|
onChange={(e) => setSelectedHours(Number(e.target.value))}
|
||||||
|
>
|
||||||
|
<option value={24}>1 день</option>
|
||||||
|
<option value={72}>3 дня</option>
|
||||||
|
<option value={168}>Неделя</option>
|
||||||
|
<option value={720}>Месяц</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
onClick={handleExport}
|
onClick={handleExport}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import toast from 'react-hot-toast'
|
import toast from 'react-hot-toast'
|
||||||
import { ToastProps } from '@/app/types'
|
import { ToastProps } from '@/types'
|
||||||
|
|
||||||
const toastStyles = {
|
const toastStyles = {
|
||||||
success: {
|
success: {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { TextInputProps } from '@/app/types'
|
import { TextInputProps } from '@/types'
|
||||||
import { HiOutlineEye, HiOutlineEyeOff } from 'react-icons/hi'
|
import { HiOutlineEye, HiOutlineEyeOff } from 'react-icons/hi'
|
||||||
|
|
||||||
const TextInput = ({
|
const TextInput = ({
|
||||||
|
|||||||
@@ -1,243 +0,0 @@
|
|||||||
{
|
|
||||||
"objects": {
|
|
||||||
"object_1": {
|
|
||||||
"name": "Торговый центр 'Галерея'",
|
|
||||||
"title": "Торговый центр 'Галерея'",
|
|
||||||
"description": "Современный торговый центр в центре города",
|
|
||||||
"image": "/images/test_image.png",
|
|
||||||
"location": "ул. Лиговский пр., 30А",
|
|
||||||
"address": "ул. Лиговский пр., 30А",
|
|
||||||
"floors": 3,
|
|
||||||
"area": 15000,
|
|
||||||
"zones": [
|
|
||||||
{
|
|
||||||
"zone_id": "zone_1",
|
|
||||||
"name": "Зона 1",
|
|
||||||
"detectors": [4000, 4001, 4004]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"zone_id": "zone_2",
|
|
||||||
"name": "Зона 2",
|
|
||||||
"detectors": [4002, 4003]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"object_2": {
|
|
||||||
"name": "Офисное здание 'Невский'",
|
|
||||||
"title": "Офисное здание 'Невский'",
|
|
||||||
"description": "Многоэтажное офисное здание на Невском проспекте",
|
|
||||||
"image": "/images/test_image.png",
|
|
||||||
"location": "Невский пр., 85",
|
|
||||||
"address": "Невский пр., 85",
|
|
||||||
"floors": 12,
|
|
||||||
"area": 8500,
|
|
||||||
"zones": [
|
|
||||||
{
|
|
||||||
"zone_id": "zone_3",
|
|
||||||
"name": "Зона 3",
|
|
||||||
"detectors": [4005, 4006]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"object_3": {
|
|
||||||
"name": "Жилой комплекс 'Северная звезда'",
|
|
||||||
"title": "Жилой комплекс 'Северная звезда'",
|
|
||||||
"description": "Высотный жилой комплекс с современными квартирами",
|
|
||||||
"image": "/images/test_image.png",
|
|
||||||
"location": "ул. Комендантский пр., 17",
|
|
||||||
"address": "ул. Комендантский пр., 17",
|
|
||||||
"floors": 25,
|
|
||||||
"area": 45000,
|
|
||||||
"zones": [
|
|
||||||
{
|
|
||||||
"zone_id": "zone_4",
|
|
||||||
"name": "Зона 4",
|
|
||||||
"detectors": [4007, 4008]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"object_4": {
|
|
||||||
"name": "Производственный комплекс 'Балтика'",
|
|
||||||
"title": "Производственный комплекс 'Балтика'",
|
|
||||||
"description": "Крупный производственный комплекс с современным оборудованием",
|
|
||||||
"image": "/images/test_image.png",
|
|
||||||
"location": "Индустриальный пр., 44",
|
|
||||||
"address": "Индустриальный пр., 44",
|
|
||||||
"floors": 2,
|
|
||||||
"area": 12000,
|
|
||||||
"zones": [
|
|
||||||
{
|
|
||||||
"zone_id": "zone_5",
|
|
||||||
"name": "Зона 5",
|
|
||||||
"detectors": [4009]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"detectors": {
|
|
||||||
"4000": {
|
|
||||||
"detector_id": 4000,
|
|
||||||
"name": "SJ-4000 N81 Мультиплексор",
|
|
||||||
"object": "object_1",
|
|
||||||
"status": "#b3261e",
|
|
||||||
"checked": false,
|
|
||||||
"type": "fire_detector",
|
|
||||||
"location": "1 этаж, секция А",
|
|
||||||
"floor": 1,
|
|
||||||
"notifications": [
|
|
||||||
{
|
|
||||||
"id": 1,
|
|
||||||
"type": "critical",
|
|
||||||
"message": "Критическое превышение температуры",
|
|
||||||
"timestamp": "2024-01-15T14:30:00Z",
|
|
||||||
"acknowledged": false,
|
|
||||||
"priority": "high"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"4001": {
|
|
||||||
"detector_id": 4001,
|
|
||||||
"name": "SJ-4001 N82 Датчик дыма",
|
|
||||||
"object": "object_1",
|
|
||||||
"status": "#fd7c22",
|
|
||||||
"checked": true,
|
|
||||||
"type": "fire_detector",
|
|
||||||
"location": "1 этаж, секция Б",
|
|
||||||
"floor": 1,
|
|
||||||
"notifications": [
|
|
||||||
{
|
|
||||||
"id": 2,
|
|
||||||
"type": "warning",
|
|
||||||
"message": "Обнаружен дым в помещении",
|
|
||||||
"timestamp": "2024-01-15T14:25:00Z",
|
|
||||||
"acknowledged": true,
|
|
||||||
"priority": "medium"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"4002": {
|
|
||||||
"detector_id": 4002,
|
|
||||||
"name": "SJ-4002 N83 Тепловой датчик",
|
|
||||||
"object": "object_1",
|
|
||||||
"status": "#00ff00",
|
|
||||||
"checked": true,
|
|
||||||
"type": "fire_detector",
|
|
||||||
"location": "2 этаж, секция А",
|
|
||||||
"floor": 2,
|
|
||||||
"notifications": [
|
|
||||||
{
|
|
||||||
"id": 3,
|
|
||||||
"type": "info",
|
|
||||||
"message": "Плановое техническое обслуживание",
|
|
||||||
"timestamp": "2024-01-15T14:20:00Z",
|
|
||||||
"acknowledged": true,
|
|
||||||
"priority": "low"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"4003": {
|
|
||||||
"detector_id": 4003,
|
|
||||||
"name": "SJ-4003 N81 Мультиплексор",
|
|
||||||
"object": "object_1",
|
|
||||||
"status": "#fd7c22",
|
|
||||||
"checked": false,
|
|
||||||
"type": "fire_detector",
|
|
||||||
"location": "2 этаж, секция Б",
|
|
||||||
"floor": 2,
|
|
||||||
"notifications": []
|
|
||||||
},
|
|
||||||
"4004": {
|
|
||||||
"detector_id": 4004,
|
|
||||||
"name": "SJ-4004 N81 Мультиплексор",
|
|
||||||
"object": "object_1",
|
|
||||||
"status": "#00ff00",
|
|
||||||
"checked": true,
|
|
||||||
"type": "fire_detector",
|
|
||||||
"location": "3 этаж, секция А",
|
|
||||||
"floor": 3,
|
|
||||||
"notifications": []
|
|
||||||
},
|
|
||||||
"4005": {
|
|
||||||
"detector_id": 4005,
|
|
||||||
"name": "SJ-4005 N86 Датчик CO",
|
|
||||||
"object": "object_2",
|
|
||||||
"status": "#b3261e",
|
|
||||||
"checked": false,
|
|
||||||
"type": "fire_detector",
|
|
||||||
"location": "3 этаж, секция В",
|
|
||||||
"floor": 3,
|
|
||||||
"notifications": [
|
|
||||||
{
|
|
||||||
"id": 4,
|
|
||||||
"type": "critical",
|
|
||||||
"message": "Превышение концентрации угарного газа",
|
|
||||||
"timestamp": "2024-01-15T14:15:00Z",
|
|
||||||
"acknowledged": false,
|
|
||||||
"priority": "high"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"4006": {
|
|
||||||
"detector_id": 4006,
|
|
||||||
"name": "SJ-4006 N81 Мультиплексор",
|
|
||||||
"object": "object_2",
|
|
||||||
"status": "#00ff00",
|
|
||||||
"checked": true,
|
|
||||||
"type": "fire_detector",
|
|
||||||
"location": "6 этаж, офис 601",
|
|
||||||
"floor": 6,
|
|
||||||
"notifications": []
|
|
||||||
},
|
|
||||||
"4007": {
|
|
||||||
"detector_id": 4007,
|
|
||||||
"name": "SJ-4007 N88 Датчик движения",
|
|
||||||
"object": "object_3",
|
|
||||||
"status": "#fd7c22",
|
|
||||||
"checked": false,
|
|
||||||
"type": "fire_detector",
|
|
||||||
"location": "4 этаж, секция А",
|
|
||||||
"floor": 4,
|
|
||||||
"notifications": [
|
|
||||||
{
|
|
||||||
"id": 5,
|
|
||||||
"type": "warning",
|
|
||||||
"message": "Несанкционированное движение",
|
|
||||||
"timestamp": "2024-01-15T14:10:00Z",
|
|
||||||
"acknowledged": false,
|
|
||||||
"priority": "medium"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"4008": {
|
|
||||||
"detector_id": 4008,
|
|
||||||
"name": "SJ-4008 N81 Мультиплексор",
|
|
||||||
"object": "object_3",
|
|
||||||
"status": "#00ff00",
|
|
||||||
"checked": false,
|
|
||||||
"type": "fire_detector",
|
|
||||||
"location": "15 этаж, квартира 1501",
|
|
||||||
"floor": 15,
|
|
||||||
"notifications": []
|
|
||||||
},
|
|
||||||
"4009": {
|
|
||||||
"detector_id": 4009,
|
|
||||||
"name": "SJ-4009 N90 Датчик протечки",
|
|
||||||
"object": "object_4",
|
|
||||||
"status": "#00ff00",
|
|
||||||
"checked": true,
|
|
||||||
"type": "fire_detector",
|
|
||||||
"location": "1 этаж, техническое помещение",
|
|
||||||
"floor": 1,
|
|
||||||
"notifications": [
|
|
||||||
{
|
|
||||||
"id": 6,
|
|
||||||
"type": "info",
|
|
||||||
"message": "Система работает в штатном режиме",
|
|
||||||
"timestamp": "2024-01-15T14:05:00Z",
|
|
||||||
"acknowledged": true,
|
|
||||||
"priority": "low"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -11,6 +11,17 @@ const compat = new FlatCompat({
|
|||||||
|
|
||||||
const eslintConfig = [
|
const eslintConfig = [
|
||||||
...compat.extends("next/core-web-vitals", "next/typescript"),
|
...compat.extends("next/core-web-vitals", "next/typescript"),
|
||||||
|
{
|
||||||
|
files: [
|
||||||
|
"app/api/**/*.ts",
|
||||||
|
"app/(protected)/**/*.tsx",
|
||||||
|
"components/**/*.ts",
|
||||||
|
"components/**/*.tsx",
|
||||||
|
],
|
||||||
|
rules: {
|
||||||
|
"@typescript-eslint/no-explicit-any": "off",
|
||||||
|
},
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export default eslintConfig;
|
export default eslintConfig;
|
||||||
|
|||||||
28
frontend/next.config.js
Normal file
28
frontend/next.config.js
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
/** @type {import('next').NextConfig} */
|
||||||
|
const nextConfig = {
|
||||||
|
outputFileTracingExcludes: {
|
||||||
|
'./**': ['./assets/big-models/**/*'],
|
||||||
|
},
|
||||||
|
async rewrites() {
|
||||||
|
const backend = process.env.BACKEND_URL || 'http://127.0.0.1:8000/api/v1'
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
source: '/static-models/:path*',
|
||||||
|
destination: '/api/big-models/:path*',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
source: '/api/v1/account/user',
|
||||||
|
destination: `${backend}/account/user/`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
source: '/api/v1/:path*',
|
||||||
|
destination: `${backend}/:path*`,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
experimental: {
|
||||||
|
webpackBuildWorker: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = nextConfig
|
||||||
30
frontend/types/detectors.ts
Normal file
30
frontend/types/detectors.ts
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
export interface DetectorType {
|
||||||
|
detector_id: number
|
||||||
|
name: string
|
||||||
|
object: string
|
||||||
|
status: string
|
||||||
|
checked: boolean
|
||||||
|
type: string
|
||||||
|
location: string
|
||||||
|
floor: number
|
||||||
|
notifications: NotificationType[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface NotificationType {
|
||||||
|
id: number
|
||||||
|
detector_id: number
|
||||||
|
detector_name: string
|
||||||
|
type: string
|
||||||
|
status: string
|
||||||
|
message: string
|
||||||
|
timestamp: string
|
||||||
|
location: string
|
||||||
|
object: string
|
||||||
|
acknowledged: boolean
|
||||||
|
priority: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DetectorsDataType {
|
||||||
|
detectors: Record<string, DetectorType>
|
||||||
|
objects?: Record<string, any>
|
||||||
|
}
|
||||||
53
frontend/types/index.ts
Normal file
53
frontend/types/index.ts
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
// Re-export all type modules so `@/app/types` resolves correctly
|
||||||
|
export * from './detectors'
|
||||||
|
|
||||||
|
// Form validation
|
||||||
|
export interface ValidationRules {
|
||||||
|
required?: boolean
|
||||||
|
minLength?: number
|
||||||
|
pattern?: RegExp
|
||||||
|
// add other rule fields as needed
|
||||||
|
}
|
||||||
|
export type ValidationErrors = Record<string, string>
|
||||||
|
|
||||||
|
// UI component props
|
||||||
|
export interface ButtonProps {
|
||||||
|
onClick?: () => void
|
||||||
|
className?: string
|
||||||
|
text?: string
|
||||||
|
leftIcon?: React.ReactNode
|
||||||
|
midIcon?: React.ReactNode
|
||||||
|
rightIcon?: React.ReactNode
|
||||||
|
type?: 'button' | 'submit' | 'reset'
|
||||||
|
disabled?: boolean
|
||||||
|
size?: 'sm' | 'md' | 'lg'
|
||||||
|
variant?: 'default' | 'text'
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ToastProps {
|
||||||
|
type: 'error' | 'success' | 'loading'
|
||||||
|
message: string
|
||||||
|
action?: {
|
||||||
|
text: string
|
||||||
|
onClick: () => void
|
||||||
|
}
|
||||||
|
duration?: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TextInputProps {
|
||||||
|
value: string
|
||||||
|
handleChange?: (e: React.ChangeEvent<HTMLInputElement>) => void
|
||||||
|
label?: string
|
||||||
|
placeholder?: string
|
||||||
|
name: string
|
||||||
|
type?: 'text' | 'email' | 'password' | 'datetime-local' | 'date'
|
||||||
|
className?: string
|
||||||
|
maxLength?: number
|
||||||
|
tooltip?: string | React.ReactNode
|
||||||
|
style: string
|
||||||
|
isPassword?: boolean
|
||||||
|
isVisible?: boolean
|
||||||
|
togglePasswordVisibility?: () => void
|
||||||
|
error?: string
|
||||||
|
min?: string
|
||||||
|
}
|
||||||
1
frontend/types/progress-webpack-plugin.d.ts
vendored
Normal file
1
frontend/types/progress-webpack-plugin.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
declare module 'progress-webpack-plugin';
|
||||||
1
package.json
Normal file
1
package.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{}
|
||||||
Reference in New Issue
Block a user