var _dash={
doneSetup:false,
params:null,
datePicker:null,
types:null,
cameras:null,
disks:null
};
function DashLoad(){
const sidebar=document.getElementById('dashSidebar');
const content=document.getElementById('dashContent');
sidebar.style.display='block';
content.style.display='block';
if(!_dash.doneSetup){
_dash.types=[
{id:1,name:Loc('CPU Usage')},
{id:9,name:Loc('Incoming Data Rate')},
{id:12,name:Loc('Recording Data Rate')},
{id:14,name:Loc('Packet Loss')},
{id:4,name:Loc('Video Decoder Pressure')},
{id:10,name:Loc('Camera Processing Duty')},
{id:11,name:Loc('Disk Pressure')},
{id:2,name:Loc('Memory Pressure')},
{id:15,name:Loc('Application Memory Usage')},
{id:16,name:Loc('System Thermal State')}];
_dash.cameras=[
{id:-1,name:Loc('All Cameras (Average)')},
{id:-2,name:Loc('All Cameras (Sum)')},
{id:-3,name:Loc('All Cameras (Minimum)')},
{id:-4,name:Loc('All Cameras (Maximum)')}];
_dash.disks=[
{id:-1,name:Loc('All Disks (Average)')},
{id:-2,name:Loc('All Disks (Sum)')}];
let today=new Date();
_dash.datePicker=new Litepicker({element: document.getElementById('dashDate'),singleMode:true,format:_dateFormat,startDate:today,maxDate:today,setup:(picker)=>{
picker.on('selected',DashDateChanged);
}});
const s1=document.getElementById('dashType1');
const s2=document.getElementById('dashType2');
for(let i=0;i<_dash.types.length;i++){
const opt1=document.createElement('option');
const opt2=document.createElement('option');
opt1.value=_dash.types[i].id;
opt1.text=_dash.types[i].name;
opt2.value=_dash.types[i].id;
opt2.text=_dash.types[i].name;
s1.add(opt1);
s2.add(opt2);
}
for(let i=0;i<_cams.length;i++)_dash.cameras.push({id:_cams[i].num,name:_cams[i].name});
_dash.doneSetup=true;
}
window.onresize=()=>{DashGenerate();};
FixRangeElements();
DashGenerate();
}
function DashUnload(){
const sidebar=document.getElementById('dashSidebar');
const content=document.getElementById('dashContent');
sidebar.style.display='none';
content.style.display='none';
window.onresize=null;
_dash.params=null;
_dash.observer=null;
}
function DashDateChanged(){
DashSetUpItemControls(1);
DashSetUpItemControls(2);
DashGenerate();
}
function DashTypeChanged(which){
DashSetUpItemControls(which);
DashGenerate();
}
function DashItemChanged(){
DashGenerate();
}
function DashSmoothChanged(){
DashGenerate();
}
function DashGenerate(){
let params=GetFormKeyValueString(document.getElementById('dashForm'));
let contentDiv=document.getElementById('dashContent');
params+='&width='+contentDiv.offsetWidth+'&height='+contentDiv.offsetHeight;
params+='&date='+_dash.datePicker.getStartDate().format('YYYY-MM-DD');
if(params!=_dash.params){
document.getElementById('dashImg').src='dashImage?'+params+'&dark='+((window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches)?1:0)+'&'+(Math.floor(Math.random()*100000));
_dash.params=params;
}
}
function DashSetUpItemControls(which){
const typeSel=document.getElementById('dashType'+which);
const itemSel=document.getElementById('dashItem'+which);
itemSel.innerHTML='';
switch(parseInt(typeSel.value)){
case 4:case 9:case 10:case 12:case 14:
for(let i=0;i<_dash.cameras.length;i++)itemSel.add(new Option(_dash.cameras[i].name,_dash.cameras[i].id));
itemSel.style.display='block';
break;
case 11:
for(let i=0;i<_dash.disks.length;i++)itemSel.add(new Option(_dash.disks[i].name,_dash.disks[i].id));
itemSel.style.display='block';
break;
default:
itemSel.style.display='none';
}
}
