/*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 = '