// var now = moment.utc().minutes(0).seconds(0).milliseconds(0); //alert( now ); var netwodkData = { edges: null, nodes: null }; var networkObj = null; var selectedSite = 0; var selectedConnection = null; var selectedNode = null; var timelineObj = null; var tlGroups = new vis.DataSet(); var tlItems = new vis.DataSet(); var tlOptions = { groupOrder: 'content', // groupOrder can be a property name or a sorting function stack: true, showCurrentTime: true, verticalScroll: true, zoomKey: 'ctrlKey', minHeight: 300, maxHeight: 300 }; var tlLoadLocker = false; var tlLastTS = 0; var tlInterval = null; function loadTimeLineGroups( NID ){ Ext.Ajax.request({ url: '/lib/controller/getTimeLineGroups.php', params: { NID: NID, UID: , SID: '' }, success: function( response, opts ){ // If the response is JSON, you have to decode it var data = Ext.decode(response.responseText); //for(var i = 0; i < data.length; i++) { //tlGroups.add(data[i]); //}; tlGroups.update( data ); loadTimeLineItems( selectedSite ); tlInterval = window.setInterval( loadTimeLineItems, 100, selectedSite ); }, failure: function( response, opts ) { //Ext.fly('some_div').update('Fail!'); }/*, callback: function(options,success,response){ // use this if you need to perform your own success/failure checking }*/ }); }; function loadTimeLineItems( NID ){ if( tlLoadLocker ) return; tlLoadLocker = true; Ext.Ajax.request({ url: '/lib/controller/getTimeLineEvents.php', params: { NID: NID, UID: , SID: '', LTS: tlLastTS }, success: function( response, opts ){ // If the response is JSON, you have to decode it var data = Ext.decode(response.responseText); var i = 0; for(; i < data.length; i++ ){ tlLastTS = data[i].start; data[i].start = moment.utc( ''+data[i].start, 'X' ); tlItems.add( data[i] ); }; if( timelineObj == null ){ //alert('Now'); var container = document.getElementById('timeline'); timelineObj = new vis.Timeline( container ); timelineObj.setOptions( tlOptions ); timelineObj.setGroups( tlGroups ); timelineObj.setItems( tlItems ); } else { timelineObj.redraw(); }; tlLoadLocker = false; }, failure: function( response, opts ) { //Ext.fly('some_div').update('Fail!'); tlLoadLocker = false; }/*, callback: function(options,success,response){ // use this if you need to perform your own success/failure checking }*/ }); }; function reloadNetworkData( NID ){ Ext.Ajax.request({ url: '/lib/controller/getNetwork.php', params: { NID: NID, UID: , SID: '', }, success: function( response, opts ){ // If the response is JSON, you have to decode it var data = Ext.decode(response.responseText); netwodkData.nodes = new vis.DataSet( data.nodes ); netwodkData.edges = new vis.DataSet( data.edges ); networkObj.setData( netwodkData ); networkObj.redraw(); }, failure: function( response, opts ) { //Ext.fly('some_div').update('Fail!'); }/*, callback: function(options,success,response){ // use this if you need to perform your own success/failure checking }*/ }); }; function createNode( NID, STYPE ){ Ext.Ajax.request({ url: '/lib/controller/addNetworkNode.php', params: { NID: NID, UID: , SID: '', TYPE: STYPE }, success: function( response, opts ){ // If the response is JSON, you have to decode it reloadNetworkData( NID ); }, failure: function( response, opts ) { //Ext.fly('some_div').update('Fail!'); }/*, callback: function(options,success,response){ // use this if you need to perform your own success/failure checking }*/ }); }; var currentConnectonMode = 0; function createConnection( NID, SID, EID, CTY ){ Ext.Ajax.request({ url: '/lib/controller/addConnection.php', params: { NID: NID, SNID: SID, ENID: EID, UID: , SID: '', TYPE: CTY }, success: function( response, opts ){ var data = Ext.decode(response.responseText); if( data.status ){ //reloadNetworkData( NID ); netwodkData.edges.add( data.edge ); } else { alert( data.message ); }; }, failure: function( response, opts ) { //Ext.fly('some_div').update('Fail!'); }/*, callback: function(options,success,response){ // use this if you need to perform your own success/failure checking }*/ }); }; var networkOpts = { interaction:{ hover: true }, manipulation: { enabled: false, addNode: function (data, callback) { // filling in the popup DOM elements console.log('add', data); }, editNode: function (data, callback) { // filling in the popup DOM elements console.log('edit', data); }, addEdge: function (data, callback) { console.log('add edge', data); if (data.from == data.to) { var r = confirm("Do you want to connect the node to itself?"); if (r === true) { //callback(data); createConnection( selectedSite, data.from, data.to, currentConnectonMode ); }; } else { //callback(data); createConnection( selectedSite, data.from, data.to, currentConnectonMode ); }; networkObj.disableEditMode(); } } }; function startCreateConnection( CType ){ if( networkObj!= null ){ currentConnectonMode = CType; networkObj.addEdgeMode(); }; }; function finishCreateConnection(){ if( networkObj!= null ){ }; //connectionAddMode = false; }; function loadDashBoard(){ var tPanel = Ext.getCmp('main_content'); if( tlInterval!= null ){ window.clearInterval( tlInterval ); tlInterval = null; timelineObj = null; }; tPanel.remove(0); tPanel.add({ html: 'DashBoard Content' }); tPanel.doLayout(); }; function loadTimeLine(){ var tPanel = Ext.getCmp('main_content'); tPanel.remove(0); tPanel.add({ title: 'Events Monitoring', frame: false, border: false, //layout: 'fit', //height: 700, //flex: 1, //border: true, items:[{ title: 'TimeLine', height: 350, flex: 1, frame: true, border: false, layout: 'fit', items:{ style: 'background: ivory;', html: '
' } },{ title: 'Event Information', frame: true, html: '

