New api and zone management; highligh occlusion and highlighAll functionality; improved search in reports and alerts history + autofill; refactored alert panel
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import React, { useState } from 'react';
|
||||
import Image from 'next/image';
|
||||
import useNavigationStore from '@/app/store/navigationStore';
|
||||
import type { Zone } from '@/app/types';
|
||||
|
||||
interface ToolbarButton {
|
||||
icon: string;
|
||||
@@ -32,7 +33,7 @@ const SceneToolbar: React.FC<SceneToolbarProps> = ({
|
||||
navMenuActive = false,
|
||||
}) => {
|
||||
const [isZoomOpen, setIsZoomOpen] = useState(false);
|
||||
const { PREFERRED_MODEL, showMonitoring, openMonitoring, closeMonitoring } = useNavigationStore();
|
||||
const { showMonitoring, openMonitoring, closeMonitoring, currentZones, loadZones, currentObject } = useNavigationStore();
|
||||
|
||||
const handleToggleNavMenu = () => {
|
||||
if (showMonitoring) {
|
||||
@@ -43,25 +44,46 @@ const SceneToolbar: React.FC<SceneToolbarProps> = ({
|
||||
};
|
||||
|
||||
const handleHomeClick = async () => {
|
||||
if (onSelectModel) {
|
||||
try {
|
||||
const res = await fetch('/api/big-models/list');
|
||||
if (!res.ok) {
|
||||
throw new Error('Failed to fetch models list');
|
||||
}
|
||||
const data = await res.json();
|
||||
const items: { name: string; path: string }[] = Array.isArray(data?.models) ? data.models : [];
|
||||
const preferredModelName = PREFERRED_MODEL.split('/').pop()?.split('.').slice(0, -1).join('.') || '';
|
||||
const preferredModel = items.find(model => (model.path.split('/').pop()?.split('.').slice(0, -1).join('.') || '') === preferredModelName);
|
||||
if (!onSelectModel) return;
|
||||
|
||||
if (preferredModel) {
|
||||
onSelectModel(preferredModel.path);
|
||||
} else {
|
||||
console.error('Preferred model not found in the list');
|
||||
try {
|
||||
let zones: Zone[] = Array.isArray(currentZones) ? currentZones : [];
|
||||
|
||||
// Если зоны ещё не загружены, откройте Monitoring и загрузите зоны для текущего объекта
|
||||
if ((!zones || zones.length === 0) && currentObject?.id) {
|
||||
if (!showMonitoring) {
|
||||
openMonitoring();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching models list:', error);
|
||||
await loadZones(currentObject.id);
|
||||
zones = useNavigationStore.getState().currentZones || [];
|
||||
}
|
||||
|
||||
if (!Array.isArray(zones) || zones.length === 0) {
|
||||
console.warn('No zones available to select a model from.');
|
||||
return;
|
||||
}
|
||||
|
||||
const sorted = zones.slice().sort((a: Zone, b: Zone) => {
|
||||
const oa = typeof a.order === 'number' ? a.order : 0;
|
||||
const ob = typeof b.order === 'number' ? b.order : 0;
|
||||
if (oa !== ob) return oa - ob;
|
||||
return (a.name || '').localeCompare(b.name || '');
|
||||
});
|
||||
|
||||
const top = sorted[0];
|
||||
let chosenPath: string | null = top?.model_path && String(top.model_path).trim() ? top.model_path! : null;
|
||||
if (!chosenPath) {
|
||||
const nextWithModel = sorted.find((z) => z.model_path && String(z.model_path).trim());
|
||||
chosenPath = nextWithModel?.model_path ?? null;
|
||||
}
|
||||
|
||||
if (chosenPath) {
|
||||
onSelectModel(chosenPath);
|
||||
} else {
|
||||
console.warn('No zone has a valid model_path to open.');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error selecting top zone model:', error);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user