Linked backend data to detectors' meshes.
This commit is contained in:
@@ -109,6 +109,26 @@ const AlertsPage: React.FC = () => {
|
||||
}
|
||||
}
|
||||
|
||||
const handleAcknowledgeToggle = async (alertId: number) => {
|
||||
try {
|
||||
const res = await fetch(`/api/update-alert/${alertId}`, { method: 'PATCH' })
|
||||
const payload = await res.json().catch(() => null)
|
||||
console.log('[AlertsPage] PATCH /api/update-alert', { id: alertId, status: res.status, payload })
|
||||
if (!res.ok) {
|
||||
throw new Error(typeof payload?.error === 'string' ? payload.error : `Update failed (${res.status})`)
|
||||
}
|
||||
// Обновить алерты
|
||||
const params = new URLSearchParams()
|
||||
if (currentObject.id) params.set('objectId', currentObject.id)
|
||||
const listRes = await fetch(`/api/get-alerts?${params.toString()}`, { cache: 'no-store' })
|
||||
const listPayload = await listRes.json().catch(() => null)
|
||||
const data = Array.isArray(listPayload?.data) ? listPayload.data : (listPayload?.data?.alerts || [])
|
||||
setAlerts(data as AlertItem[])
|
||||
} catch (e) {
|
||||
console.error('Failed to update alert:', e)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex h-screen bg-[#0e111a]">
|
||||
<Sidebar
|
||||
@@ -218,6 +238,12 @@ const AlertsPage: React.FC = () => {
|
||||
}`}>
|
||||
{item.acknowledged ? 'Да' : 'Нет'}
|
||||
</span>
|
||||
<button
|
||||
onClick={() => handleAcknowledgeToggle(item.id)}
|
||||
className="ml-2 inline-flex items-center px-2 py-1 rounded text-xs font-medium bg-[#2a2e3e] text-white hover:bg-[#353a4d]"
|
||||
>
|
||||
{item.acknowledged ? 'Снять' : 'Подтвердить'}
|
||||
</button>
|
||||
</td>
|
||||
<td className="py-4">
|
||||
<div className="text-sm text-gray-300">{new Date(item.timestamp).toLocaleString('ru-RU')}</div>
|
||||
|
||||
@@ -10,19 +10,21 @@ import DetectorMenu from '../../../components/navigation/DetectorMenu'
|
||||
import Notifications from '../../../components/notifications/Notifications'
|
||||
import NotificationDetectorInfo from '../../../components/notifications/NotificationDetectorInfo'
|
||||
import dynamic from 'next/dynamic'
|
||||
import type { ModelViewerProps } from '../../../components/model/ModelViewer'
|
||||
|
||||
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>
|
||||
),
|
||||
})
|
||||
const ModelViewer = dynamic<ModelViewerProps>(() => 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 {
|
||||
detector_id: number
|
||||
name: string
|
||||
serial_number: string
|
||||
object: string
|
||||
status: string
|
||||
checked: boolean
|
||||
@@ -122,6 +124,13 @@ const NavigationPage: React.FC = () => {
|
||||
}
|
||||
|
||||
const handleDetectorMenuClick = (detector: DetectorType) => {
|
||||
// Для тестов. Выбор детектора.
|
||||
console.log('[NavigationPage] Selected detector click:', {
|
||||
detector_id: detector.detector_id,
|
||||
name: detector.name,
|
||||
serial_number: detector.serial_number,
|
||||
})
|
||||
|
||||
if (selectedDetector?.detector_id === detector.detector_id && showDetectorMenu) {
|
||||
setShowDetectorMenu(false)
|
||||
setSelectedDetector(null)
|
||||
@@ -226,12 +235,7 @@ const NavigationPage: React.FC = () => {
|
||||
})()}
|
||||
|
||||
{showFloorNavigation && showDetectorMenu && selectedDetector && (
|
||||
<DetectorMenu
|
||||
detector={selectedDetector}
|
||||
isOpen={showDetectorMenu}
|
||||
onClose={closeDetectorMenu}
|
||||
getStatusText={getStatusText}
|
||||
/>
|
||||
null
|
||||
)}
|
||||
|
||||
<header className="bg-[#161824] border-b border-gray-700 px-6 py-4">
|
||||
@@ -263,6 +267,19 @@ const NavigationPage: React.FC = () => {
|
||||
modelPath='/static-models/AerBIM_Monitor_ASM_HT_Viewer_Expo2017Astana_Level_+1430_custom_prop.glb'
|
||||
onModelLoaded={handleModelLoaded}
|
||||
onError={handleModelError}
|
||||
focusSensorId={selectedDetector?.serial_number ?? null}
|
||||
renderOverlay={({ anchor }) => (
|
||||
selectedDetector && showDetectorMenu && anchor ? (
|
||||
<DetectorMenu
|
||||
detector={selectedDetector}
|
||||
isOpen={true}
|
||||
onClose={closeDetectorMenu}
|
||||
getStatusText={getStatusText}
|
||||
compact={true}
|
||||
anchor={anchor}
|
||||
/>
|
||||
) : null
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user