You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

1299 lines
38 KiB

//<?php require_once('../../js_asm.php'); ?>
var serverToolBox = null;
var currentNodeID = 0;
//import * as THREE from 'three';
//let camera, scene, renderer;
var l3dMapOverlayTexture = new THREE.TextureLoader().load( '/lib/controller/data/assets/images/mask_3d.png' );
var l3dMapOverlayMaterial = new THREE.MeshBasicMaterial( { map: l3dMapOverlayTexture, alphaTest: 0.7 } );
var l3dMapOverlayGeometry = new THREE.SphereGeometry( 490, 60, 40 );
// invert the geometry on the x-axis so that all of the faces point inward
l3dMapOverlayGeometry.scale( -1, 1, 1 );
var l3dMapOverlayMesh = new THREE.Mesh( l3dMapOverlayGeometry, l3dMapOverlayMaterial );
function addl3dTarget( id, radius, az, el, color = 0xff0000 ){
if( id > 0 ){
var target = {};
target.geometry = new THREE.BoxGeometry( 10, 10, 10 );
//target.geometry = new THREE.OctahedronGeometry({ radius : 20 });
//target.geometry.translate( x, y, z );
// Turn back into Cartesian coordinates
var fi = (Math.PI/2) - el;
var x = radius * Math.sin( fi) * Math.cos( az );
var y = radius * Math.sin( fi ) * Math.sin( az );
var z = radius * Math.cos( fi );
//alert( "Cords: "+x+" "+y+" "+z+" An:"+az+" "+el);
//target.geometry.position.set( x, y, z ); //translate( x, y, z );
target.material = new THREE.MeshBasicMaterial( {color: color} );
target.mesh = new THREE.Mesh( target.geometry, target.material );
nodeTHREEviewers[id].scene.add( target.mesh );
target.mesh.position.set( x, z, y );
nodeTHREEviewers[id].targets.push( target );
};
};
function cleanup3DDraw( id ){
if( typeof nodeTHREEviewers[id] !== 'undefined' ){
if( typeof nodeTHREEviewers[id].targets !== 'undefined' ){
for( var z=0; z < nodeTHREEviewers[id].targets.length; z++ ){
nodeTHREEviewers[id].scene.remove( nodeTHREEviewers[id].targets[z].mesh );
delete nodeTHREEviewers[id].targets[z].mesh;
delete nodeTHREEviewers[id].targets[z].material;
delete nodeTHREEviewers[id].targets[z].geometry;
delete nodeTHREEviewers[id].targets[z];
};
nodeTHREEviewers[id].targets = [];
//nodeTHREEviewers[id].renderer.render( nodeTHREEviewers[id].scene, nodeTHREEviewers[id].camera );
};
};
};
function DrawClicker( id, event ){
var x = event.offsetX-100;
var y = event.offsetY-100;
switch( drawZoomLevels[ id ] ){
case 100:{
var r = Math.round( 1024.0 / 98 * Math.sqrt( x*x + y*y ) );
if( r > 1024 ) r = 1024;
break;
};
case 50:{
var r = Math.round( 512.0 / 98 * Math.sqrt( x*x + y*y ) );
if( r > 512 ) r = 512;
break;
};
case 25:{
var r = Math.round( 256.0 / 98 * Math.sqrt( x*x + y*y ) );
if( r > 256 ) r = 256;
break;
};
case 12:{
var r = Math.round( 128.0 / 98 * Math.sqrt( x*x + y*y ) );
if( r > 128 ) r = 128;
break;
};
default:{
var r = -1;
break;
};
};
if( r > -1 ){
var z = Math.round( -1.0 * Math.atan2(y, x) * 3000 / Math.PI );
if( z < 0 ) z += 6000 ;
doDeviceOperation( id, 42, r+':'+z, true );
};
};
function Draw3DTargets( k, b ){
cleanup3DDraw( k );
for( var z = 0; z < b.length; z++ ){
var az = b[z].az * ( Math.PI/180.0 );
var el = b[z].el * ( Math.PI/180.0 );
//addl3dTarget( k, b[z].range, az, el, b[z].color );
addl3dTarget( k, 280, az, el, b[z].color );
};
};
let isUserInteracting = false, onPointerDownMouseX = 0, onPointerDownMouseY = 0,
lon = 0, onPointerDownLon = 0,
lat = 0, onPointerDownLat = 0,
phi = 0, theta = 0;
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
};
function onPointerDown( event ) {
if ( event.isPrimary === false ) return;
isUserInteracting = true;
onPointerDownMouseX = event.clientX;
onPointerDownMouseY = event.clientY;
onPointerDownLon = lon;
onPointerDownLat = lat;
document.addEventListener( 'pointermove', onPointerMove );
document.addEventListener( 'pointerup', onPointerUp );
};
function onPointerMove( event ) {
if ( event.isPrimary === false ) return;
lon = ( onPointerDownMouseX - event.clientX ) * 0.1 + onPointerDownLon;
lat = ( event.clientY - onPointerDownMouseY ) * 0.1 + onPointerDownLat;
};
function onPointerUp() {
if ( event.isPrimary === false ) return;
isUserInteracting = false;
document.removeEventListener( 'pointermove', onPointerMove );
document.removeEventListener( 'pointerup', onPointerUp );
};
function onDocumentMouseWheel( event ) {
var id = event.currentTarget.myVID;
if( id > 0 ){
const fov = nodeTHREEviewers[id].camera.fov + event.deltaY * 0.05;
nodeTHREEviewers[id].camera.fov = THREE.MathUtils.clamp( fov, 10, 75 );
nodeTHREEviewers[id].camera.updateProjectionMatrix();
};
};
function reload3dTexture( id ){
if( typeof nodeTHREEviewers[id] !== 'undefined' ){
stopAnimation();
//while( nodeTHREEviewers[id].scene.children.length > 0){
// nodeTHREEviewers[id].scene.remove(nodeTHREEviewers[id].scene.children[0]);
//};
nodeTHREEviewers[id].scene.remove( nodeTHREEviewers[id].mesh );
//nodeTHREEviewers[id].mesh.geometry.dispose();
//nodeTHREEviewers[id].mesh.material.dispose();
delete nodeTHREEviewers[id].mesh;
delete nodeTHREEviewers[id].material;
delete nodeTHREEviewers[id].texture;
delete nodeTHREEviewers[id].geometry;
nodeTHREEviewers[id].geometry = new THREE.SphereGeometry( 500, 60, 40 );
nodeTHREEviewers[id].geometry.scale( -1, 1, 1 );
nodeTHREEviewers[id].texture = new THREE.TextureLoader().load( '/lib/controller/getDeviceDraw.php?NID='+id );
nodeTHREEviewers[id].material = new THREE.MeshBasicMaterial( { map: nodeTHREEviewers[id].texture } );
nodeTHREEviewers[id].mesh = new THREE.Mesh( nodeTHREEviewers[id].geometry, nodeTHREEviewers[id].material );
nodeTHREEviewers[id].scene.add( nodeTHREEviewers[id].mesh );
animate();
//nodeTHREEviewers[id].material.map.needsUpdate = true;
//nodeTHREEviewers[id].material.needsUpdate = true
//alert( ' reloadded ' );
};
};
function stopAnimation(){
if( nodeTHREEanimationId > 0 ) cancelAnimationFrame( nodeTHREEanimationId );
};
function animate( ) {
if( nodeTHREEanimationId > 0 ) cancelAnimationFrame( nodeTHREEanimationId );
nodeTHREEanimationId = requestAnimationFrame( animate );
nodeTHREEviewers.forEach( function(element, index, array){
if ( isUserInteracting === false ) {
lon += 0.5;
}
lat = Math.max( - 85, Math.min( 85, lat ) );
phi = THREE.MathUtils.degToRad( 90 - lat );
theta = THREE.MathUtils.degToRad( lon );
const x = 500 * Math.sin( phi ) * Math.cos( theta );
const y = 500 * Math.cos( phi );
const z = 500 * Math.sin( phi ) * Math.sin( theta );
element.camera.lookAt( x, y, z );
element.renderer.render( element.scene, element.camera );
});
//update( id );
};
function animateTargets(){
if( nodeTHREEanimationId > 0 ) cancelAnimationFrame( nodeTHREEanimationId );
nodeTHREEanimationId = requestAnimationFrame( animateTargets );
nodeTHREEviewers.forEach( function(element, index, array){
if ( isUserInteracting === false ) {
if( element.targetShowCopunter ){
element.targetShowCopunter--;
} else {
element.camera.lookAt( element.targets[element.targetIndex].mesh.position );
element.targetShowCopunter = 100;
element.renderer.render( element.scene, element.camera );
element.targetIndex++;
if( element.targetIndex == element.targets.length ) element.targetIndex = 0;
};
};
});
};
function update() {
if ( isUserInteracting === false ) {
lon += 0.5;
}
lat = Math.max( - 85, Math.min( 85, lat ) );
phi = THREE.MathUtils.degToRad( 90 - lat );
theta = THREE.MathUtils.degToRad( lon );
const x = 500 * Math.sin( phi ) * Math.cos( theta );
const y = 500 * Math.cos( phi );
const z = 500 * Math.sin( phi ) * Math.sin( theta );
camera.lookAt( x, y, z );
renderer.render( scene, camera );
};
function Pie(cx, cy, radius, data) {
var decimals = 4;
var total = 0;
var offset = 0;
var offset2;
var arr = [];
var x;
var y;
var la;
var radians;
for (var i = 0; i < data.length; i++)
total += data[i].value;
for (var i = 0; i < data.length; i++) {
var item = data[i];
var tmp = {};
tmp.index = i;
tmp.value = item.value;
radians = ((((item.value / total) * 360) * Math.PI) / 180).floor(decimals);
offset2 = ((offset / total) * 360).floor(decimals);
tmp.data = item;
x = (cx + Math.sin(radians) * radius).floor(decimals);
y = (cy - Math.cos(radians) * radius).floor(decimals);
la = radians > Math.PI ? 1 : 0;
// Arc
tmp.d = 'M{0} {1},L{0} {2},A{3} {3},0 {4} 1,{5} {6}Z'.format(cx, cy, cy - radius, radius, la, x, y);
tmp.transform = 'rotate({0}, {1}, {2})'.format(offset2, cx, cy);
// Text
x = (cx + Math.sin(radians / 2) * radius / 2).floor(decimals);
y = (cy - Math.cos(radians / 2) * radius / 2).floor(decimals);
tmp.text = 'x="{0}" y="{1}" transform="rotate({2},{0},{1})"'.format(x, y, -offset2);
offset += item.value;
arr.push(tmp);
}
return arr;
}
function Donut(cx, cy, radius, data) {
function arcradius(cx, cy, radius, degrees) {
var radians = (degrees - 90) * Math.PI / 180.0;
return { x: cx + (radius * Math.cos(radians)), y: cy + (radius * Math.sin(radians)) };
}
var decimals = 4;
var total = 0;
var arr = [];
var beg = 0;
var end = 0;
var count = 0;
var half = radius / 2;
var midpoint = radius / 2.4;
for (var i = 0; i < data.length; i++)
total += data[i].value;
for (var i = 0; i < data.length; i++) {
var item = data[i];
var tmp = {};
//var p = (((item.value + 1) / total) * 100).floor( 2 );
var p = Math.floor(((item.value + 1) / total) * 100);
count += p;
if (i === length - 1 && count < 100)
p = p + (100 - count);
end = beg + ((360 / 100) * p);
tmp.index = i;
tmp.value = item.value;
tmp.data = item;
var b = arcradius(cx, cy, radius, end);
var e = arcradius(cx, cy, radius, beg);
var la = (end - beg) <= 180 ? 0 : 1;
tmp.d = ['M', Math.floor( b.x ), Math.floor( b.y ), 'A', radius, radius, 0, la, 0, Math.floor( e.x ), Math.floor( e.y ) ].join(' ');
arr.push(tmp);
beg = end;
}
return arr;
}
//Pie Chart Usage
/*
var svg = $('#yoursvgelement');
var data = [{ value: 33 }, { value: 20 }, { value: 80 }, { value: 48 }];
var centerX = 300;
var centerY = 300;
var radius = 250;
var color = ['#F6BB42', '#8CC152', '#3BAFDA', '#967ADC', '#DA4453'];
var arr = Pie(centerX, centerY, radius, data);
for (var i = 0; i < arr.length; i++) {
var item = arr[i];
svg.asvg('<g transform="{0}"><path d="{1}" fill="{4}" /><text fill="white" font-size="25" {2}>{3}</text></g>'.format(item.transform, item.d, item.text, item.value, color[i]));
}
*/
// Donut Chart Usage
/*
var svg = $('#yoursvgelement');
var data = [{ value: 33 }, { value: 20 }, { value: 80 }, { value: 48 }];
var centerX = 300;
var centerY = 300;
var radius = 250;
var color = ['#F6BB42', '#8CC152', '#3BAFDA', '#967ADC', '#DA4453'];
var arr = Donut(centerX, centerY, radius, data);
for (var i = 0; i < arr.length; i++) {
var item = arr[i];
svg.asvg('<g><path d="{0}" stroke="{1}" fill="none" stroke-width="50" /></g>'.format(item.d, color[i]));
}
*/
function makePtzMove( me ){
var name = me.target.id;
Ext.Ajax.request({
url: '/lib/controller/camMakeMove.php',
params: {
SITE: <?=$SiteID;?>,
UID: <?=$UserID;?>,
SID: '<?=$Session;?>',
CMD: name
},
//success: function( response, opts ){
//},
failure: failureAJAXFunction
});
};
function ptzCtrl( a ){
};
function makePtzStop( me ){
var name = me.target.id;
Ext.Ajax.request({
url: '/lib/controller/camStop.php',
params: {
SITE: <?=$SiteID;?>,
UID: <?=$UserID;?>,
SID: '<?=$Session;?>',
CMD: name
},
//success: function( response, opts ){
//},
failure: failureAJAXFunction
});
};
function fullScreen( id = '' ){
if(
id == '' ||
document.fullscreenElement ||
document.webkitFullscreenElement ||
document.mozFullScreenElement ||
document.msFullscreenElement
){
if( document.exitFullscreen ){
document.exitFullscreen();
}else if( document.mozCancelFullScreen ){
document.mozCancelFullScreen();
}else if( document.webkitExitFullscreen ){
document.webkitExitFullscreen();
}else if( document.msExitFullscreen ){
document.msExitFullscreen();
};
}else{
//element = $('#container').get(0);
var element = document.getElementById( id ); //Ext.getCmp( id );
if( element.requestFullscreen ){
element.requestFullscreen();
}else if( element.mozRequestFullScreen ){
element.mozRequestFullScreen();
}else if( element.webkitRequestFullscreen ){
element.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
}else if( element.msRequestFullscreen ){
element.msRequestFullscreen();
};
};
};
function updateDashBoardItemLayout( id, x, y ){
Ext.Ajax.request({
url: '/lib/controller/updateDashBoardItems.php',
params: {
SITE: <?=$SiteID;?>,
UID: <?=$UserID;?>,
SID: '<?=$Session;?>',
PANEL: id,
X: x,
Y: y
},
success: function( response, opts ){
//var data = Ext.decode(response.responseText);
//var tPanel = Ext.getCmp('main_portal');
//tPanel.removeAll(true);
//for( i=0; i < data.length; i++) tPanel.add( data[i] );
//tPanel.doLayout();
},
failure: failureAJAXFunction
});
};
var drawZoomLevels = Array();
function cleanup2DDraw( a ){
var canvas = document.getElementById('targ_canvas_'+a );
var img = document.getElementById('draw_img_'+a );
if( canvas != 'undefined' ){
canvas.style='display: block; cursor: crosshair;'; //cursor: auto;
img.style='display: none;';
var ctx = canvas.getContext('2d');
ctx.drawImage( img, 0, 0 );
};
};
function Draw2DTargets( k, b ){
var canvas = document.getElementById('targ_canvas_'+k );
var ctx = canvas.getContext('2d');
var img = document.getElementById('draw_img_'+k );
ctx.drawImage( img, 0, 0 );
canvas.style='display: block;';
img.style='display: none;';
for( var i=0; i< b.length; i++ ){
switch( drawZoomLevels[k] ){
case 12:{
if( b[i].digital < 256 ){
var cc = 255 - i ;//* ( 255 / 33 );
//ctx.fillStyle = "#" + cc.toString(16) + "0000";
ctx.fillStyle = "rgba(255, 0, 0,"+((b.length - i)/ b.length )+")";
//ctx.strokeStyle = "#FF0000";
var r = (196 * b[i].digital)/ 512;
var a = -1.0 * b[i].az * ( Math.PI / 180 );
var x = 100 + Math.cos( a ) * r;
var y = 100 + Math.sin( a ) * r;
ctx.fillRect( x, y, 24, 24 );
};
break;
};
case 25:{
if( b[i].digital < 512 ){
var cc = 255 - i ;//* ( 255 / 33 );
//ctx.fillStyle = "#" + cc.toString(16) + "0000";
ctx.fillStyle = "rgba(255, 0, 0,"+((b.length - i)/ b.length )+")";
//ctx.strokeStyle = "#FF0000";
var r = (196 * b[i].digital)/ 1024;
var a = -1.0 * b[i].az * ( Math.PI / 180 );
var x = 100 + Math.cos( a ) * r;
var y = 100 + Math.sin( a ) * r;
ctx.fillRect( x, y, 12, 12 );
};
break;
};
case 50:{
if( b[i].digital < 1024 ){
var cc = 255 - i ;//* ( 255 / 33 );
//ctx.fillStyle = "#" + cc.toString(16) + "0000";
ctx.fillStyle = "rgba(255, 0, 0,"+((b.length - i)/ b.length )+")";
//ctx.strokeStyle = "#FF0000";
var r = (196 * b[i].digital) / 2048;
var a = -1.0 * b[i].az * ( Math.PI / 180 );
var x = 100 + Math.cos( a ) * r;
var y = 100 + Math.sin( a ) * r;
ctx.fillRect( x, y, 6, 6 );
};
break;
};
case 100:{
var cc = 255 - i ;//* ( 255 / 33 );
//ctx.fillStyle = "#" + cc.toString(16) + "0000";
ctx.fillStyle = "rgba(255, 0, 0,"+((b.length - i)/ b.length )+")";
//ctx.strokeStyle = "#FF0000";
var r = (196 * b[i].digital)/ 4096;
var a = -1.0 * b[i].az * ( Math.PI / 180 );
var x = 100 + Math.cos( a ) * r;
var y = 100 + Math.sin( a ) * r;
ctx.fillRect( x, y, 3, 3 );
break;
};
};
};
};
var lastNotificationID = 0;
function setDonatStatus( node_id, param_id, value ){
alert('zaza');
var val1D = document.getElementById('status_'+node_id+'_donut'+param_id+'_segment1');
var val2D = document.getElementById('status_'+node_id+'_donut'+param_id+'_segment2');
var val3D = document.getElementById('status_'+node_id+'_donut'+param_id+'_segment3');
var val1 = (value>-1)?value:0;
var val2 = (value>-1)?100 - val1:0;//data.nodes[i].cpu5 * 100;
var val3 = (value>-1)?0:100;//data.nodes[i].cpu15 * 100;
var totalValue = document.getElementById('status_'+node_id+'_totalValue'+param_id);
if( totalValue == undefined ) return;
var total = val1+val2+val3;
var per1 = val1/total*100;
var per2 = val2/total*100;
var per3 = val3/total*100;
var offset = 25;
if( ( val1 != undefined ) && ( value > -1 ) ){
totalValue.textContent = val1+'%';
} else {
totalValue.textContent = 'No Data';
};
val1D.style.transition = "stroke-dasharray 0.5s ease-in-out, stroke-dashoffset 0.5s ease-in-out";
val1D.style.strokeDasharray = per1+" "+(100-per1);
val1D.style.strokeDashoffset = offset;
val2D.style.transition = "stroke-dasharray 0.5s ease-in-out, stroke-dashoffset 0.5s ease-in-out";
val2D.style.strokeDasharray = per2+" "+(100-per2);
val2D.style.strokeDashoffset = 100-per1+offset;
val3D.style.transition = "stroke-dasharray 0.5s ease-in-out, stroke-dashoffset 0.5s ease-in-out";
val3D.style.strokeDasharray = per3+" "+(100-per3);
val3D.style.strokeDashoffset = 100-(per1+per2)+offset;
};
function fetchSiteStatus(){
Ext.Ajax.request({
url: '/lib/controller/getStatus.php',
params: {
SITE: <?=$SiteID;?>,
LNID: lastNotificationID,
SPID: StatusTS,
LOAT: LoadTS,
UID: <?=$UserID;?>,
SID: '<?=$Session;?>'
},
success: function( response, opts ){
var data = Ext.decode(response.responseText);
StatusTS = data.CTS;
if( data.nodes.length > 0 ){
for( i=0; i < data.nodes.length; i++ ){
if( data.nodes[i].type == 0 ){
//Handle Server Status
if ( data.nodes[i].status ){
setDonatStatus( data.nodes[i].id, 0, data.nodes[i].cpu5 );
setDonatStatus( data.nodes[i].id, 1, data.nodes[i].mem );
setDonatStatus( data.nodes[i].id, 2, data.nodes[i].disk );
document.getElementById('status_'+data.nodes[i].id+'_txt').innerHTML="Server is Online";
document.getElementById('status_'+data.nodes[i].id+'_img').src = "/style/icons/icons/accept.png";
} else {
setDonatStatus( data.nodes[i].id, 0, -1 );
setDonatStatus( data.nodes[i].id, 1, -1 );
setDonatStatus( data.nodes[i].id, 2, -1 );
document.getElementById('status_'+data.nodes[i].id+'_txt').innerHTML="Server is Offline";
document.getElementById('status_'+data.nodes[i].id+'_img').src = "/style/icons/icons/stop.png";
};
};
// Sesors
if( data.nodes[i].type > 0 && data.nodes[i].type < 7 ){
if( data.nodes[i].reload_draw ){
reload3dTexture( data.nodes[i].id );
LoadTS = StatusTS;
};
};
// Cameras
if( data.nodes[i].type > 9 && data.nodes[i].type < 14 ){
var iel = document.getElementById('img-'+data.nodes[i].id );
if( iel != null ){
if( !data.nodes[i].valid ){
if( iel.src != "/style/assets/no-signal.png" ) iel.src = "/style/assets/no-signal.png";
} else {
if( data.nodes[i].src != iel.src ) iel.src = data.nodes[i].src;
};
};
};
var tt = Ext.getCmp('status_'+data.nodes[i].id );
if( tt != undefined ){
if( data.nodes[i].type < 5 && data.nodes[i].type > 0 ){
if( data.nodes[i].status == 4 ){
Draw2DTargets( data.nodes[i].id, data.nodes[i].targets );
} else {
cleanup2DDraw( data.nodes[i].id );
};
};
if( data.nodes[i].type == 5 ){//addl3dTarget( id, radius, az, el, color = 0xff0000 )
if( data.nodes[i].status == 4 ){
//DrawTargets( data.nodes[i].id, data.nodes[i].targets );
//addl3dTarget( data.nodes[i].id, data.nodes[i].targets[0].digital, data.nodes[i].targets[0].az, data.nodes[i].targets[0].el );
//addl3dTarget( data.nodes[i].id, 150, data.nodes[i].targets[0].az, data.nodes[i].targets[0].el );
Draw3DTargets( data.nodes[i].id, data.nodes[i].targets );
animateTargets();
} else {
cleanup3DDraw( data.nodes[i].id );
animate();
};
var ca = document.getElementById( 'status_canvas_' + data.nodes[i].id );
var ctx = ca.getContext('2d');
//if( stat_present );
ca.style='display: block;';
ctx.font = "10px Arial";
ctx.fillStyle = "rgba(255, 255, 255, 255)";
ctx.fillText( "Master:", 5, 8 );
ctx.fillText( "Slave:", 5, 24 );
//var cc = 255 - i ;//* ( 255 / 33 );
//ctx.fillStyle = "#" + cc.toString(16) + "0000";
//ctx.fillStyle = "rgba(255, 0, 0, 100)";//+((b.length - i)/ b.length )+")";
if( data.nodes[i].master_present ){
ctx.fillStyle = "rgba(0, 255, 0, 255)";
} else {
ctx.fillStyle = "rgba(128, 0, 0, 255)";
};
ctx.fillRect( 43, 1, 8, 8 );
if( data.nodes[i].stat_present ){
ctx.strokeStyle = "#FFFF00";
ctx.strokeRect( 43, 1, 8, 8 );
ctx.beginPath();
ctx.moveTo( 51, 5 );
ctx.lineTo( 56, 5 );
ctx.lineTo( 56, 2 );
ctx.lineTo( 103, 2 );
ctx.lineTo( 103, 5 );
ctx.moveTo( 63, 5 );
ctx.lineTo( 143, 5 );
ctx.stroke();
for( z=0; z < 8; z++ ){
//ctx.strokeStyle = "#FFFF00";
//ctx.fillStyle = "rgba(0, 255, 0, 255)";
ctx.fillStyle = "rgba(20, 20, 20, 255)";
h = 19 - ( 19 * data.nodes[i].runtime.mp[z] );
ha = 19 - h;
ctx.fillRect( 64 + z*10, 7, 2, h );
if( ha > 0 ) {
if( data.nodes[i].runtime.mp[z] > 0.8 ){
ctx.fillStyle = "rgba(0, 255, 0, 255)";
} else if ( data.nodes[i].runtime.mp[z] > 0.5 ){
ctx.fillStyle = "rgba( 255, 255, 0, 255)";
} else if ( data.nodes[i].runtime.mp[z] > 0.3 ){
ctx.fillStyle = "rgba( 255, 128, 0, 255)";
} else {
ctx.fillStyle = "rgba( 255, 0, 0, 255)";
};
ctx.fillRect( 64 + z*10, 7+h, 2, ha );
};
ctx.fillStyle = "rgba(20, 20, 20, 255)";
h = 19 - ( 19 * data.nodes[i].runtime.gp[z] );
ha = 19 - h;
ctx.fillRect( 67 + z*10, 7, 2, h );
if( ha > 0 ) {
if( data.nodes[i].runtime.gp[z] > 0.8 ){
ctx.fillStyle = "rgba(0, 255, 0, 255)";
} else if ( data.nodes[i].runtime.gp[z] > 0.5 ){
ctx.fillStyle = "rgba( 255, 255, 0, 255)";
} else if ( data.nodes[i].runtime.gp[z] > 0.3 ){
ctx.fillStyle = "rgba( 255, 128, 0, 255)";
} else {
ctx.fillStyle = "rgba( 255, 0, 0, 255)";
};
ctx.fillRect( 67 + z*10, 7+h, 2, ha );
};
ctx.fillStyle = "rgba(20, 20, 20, 255)";
h = 19 - ( 19 * data.nodes[i].runtime.wp[z] );
ha = 19 - h;
ctx.fillRect( 70 + z*10, 7, 2, h );
if( ha > 0 ){
if( data.nodes[i].runtime.wp[z] > 0.8 ){
ctx.fillStyle = "rgba(0, 255, 0, 255)";
} else if ( data.nodes[i].runtime.wp[z] > 0.5 ){
ctx.fillStyle = "rgba( 255, 255, 0, 255)";
} else if ( data.nodes[i].runtime.wp[z] > 0.3 ){
ctx.fillStyle = "rgba( 255, 128, 0, 255)";
} else {
ctx.fillStyle = "rgba( 255, 0, 0, 255)";
};
ctx.fillRect( 70 + z*10, 7+h, 2, ha );
};
};
//ffmpeg -f v4l2 -framerate <framerate> -thread_queue_size 512 -i <input device> -f alsa -thread_queue_size 512 -i <input device> -t <duration of video> -c:v h264 -c:a aac -pix_fmt yuv420p <output filename>
} else {
ctx.strokeStyle = "#808080";
ctx.strokeRect( 43, 1, 8, 8 );
ctx.beginPath();
ctx.moveTo( 51, 5 );
ctx.lineTo( 56, 5 );
ctx.lineTo( 56, 2 );
ctx.lineTo( 103, 2 );
ctx.lineTo( 103, 5 );
ctx.moveTo( 63, 5 );
ctx.lineTo( 143, 5 );
ctx.stroke();
ctx.fillStyle = "rgba( 128, 0, 0, 255)";
for( z=0; z < 8; z++ ){
ctx.fillRect( 64 + z*10, 7, 2, 19 );
ctx.fillRect( 67 + z*10, 7, 2, 19 );
ctx.fillRect( 70 + z*10, 7, 2, 19 );
//https://www.ebay.com/itm/304440983138
};
};
if( data.nodes[i].slave_present ){
ctx.strokeStyle = "#FFFF00";
ctx.fillStyle = "rgba(0, 255, 0, 255)";
} else {
ctx.strokeStyle = "#808080";
ctx.fillStyle = "rgba(128, 0, 0, 255)";
};
ctx.fillRect( 43, 17, 8, 8 );
ctx.strokeRect( 43, 17, 8, 8 );
ctx.beginPath();
ctx.moveTo( 51, 21 );
ctx.lineTo( 56, 21 );
ctx.lineTo( 56, 31 );
ctx.lineTo( 187, 31 );
ctx.lineTo( 187, 28 );
ctx.moveTo( 147, 28 );
ctx.lineTo( 227, 28 );
ctx.stroke();
for( z=8; z < 16; z++ ){
//ctx.strokeStyle = "#FFFF00";
//ctx.fillStyle = "rgba(0, 255, 0, 255)";
ctx.fillRect( 68 + z*10, 7, 2, 19 );
ctx.fillRect( 71 + z*10, 7, 2, 19 );
ctx.fillRect( 74 + z*10, 7, 2, 19 );
//ctx.strokeRect( 43, 1, 8, 8 );
};
};
if( typeof nodeDashboardStatuses[i] === 'undefined' || nodeDashboardStatuses[i] != data.nodes[i].status ){
nodeDashboardStatuses[i] = data.nodes[i].status;
switch( data.nodes[i].status ){
case 0:{
if( data.nodes[i].type == 3 ) cleanup2DDraw( data.nodes[i].id );
tt.update('<table style="background-color:#808080; color:#ffff00;" border="0" width="100%"><tr><td>Offline</td><td width="16"><img width="16px" src="/style/assets/offline.png"></td></tr></table>');
break;
};
case 1:{
if( data.nodes[i].type == 3 ) cleanup2DDraw( data.nodes[i].id );
tt.update('<table style="background-color:#008000; color:#ffff00;" border="0" width="100%"><tr><td>Online</td><td width="16"><img width="16px" src="/style/assets/green_2.gif"></td></tr></table>');
break;
};
case 2:{
if( data.nodes[i].type == 3 ) cleanup2DDraw( data.nodes[i].id );
tt.update('<table style="background-color:#008000; color:#ffff00;" border="0" width="100%"><tr><td>Initializing</td><td width="16"><img width="16px" src="/style/assets/green_1.gif"></td></tr></table>');
break;
};
case 3:{
if( data.nodes[i].type == 3 ) cleanup2DDraw( data.nodes[i].id );
tt.update('<table style="background-color:#800000; color:#ffff00;" border="0" width="100%"><tr><td>Trouble</td><td width="16"><img width="16px" src="/style/assets/red_1.gif"></td></tr></table>');
break;
};
case 4:{
if( data.nodes[i].type == 3 ) cleanup2DDraw( data.nodes[i].id, data.nodes[i].targets );
tt.update('<table style="background-color:#ff0000; color:#ffff00;" border="0" width="100%"><tr><td>Alarm</td><td width="16"><img width="16px" src="/style/assets/red_2.gif"></td></tr></table>');
break;
};
};
};
};
};
};
if( data.notifications.length > 0 ){
sndExcl.play();
for( i=0; i < data.notifications.length; i++ ){
/*const not = PNotify.alert({
title: 'You Will Receive a Side',
text: 'You have no choice.',
icon: 'fas fa-info-circle',
hide: false,
closer: false,
sticker: false,
destroy: true,
modules: new Map([
...PNotify.defaultModules,
[PNotifyConfirm, {
confirm: true,
buttons: [{
text: 'Ok',
primary: true,
click: notice => notice.close()
}]
}]
])
});
*/
const l = PNotify.alert({
type: data.notifications[i].type,
text: data.notifications[i].msg,
textTrusted: true,
stack: NotificationStack,
title: data.notifications[i].action,
hide: data.notifications[i].hide,
closer: data.notifications[i].hide,
sticker: data.notifications[i].hide,
destroy: true,
modules: (data.notifications[i].react )? new Map([
...PNotify.defaultModules,
[PNotifyConfirm, {
confirm: true,
buttons: [{
text: 'Ok',
primary: true,
click: ( notice, value, evt ) => {
notice.close();
if( notice.title!='' ){
resolveDeviceMistmatch( notice.title );
};
}
}]
}]
]): null
});
/*
if( data.notifications[i].react ){
l.on('click', (notice, value) => {
notice.close();
resolveDeviceMistmatch( notice.title );
});
};
*/
lastNotificationID = data.notifications[i].id;
};
};
},
failure: failureAJAXFunction
});
};
function loadDashBoard(){
if( tlInterval!= null ){
window.clearInterval( tlInterval );
tlInterval = null;
timelineObj = null;
};
setUserContent( 0 );
Ext.Ajax.request({
url: '/lib/controller/getDashBoardItems.php',
params: {
SITE: <?=$SiteID;?>,
UID: <?=$UserID;?>,
SID: '<?=$Session;?>'
},
success: function( response, opts ){
var data = Ext.decode(response.responseText);
Ext.getCmp('main_content').setTitle( '<?=$Labels->GetLabel('_SYS_DASHBOARD_');?>' );
var tPanel = Ext.getCmp('main_portal');
tPanel.removeAll(true);
nodeDashboardStatuses = new Array();
for( i=0; i < data.length; i++) tPanel.add( data[i] );
tPanel.doLayout();
$('img[data-enlargeable]').addClass('img-enlargeable').click(function() {
var src = $(this).attr('src');
var modal;
function removeModal() {
modal.remove();
$('body').off('keyup.modal-close');
}
modal = $('<div>').css({
background: 'RGBA(0,0,0,.5) url(' + src + ') no-repeat center',
backgroundSize: 'contain',
width: '100%',
height: '100%',
position: 'fixed',
zIndex: '10000',
top: '0',
left: '0',
cursor: 'zoom-out'
}).click(function() {
removeModal();
}).appendTo('body');
//handling ESC
$('body').on('keyup.modal-close', function(e) {
if (e.key === 'Escape') {
removeModal();
}
});
});
tlInterval = window.setInterval( fetchSiteStatus, 333, selectedSite );
},
failure: failureAJAXFunction
});
};
function showServerToolBox( ServerNodeId ){
currentNodeID = ServerNodeId;
if( serverToolBox == null ){
serverToolBox = new Ext.Window({
title: '<?=$Labels->GetLabel('_SERV_CTLPANEL_SHRT_');?>',
modal: true,
width: 400,
height: 328,
closeAction: 'hide',
items:[{
xtype: 'button',
text: 'Restart',
width: '100%',
textAlign: 'left',
iconCls: 'server_btn_restart',
scale: 'large',
iconAlign: 'left',
handler: function(){
doDeviceOperation( currentNodeID, 250,'', true );
}
},{
xtype: 'button',
text: 'Initialize Hardware',
width: '100%',
textAlign: 'left',
iconCls: 'server_btn_hwinit',
scale: 'large',
iconAlign: 'left',
handler: function(){
doDeviceOperation( currentNodeID, 251,'', true );
}
},{
xtype: 'button',
text: 'Sync Time With Browser',
width: '100%',
textAlign: 'left',
iconCls: 'server_btn_timeinit',
scale: 'large',
iconAlign: 'left',
handler: function(){
doDeviceOperation( currentNodeID, 252, ((new Date())/1000), true );
}
}]
});
};
serverToolBox.show();
};
var detectionProfileWindow = null;
var deviceCtrlNode = '';
function showSensorToolBox( NodeID ){
currentNodeID = NodeID;
deviceCtrlNode = NodeID + ':0';
if( detectionProfileWindow == null ){
detectionProfileWindow = new Ext.Window({
title: '<?=$Labels->GetLabel('_DEV_CTLPANEL_SHRT_');?>',
modal: true,
width: 340,
height: 328,
autoScroll: 'auto',
closeAction: 'hide',
resizable: false,
items:[{
xtype: 'panel',
title: '<?=$Labels->GetLabel('_SPEC_FUNCTI_');?>',
height: 95,
id: 'sf_panel',
frame: true,
flex: 1,
layout: 'vbox',
hidden: true,
items:[{
xtype: 'button',
text: 'Resolve Trouble',
width: '100%',
iconCls: 'ctrl_panel_cog',
scale: 'large',
iconAlign: 'left',
handler: function(){
detectionProfileWindow.hide();
resolveDeviceMistmatch( deviceCtrlNode );
}
}]
},{
xtype: 'panel',
title: '<?=$Labels->GetLabel('_DET_GENWORKS_');?>',
height: 193,
frame: true,
flex: 1,
layout: 'vbox',
items:[{
xtype: 'button',
width: '100%',
text: 'Clear Alarm',
scale: 'large',
iconCls: 'ctrl_panel_clean',
iconAlign: 'left',
handler: function(){
clearDeviceEvents( deviceCtrlNode );
}
},{
xtype: 'button',
width: '100%',
text: 'Draw Background',
scale: 'large',
iconCls: 'ctrl_panel_drawscan',
iconAlign: 'left',
handler: function(){
doDeviceOperation( deviceCtrlNode, 3 );
}
},{
xtype: 'button',
width: '100%',
text: 'Force Study Background',
scale: 'large',
iconCls: 'ctrl_panel_study',
iconAlign: 'left',
handler: function(){
doDeviceOperation( deviceCtrlNode, 2 );
}
},{
xtype: 'button',
width: '100%',
buttonAlign: 'left',
//text: '<table width="100%" border=1><tr><td style="text-align:left">Button 1</td></tr></table>',
text: 'Force Reset Sensor',
scale: 'large',
iconCls: 'ctrl_panel_reset',
iconAlign: 'left',
handler: function(){
doDeviceOperation( deviceCtrlNode, 1 );
}
}]
},{
xtype: 'panel',
title: 'Zone Masking Management',
height: 140,
frame: true,
flex: 1,
layout: 'vbox',
items:[{
xtype: 'button',
text: 'Mask Editor',
id: 'DMED',
width: '100%',
handler: function(){
showMaskEditor( true, 0, deviceCtrlNode );
}
},{
xtype: 'spacer',
height: 6
},{
xtype: 'panel',
frame: false,
border: false,
flex: 1,
width: '100%',
height: 40,
layout: 'hbox',
items:[{
xtype: 'button',
enableToggle: true,
width: '20%',
scale: 'large',
id: 'mz_btn_0',
iconCls: 'mask_zone1_btn',
iconAlign: 'top',
pressed: false,
disabled: true,
handler: function(){
Ext.getCmp('MAPPLY').enable();
}
},{
xtype: 'button',
enableToggle: true,
width: '20%',
scale: 'large',
id: 'mz_btn_1',
iconCls: 'mask_zone2_btn',
iconAlign: 'top',
pressed: false,
disabled: true,
handler: function(){
Ext.getCmp('MAPPLY').enable();
}
},{
xtype: 'button',
enableToggle: true,
width: '20%',
scale: 'large',
id: 'mz_btn_2',
iconCls: 'mask_zone3_btn',
iconAlign: 'top',
pressed: false,
disabled: true,
handler: function(){
Ext.getCmp('MAPPLY').enable();
}
},{
xtype: 'button',
enableToggle: true,
width: '20%',
scale: 'large',
id: 'mz_btn_3',
iconCls: 'mask_zone4_btn',
iconAlign: 'top',
pressed: false,
disabled: true,
handler: function(){
Ext.getCmp('MAPPLY').enable();
}
},{
xtype: 'button',
enableToggle: true,
width: '20%',
scale: 'large',
id: 'mz_btn_4',
iconCls: 'mask_zone5_btn',
iconAlign: 'top',
pressed: false,
disabled: true,
handler: function(){
Ext.getCmp('MAPPLY').enable();
}
}]
},{
xtype: 'spacer',
height: 6
},{
xtype: 'button',
text: 'Apply Zone Masks',
id: 'MAPPLY',
disabled: true,
width: '100%',
handler: function(){
}
}]
},{
xtype: 'panel',
title: '<?=$Labels->GetLabel('_DET_SENSITIVITY_');?>',
height: 95,
frame: true,
flex: 1,
layout: 'hbox',
items:[<?php
if( $CUser->Data['access']>4 ){
?>{
xtype: 'button',
text: 'Factory',
id: 'DDSPBTN0',
width: 80,
iconCls: 'detection_btn_factory',
enableToggle: true,
toggleGroup: 'det_sens_btn_grp',
disabled: true,
scale: 'large',
iconAlign: 'top'
},<?php
};
?>{
xtype: 'button',
text: 'Low',
id: 'DDSPBTN1',
width: 80,
iconCls: 'detection_btn_low',
enableToggle: true,
toggleGroup: 'det_sens_btn_grp',
disabled: true,
scale: 'large',
iconAlign: 'top'
},{
xtype: 'button',
text: 'Meduim',
id: 'DDSPBTN2',
width: 80,
iconCls: 'detection_btn_medium',
enableToggle: true,
toggleGroup: 'det_sens_btn_grp',
disabled: true,
scale: 'large',
iconAlign: 'top'
},{
xtype: 'button',
text: 'High',
id: 'DDSPBTN3',
width: 80,
iconCls: 'detection_btn_high',
enableToggle: true,
toggleGroup: 'det_sens_btn_grp',
disabled: true,
scale: 'large',
iconAlign: 'top'
}]
}]
});
};
detectionProfileWindow.show();
var myMask = new Ext.LoadMask( detectionProfileWindow.getEl(), {msg:"Please wait..."});
myMask.show();
Ext.Ajax.request({
url: '/lib/controller/getDetectionProfile.php',
params: {
SITE: SelectedSite,
UID: <?=$UserID;?>,
SID: '<?=$Session;?>',
NID: NodeID
},
success: function( response, opts ){
var data = Ext.decode( response.responseText );
myMask.hide();
detectionProfileWindow.setTitle( '['+data.name + '] <?=$Labels->GetLabel('_DEV_CTLPANEL_SHRT_');?>');
if(data.masks_array != 'undefined' ){
for( i = 0; i < 5; i++ ){
var cE = Ext.getCmp('mz_btn_'+i );
if( data.masks_array[i]=='E'){
cE.enable();
cE.toggle( true, true );
} else {
cE.toggle( false, true );
if( data.masks_array[i]=='D' ){
cE.enable();
} else {
cE.disable();
};
};
};
};
if( data.data_status == 3 ){
if( data.profiles.length > 1 ){
for( i=0; i < data.profiles.length; i++ ){
Ext.getCmp('DDSPBTN'+i ).enable();
if( i == data.profile_id ) Ext.getCmp('DDSPBTN'+i ).toggle( true, false );
};
} else {
Ext.getCmp('DDSPBTN0').toggle( true, false );
Ext.getCmp('DDSPBTN0').disable();
};
} else if( data.data_status == 4 ){
Ext.getCmp('sf_panel').show();
};
detectionProfileWindow.doLayout();
},
failure: failureAJAXFunction
});
};