Select an Event from TimeLine to See Information' }] }); tPanel.doLayout(); loadTimeLineGroups( selectedSite ); }; function loadOnlineMonitoring(devID){ var tPanel = Ext.getCmp('main_content'); if( tlInterval!= null ){ window.clearInterval( tlInterval ); tlInterval = null; timelineObj = null; }; tPanel.remove(0); tPanel.add({ html: 'Device Monitoring '+devID }); tPanel.doLayout(); }; function loadNodeProperties( NodeID ){ //alert( 'Node: ' + NodeID ); Ext.Ajax.request({ url: '/lib/controller/getNetworkNodeProps.php', params: { NID: selectedSite, UID: , SID: '', NODE: NodeID }, success: function( response, opts ){ // If the response is JSON, you have to decode it var data = Ext.decode(response.responseText); var tPanel = Ext.getCmp('prop_content'); tPanel.remove(0); tPanel.add( data ); tPanel.doLayout(); }, failure: function( response, opts ) { //Ext.fly('some_div').update('Fail!'); }/*, callback: function(options,success,response){ // use this if you need to perform your own success/failure checking }*/ }); }; function loadLinkProperties( EdgeID, From, To ){ alert( 'Edge: ' + EdgeID ); }; function loadSystemEditor(){ var tPanel = Ext.getCmp('main_content'); if( tlInterval!= null ){ window.clearInterval( tlInterval ); tlInterval = null; timelineObj = null; }; tPanel.remove(0); tPanel.add({ title: 'System Map', // id: 'sys_map', frame: false, border: false, //layout: 'column', // Specifies that the items will now be arranged in columns layout:'hbox', layoutConfig: { align : 'stretch', pack : 'start', //padding:'5', //align:'middle' }, items: [{ //columnWidth: 0.60, layout: 'fit', //height: 700, flex: 1, border: true, items:{ id: 'sys_map' } },{ title: 'Properties', flex: 1, width: 210, layout: 'fit', frame: true, id: 'prop_content', // border: true items:{ html: 'Select Item From Map' } }], tbar: [{ xtype: 'splitbutton', text: 'Add Laser Sensor', split: true, enableToggle : undefined, menu : { items: [{ text:'ALS', handler: function(){ createNode( 0, 1 ); } },{ text:'LFS', handler: function(){ createNode( 0, 2 ); } },{ text:'PLS-200', handler: function(){ createNode( 0, 3 ); } },{ text:'PLS-360', handler: function(){ createNode( 0, 4 ); } },{ text:'3DLIDAR', handler: function(){ createNode( 0, 5 ); } }] } },{ xtype: 'splitbutton', text: 'Add Additional Equipment', split: true, enableToggle : undefined, menu : { items: [{ text:'Static Analog Camera' },{ text:'PTZ Analog Camera' },{ text:'Static IP Camera' },{ text:'PTZ IP Camera' },{ text:'DVR/Video Server/Streamer' },{ text:'Network Video Recorder' },{ text:'Ethernet to UART transeiver' },{ text:'DC to Ethernet (ADAM)' }] } },{ xtype: 'splitbutton', text: 'Add Connection', split: true, enableToggle : undefined, menu : { items: [{ text:'COM_TYPE_RS485_CTRL', handler: function(){ startCreateConnection(1); } },{ text:'COM_TYPE_RS422_CTRL', handler: function(){ startCreateConnection(2); } },{ text:'COM_TYPE_RS232_CTRL', handler: function(){ startCreateConnection(3); } },{ text:'COM_TYPE_TCP_CTRL', handler: function(){ startCreateConnection(4); } },{ text:'COM_TYPE_RS485_PTZ', handler: function(){ startCreateConnection(5); } },{ text:'COM_TYPE_RS422_PTZ', handler: function(){ startCreateConnection(6); } },{ text:'COM_TYPE_RS232_PTZ', handler: function(){ startCreateConnection(7); } },{ text:'COM_TYPE_TCP_PTZ', handler: function(){ startCreateConnection(8); } },{ text:'COM_TYPE_ANALOG_VIDEO', handler: function(){ startCreateConnection(9); } },{ text:'COM_TYPE_ANALOG_AUDIO', handler: function(){ startCreateConnection(10); } },{ text:'COM_TYPE_DC_ALARM_NC', handler: function(){ startCreateConnection(11); } },{ text:'COM_TYPE_DC_ALARM_NO', handler: function(){ startCreateConnection(12); } }] } }] }); tPanel.doLayout(); Ext.Ajax.request({ url: '/lib/controller/getNetwork.php', params: { NID: selectedSite, UID: , SID: '' }, success: function( response, opts ){ // If the response is JSON, you have to decode it var data = Ext.decode(response.responseText); netwodkData.nodes = new vis.DataSet( data.nodes ); netwodkData.edges = new vis.DataSet( data.edges ); var container = document.getElementById(Ext.getCmp('sys_map').body.id); networkObj = new vis.Network(container, netwodkData, networkOpts ); networkObj.on("click", function (params) { //if(!connectionAddMode){ if( params.nodes.length > 0 ){ loadNodeProperties( params.nodes[0] ); } else if( params.edges.length > 0 ){ selectedConnection = netwodkData.edges.get(params.edges[0]); loadLinkProperties( params.edges[0], selectedConnection.from, selectedConnection.to ); }; //}; }); networkObj.on("doubleClick", function (params) { //if(!connectionAddMode){ if( params.nodes.length > 0 ){ loadNodeProperties( params.nodes[0] ); } else if( params.edges.length > 0 ){ selectedConnection = netwodkData.edges.get(params.edges[0]); loadLinkProperties( params.edges[0], selectedConnection.from, selectedConnection.to ); }; //}; }); /* networkObj.on("dragStart", function (params) { if( connectionAddMode ){ var tID = this.getNodeAt(params.pointer.DOM); if( tID != undefined ){ newConnectionStart = tID; }; }; }); networkObj.on("dragEnd", function (params) { if( connectionAddMode ){ var tID = this.getNodeAt(params.pointer.DOM); if( tID != undefined ){ newConnectionEnd = tID; //selectedConnection = netwodkData.edges[netwodkData.edges.length]; //selectedConnection.color = { // color: '#ff0000', // opacity: 0.3, // highlight: 'blue' //}; //networkObj.addEdgeMode(0); createConnection( newConnectionStart, newConnectionEnd ); connectionAddMode = false; }; }; }); */ }, failure: function( response, opts ) { //Ext.fly('some_div').update('Fail!'); }/*, callback: function(options,success,response){ // use this if you need to perform your own success/failure checking }*/ }); }; //http://visjs.org/index.html Ext.onReady(function(){ var viewport = new Ext.Viewport({ layout:'border', items: [{ xtype: 'panel', region: 'north', baseCls: 'x-plain', height: 50, items:[{ xtype: 'panel', id:'top', baseCls: 'x-plain', html: '

