Fix dashboard: gunakan camera URL dari database bukan hardcoded
This commit is contained in:
@@ -117,13 +117,9 @@ async function getLastAvailableDate() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Video HLS setup - mapping lokasi ke URL camera
|
// Video HLS setup - menggunakan URL kamera dari database
|
||||||
const LOCATION_CAMERAS = {
|
let gatesCache = {}; // Cache untuk gates dengan camera URL
|
||||||
'kerkof_01': {
|
let locationsCache = {}; // Cache untuk locations
|
||||||
url: 'https://kerkof.btekno.cloud/cam1/index.m3u8',
|
|
||||||
name: 'Kerkof'
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let hls = null;
|
let hls = null;
|
||||||
let isVideoPlaying = false;
|
let isVideoPlaying = false;
|
||||||
@@ -504,9 +500,59 @@ async function loadSummaryAndCharts() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load gates untuk mendapatkan camera URL dari database
|
||||||
|
async function loadGatesForCamera() {
|
||||||
|
try {
|
||||||
|
const response = await apiGetGates(null, { limit: 1000 });
|
||||||
|
let gates = Array.isArray(response) ? response : (response && Array.isArray(response.data) ? response.data : []);
|
||||||
|
|
||||||
|
gatesCache = {};
|
||||||
|
gates.forEach(gate => {
|
||||||
|
const locationCode = gate.location_code || '';
|
||||||
|
const camera = gate.camera || null;
|
||||||
|
|
||||||
|
// Hanya simpan gate yang punya camera URL
|
||||||
|
if (camera && camera.trim() !== '') {
|
||||||
|
// Jika sudah ada, gunakan yang pertama (atau bisa dipilih gate tertentu)
|
||||||
|
if (!gatesCache[locationCode]) {
|
||||||
|
const locationName = locationsCache[locationCode]?.name || locationCode;
|
||||||
|
gatesCache[locationCode] = {
|
||||||
|
url: camera.trim(),
|
||||||
|
name: locationName,
|
||||||
|
gate_name: gate.name || gate.gate_code || '',
|
||||||
|
location_code: locationCode
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log('[Dashboard] Gates dengan camera loaded:', Object.keys(gatesCache).length);
|
||||||
|
} catch (err) {
|
||||||
|
console.error('[Dashboard] Error loading gates for camera:', err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load locations untuk mendapatkan nama lokasi
|
||||||
|
async function loadLocationsForCamera() {
|
||||||
|
try {
|
||||||
|
const response = await apiGetLocations({ limit: 1000 });
|
||||||
|
let locations = Array.isArray(response) ? response : (response && Array.isArray(response.data) ? response.data : []);
|
||||||
|
|
||||||
|
locationsCache = {};
|
||||||
|
locations.forEach(loc => {
|
||||||
|
const code = loc.code || loc.location_code || '';
|
||||||
|
locationsCache[code] = {
|
||||||
|
name: loc.name || loc.label || code
|
||||||
|
};
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.error('[Dashboard] Error loading locations for camera:', err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function getCameraForLocation(locationCode) {
|
function getCameraForLocation(locationCode) {
|
||||||
if (!locationCode) return null;
|
if (!locationCode) return null;
|
||||||
return LOCATION_CAMERAS[locationCode] || null;
|
return gatesCache[locationCode] || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function showVideoPanel(locationCode) {
|
function showVideoPanel(locationCode) {
|
||||||
@@ -514,9 +560,10 @@ function showVideoPanel(locationCode) {
|
|||||||
const videoPanelTitle = document.getElementById('video-panel-title');
|
const videoPanelTitle = document.getElementById('video-panel-title');
|
||||||
const camera = getCameraForLocation(locationCode);
|
const camera = getCameraForLocation(locationCode);
|
||||||
|
|
||||||
if (camera && videoSection && videoPanelTitle) {
|
if (camera && camera.url && videoSection && videoPanelTitle) {
|
||||||
videoSection.style.display = 'block';
|
videoSection.style.display = 'block';
|
||||||
videoPanelTitle.textContent = `Live Camera - ${camera.name}`;
|
const displayName = camera.gate_name ? `${camera.name} - ${camera.gate_name}` : camera.name;
|
||||||
|
videoPanelTitle.textContent = displayName;
|
||||||
currentVideoUrl = camera.url;
|
currentVideoUrl = camera.url;
|
||||||
// Auto-stop video kalau lokasi berubah
|
// Auto-stop video kalau lokasi berubah
|
||||||
if (isVideoPlaying) {
|
if (isVideoPlaying) {
|
||||||
@@ -641,10 +688,13 @@ function setupFilters() {
|
|||||||
const gateSelect = document.getElementById('filter-gate');
|
const gateSelect = document.getElementById('filter-gate');
|
||||||
if (gateSelect) gateSelect.value = '';
|
if (gateSelect) gateSelect.value = '';
|
||||||
|
|
||||||
|
// Reload gates untuk update camera cache
|
||||||
|
await loadGates();
|
||||||
|
await loadGatesForCamera(); // Reload camera URLs
|
||||||
|
|
||||||
// Show/hide video panel berdasarkan lokasi
|
// Show/hide video panel berdasarkan lokasi
|
||||||
showVideoPanel(state.locationCode);
|
showVideoPanel(state.locationCode);
|
||||||
|
|
||||||
await loadGates();
|
|
||||||
loadSummaryAndCharts();
|
loadSummaryAndCharts();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -728,6 +778,10 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|||||||
await loadLocations();
|
await loadLocations();
|
||||||
await loadGates();
|
await loadGates();
|
||||||
|
|
||||||
|
// Load locations dan gates untuk camera URL dari database
|
||||||
|
await loadLocationsForCamera();
|
||||||
|
await loadGatesForCamera();
|
||||||
|
|
||||||
// Cek lokasi awal untuk show/hide video
|
// Cek lokasi awal untuk show/hide video
|
||||||
showVideoPanel(state.locationCode);
|
showVideoPanel(state.locationCode);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user