Tambah logging di loadLocationsForCamera dan getCameraForLocation

This commit is contained in:
mwpn
2025-12-19 05:09:09 +07:00
parent b6f79d4978
commit 39e90d4de6

View File

@@ -541,7 +541,12 @@ async function loadGatesForCamera() {
async function loadLocationsForCamera() { async function loadLocationsForCamera() {
try { try {
const response = await apiGetLocations({ limit: 1000 }); const response = await apiGetLocations({ limit: 1000 });
let locations = Array.isArray(response) ? response : (response && Array.isArray(response.data) ? response.data : []); let locations = [];
if (Array.isArray(response)) {
locations = response;
} else if (response && Array.isArray(response.data)) {
locations = response.data;
}
locationsCache = {}; locationsCache = {};
locations.forEach(loc => { locations.forEach(loc => {
@@ -550,14 +555,21 @@ async function loadLocationsForCamera() {
name: loc.name || loc.label || code name: loc.name || loc.label || code
}; };
}); });
console.log('[Dashboard] Locations loaded for camera:', Object.keys(locationsCache).length, locationsCache);
} catch (err) { } catch (err) {
console.error('[Dashboard] Error loading locations for camera:', err); console.error('[Dashboard] Error loading locations for camera:', err);
} }
} }
function getCameraForLocation(locationCode) { function getCameraForLocation(locationCode) {
if (!locationCode) return null; if (!locationCode) {
return gatesCache[locationCode] || null; console.log('[Dashboard] getCameraForLocation: no locationCode');
return null;
}
const camera = gatesCache[locationCode] || null;
console.log('[Dashboard] getCameraForLocation:', { locationCode, found: !!camera, gatesCacheKeys: Object.keys(gatesCache) });
return camera;
} }
function showVideoPanel(locationCode) { function showVideoPanel(locationCode) {