/*jslint indent: 2, nomen: true, maxlen: 100, sloppy: true, vars: true, white: true, plusplus: true */ /*global require, exports, Backbone, EJS, $, flush, window, arangoHelper, nv, d3, localStorage*/ var dashboardView = Backbone.View.extend({ el: '#content', updateInterval: 500, // 0.5 second, constant updateFrequency: 10, // the actual update rate (5 s) updateCounter: 0, arraySize: 20, // how many values will we keep per figure? seriesData: {}, charts: {}, units: [], graphState: {}, updateNOW: false, collectionsStats: { "corrupted": 0, "new born collection" : 0, "unloaded" : 0, "loaded" : 0, "in the process of being unloaded" : 0, "deleted" : 0 }, detailGraph: "userTime", initialize: function () { this.loadGraphState(); this.arangoReplication = new window.ArangoReplication(); var self = this; this.initUnits(); //this.addCustomCharts(); this.collection.fetch({ success: function() { self.countCollections(); self.calculateSeries(); self.renderCharts(); window.setInterval(function() { self.updateCounter++; if (self.updateNOW === true) { self.calculateSeries(); self.renderCharts(); self.updateNOW = false; } if (self.updateCounter < self.updateFrequency) { return false; } if (window.location.hash === '#dashboard') { self.getReplicationStatus(); } self.updateCounter = 0; self.collection.fetch({ success: function() { self.calculateSeries(); self.renderCharts(); }, error: function() { // need to flush previous values self.calculateSeries(true); arangoHelper.arangoError("Lost connection to database!"); self.renderCharts(); } }); }, self.updateInterval); } }); }, events: { "click #dashboardDropdown li" : "checkEnabled", "click #intervalUL li" : "checkInterval", "click .db-zoom" : "renderDetailChart", "click .db-minimize" : "checkDetailChart", "click .db-hide" : "hideChart", "click .group-close" : "hideGroup", "click .group-open" : "showGroup", "click .dashSwitch" : "showCategory", "click #dashboardToggle" : "toggleEvent" }, template: new EJS({url: 'js/templates/dashboardView.ejs'}), toggleEvent: function () { $('#dashboardDropdownOut').slideToggle(200); }, countCollections: function() { var self = this; $.each(window.arangoCollectionsStore.models, function(k,v) { if ( self.collectionsStats[this.attributes.status] === undefined ) { self.collectionsStats[this.attributes.status] = 0; } self.collectionsStats[this.attributes.status]++; }); }, getReplicationStatus: function () { this.replLogState = this.arangoReplication.getLogState(); this.replApplyState = this.arangoReplication.getApplyState(); this.putReplicationStatus(); }, putReplicationStatus: function () { var loggerRunning = this.replLogState.state.running; var applierRunning = this.replApplyState.state.running; if (applierRunning || this.replApplyState.state.lastError !== '') { $('#detailReplication').height(290); $('.checkApplyRunningStatus').show(); } else { $('.checkApplyRunningStatus').hide(); } var time = this.replLogState.state.time; var cls = loggerRunning ? 'true' : 'false'; var runningLog = '
' + cls + '
'; var clientString = '-'; if (this.replLogState.state.clients) { $.each(this.replLogState.state.clients, function(k,v) { clientString = clientString + "Server: " + v.serverId + " | Time: " + v.time + "\n"; }); } var lastLog; if (this.replLogState.state.lastLogTick === '0') { lastLog = '-'; } else { lastLog = this.replLogState.state.lastLogTick; } var numEvents = this.replLogState.state.totalEvents || 0; //log table $('#logRunningVal').html(runningLog); $('#logTotalEventsVal').text(numEvents); $('#logTimeVal').text(time); $('#logLastTickVal').text(lastLog); $('#logClientsVal').text(clientString); //apply table var lastAppliedTick = "-"; var lastAvailableTick = "-"; var progress = "-"; var lastError = "-"; var endpoint = "-"; var numRequests = "-"; var numFailed = "-"; if (this.replApplyState.state.lastAppliedContinuousTick !== null) { lastAppliedTick = this.replApplyState.state.lastAppliedContinuousTick; } if (this.replApplyState.state.lastAvailableContinuousTick !== null) { lastAvailableTick = this.replApplyState.state.lastAvailableContinuousTick; } if (this.replApplyState.state.endpoint !== undefined) { endpoint = this.replApplyState.state.endpoint; } time = this.replApplyState.state.time; if (this.replApplyState.state.progress) { progress = this.replApplyState.state.progress.message; } if (this.replApplyState.state.lastError) { lastError = this.replApplyState.state.lastError.errorMessage; } cls = applierRunning ? 'true' : 'false'; var runningApply = '
' + cls + '
'; numEvents = this.replApplyState.state.totalEvents || 0; numRequests = this.replApplyState.state.totalRequests || 0; numFailed = this.replApplyState.state.totalFailedConnects || 0; $('#applyRunningVal').html(runningApply); $('#applyEndpointVal').text(endpoint); $('#applyLastAppliedTickVal').text(lastAppliedTick); $('#applyLastAvailableTickVal').text(lastAvailableTick); $('#applyTimeVal').text(time); $('#applyProgressVal').text(progress); $('#applyTotalEventsVal').text(numEvents); $('#applyTotalRequestsVal').text(numRequests); $('#applyTotalFailedVal').text(numFailed); $('#applyLastErrorVal').text(lastError); }, render: function() { var self = this; self.updateNOW = true; $(this.el).html(this.template.text); this.getReplicationStatus(); //Client calculated charts /*self.genCustomCategories(); self.genCustomChartDescription( "userTime + systemTime", "custom", "totalTime2", "Total Time (User+System)", "accumulated", "seconds" );*/ var counter = 1; $.each(this.options.description.models[0].attributes.groups, function () { $('#dbThumbnailsIn').append( ''); //group $('#dashboardDropdown').append(''); $('#'+this.group+'Ul').append(''); /*TEST $('#menuGroups').append( '
  • ' + '
    ' + figure.name + '
    '+ '' + '' + '' + '
    ' + '
    ' + '
  • ' ); $('#' + figure.group + 'Ul').append( '
  • ' ); $('.db-info').tooltip({ placement: "top" }); } });