R-Goose Security System

' }] },{ xtype: 'panel', id:'btns', region:'west', baseCls:'x-plain', split:true, width:150, minWidth: 100, maxWidth: 250, layout:'fit', margins: '5 0 5 5', items: [{ xtype: 'panel', //baseCls: 'x-plain', height: 400, title: 'R-Goose System', layout:'accordion', defaults: { // applied to each contained panel bodyStyle: 'padding:5px' }, layoutConfig: { // layout-specific configs go here titleCollapse: false, animate: true//, //activeOnTop: true }, items: [{ title: 'Dashboard', layout: 'vbox', height: 120, pack: 'center', align : 'strech', items:[{ xtype: 'button', width: '100%', id:'go_home', text: 'Go Home', handler: function( b, e ){ loadDashBoard(); } },{ xtype: 'button', width: '100%', id:'go_monitor', text: 'Monitor Events', handler: function( b, e ){ loadTimeLine(); } },{ xtype: 'button', width: '100%', id:'go_out', text: 'Logout', handler: function( b, e ){ window.location = '/login.php?UID=1'; } }] },{ title: 'System Settings', layout: 'vbox', height: 120, pack: 'center', align : 'strech', items:[{ xtype: 'button', width: '100%', id:'sys_edit', text: 'Edit System', handler: function( b, e ){ loadSystemEditor(); } },{ xtype: 'button', width: '100%', id:'logout', text: 'Logout', handler: function( b, e ){ window.location = '/login.php?UID=1'; } }] },{ title: 'Profile Settings', html: '

Panel content!

' }] }] },{ region:'center', margins: '5 5 5 0', id: 'main_content', layout: 'fit', items:[{ xtype: 'panel', html: '

' }] }] }); loadDashBoard(); });