обновление бизнес логики

This commit is contained in:
2026-02-05 18:53:25 +03:00
parent f275db88c9
commit 44473a8d9d
24 changed files with 712 additions and 5397 deletions

View File

@@ -215,7 +215,41 @@ const NavigationPage: React.FC = () => {
const loadDetectors = async () => {
try {
setDetectorsError(null)
const res = await fetch('/api/get-detectors', { cache: 'no-store' })
// Если есть modelPath и objectId - фильтруем по зоне
let zoneId: string | null = null
if (selectedModelPath && objectId) {
try {
// Получаем зоны для объекта
const zonesRes = await fetch(`/api/get-zones?objectId=${objectId}`, { cache: 'no-store' })
if (zonesRes.ok) {
const zonesResponse = await zonesRes.json()
// API возвращает { success: true, data: [...] }
const zonesData = zonesResponse?.data || zonesResponse
console.log('[NavigationPage] Loaded zones:', { count: Array.isArray(zonesData) ? zonesData.length : 0, zonesData })
// Ищем зону по model_path
if (Array.isArray(zonesData)) {
const zone = zonesData.find((z: any) => z.model_path === selectedModelPath)
if (zone) {
zoneId = zone.id
console.log('[NavigationPage] Found zone for model_path:', { modelPath: selectedModelPath, zoneId })
} else {
console.log('[NavigationPage] No zone found for model_path:', selectedModelPath)
}
}
}
} catch (e) {
console.warn('[NavigationPage] Failed to load zones for filtering:', e)
}
}
// Загружаем датчики (с фильтром по зоне если найдена)
const detectorsUrl = zoneId
? `/api/get-detectors?zone_id=${zoneId}`
: '/api/get-detectors'
console.log('[NavigationPage] Loading detectors from:', detectorsUrl)
const res = await fetch(detectorsUrl, { cache: 'no-store' })
const text = await res.text()
let payload: any
try { payload = JSON.parse(text) } catch { payload = text }
@@ -232,7 +266,7 @@ const NavigationPage: React.FC = () => {
}
}
loadDetectors()
}, [])
}, [selectedModelPath, objectId])
const handleBackClick = () => {
router.push('/dashboard')