// 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: 308, maxHeight: 308 }; var tlLoadLocker = false; var tlLastTS = 0; var tlInterval = null; var tlMonitoring = false; function loadTimeLineGroups( NID ){ Ext.Ajax.request({ url: '/lib/controller/getTimeLineGroups.php', params: { NID: NID, UID: =$UserID;?>, SID: '=$Session;?>' }, 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, 333, 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: =$UserID;?>, SID: '=$Session;?>', 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 ); timelineObj.on('select', function (properties) { logEvent('select', properties); }); } else { timelineObj.redraw(); }; if( tlMonitoring ) timelineObj.moveTo( moment.utc() ); 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 loadTimeLine(){ var tPanel = Ext.getCmp('main_content'); tPanel.remove(0); tPanel.add({ title: 'Events Monitoring', frame: false, border: false, layout: 'vbox', layoutConfig: { align : 'stretch', pack : 'start', }, //height: 700, //flex: 1, //border: true, items:[{ //title: 'TimeLine', height: 350, flex: 1, frame: true, border: false, layout: 'fit', items:{ style: 'background: ivory;', html: '
' }, tbar:[{ id: 'fev', text: 'Fit Events', disabled: tlMonitoring, handler: function(){ timelineObj.fit(); } },{ id: 'gtn', text: 'Go to Now', disabled: tlMonitoring, handler: function(){ timelineObj.moveTo( moment.utc() ); } },{ text: 'Live Monitoring', enableToggle: true, pressed: tlMonitoring, toggleHandler: function(){ tlMonitoring = !tlMonitoring; if( tlMonitoring ){ Ext.getCmp('gtn').disable(); Ext.getCmp('fev').disable(); } else { Ext.getCmp('gtn').enable(); Ext.getCmp('fev').enable(); }; } }] },{ 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(); };