1
0
Fork 0

updated dashboard

This commit is contained in:
Heiko Kernbach 2013-05-10 17:30:49 +02:00
parent 775d777267
commit 03893bf9cd
2 changed files with 108 additions and 57 deletions

View File

@ -11,9 +11,10 @@
<button data-toggle="dropdown" class="btn btn-inverse btn-small dropdown-toggle"><span class="caret"></span></button> <button data-toggle="dropdown" class="btn btn-inverse btn-small dropdown-toggle"><span class="caret"></span></button>
<ul class="dropdown-menu dashboard-dropdown"> <ul class="dropdown-menu dashboard-dropdown">
<li class="nav-header system-entry">Process</li> <li class="nav-header system-entry">Process Statistics</li>
<li class="divider"></li> <li class="divider" id="firstDashDivider"></li>
<li class="nav-header client-entry">Client</li> <li class="nav-header client-entry">Client Statistics</li>
<li class="divider" id="lastDashDivider"></li>
</ul> </ul>
</div> </div>
<!-- /btn-group --> <!-- /btn-group -->

View File

@ -1,6 +1,7 @@
var dashboardView = Backbone.View.extend({ var dashboardView = Backbone.View.extend({
el: '#content', el: '#content',
updateInterval: 5000, updateInterval: 5000,
counterInterval: 0,
arraySize: 100, arraySize: 100,
clients: [], clients: [],
systems: [], systems: [],
@ -12,16 +13,46 @@ var dashboardView = Backbone.View.extend({
this.collection.fetch({ this.collection.fetch({
success: function() { success: function() {
var toCheck;
self.renderCharts("system"); self.renderCharts("system");
self.renderCharts("client"); self.renderCharts("client");
window.setInterval(function() { window.setInterval(function() {
self.collection.fetch({ var toCheck = false;
success: function() {
self.updateSystems(); self.counterInterval++;
self.updateCharts("system"); if (self.updateInterval === 5000 && self.counterInterval === 1) {
self.updateCharts("client"); toCheck = true;
} self.counterInterval = 0;
}); }
else if (self.updateInterval === 15000 && self.counterInterval === 3) {
toCheck = true;
self.counterInterval = 0;
}
else if (self.updateInterval === 30000 && self.counterInterval === 6) {
toCheck = true;
self.counterInterval = 0;
}
else if (self.updateInterval === 60000 && self.counterInterval === 12) {
toCheck = true;
self.counterInterval = 0;
}
else if (self.updateInterval === 120000 && self.counterInterval === 24) {
toCheck = true;
self.counterInterval = 0;
}
else {
return false;
}
if (toCheck === true) {
self.collection.fetch({
success: function() {
self.updateSystems();
self.updateCharts("system");
self.updateCharts("client");
}
});
}
}, self.updateInterval); }, self.updateInterval);
} }
}); });
@ -71,8 +102,8 @@ var dashboardView = Backbone.View.extend({
}, },
checkInterval: function (a) { checkInterval: function (a) {
var self = this; var self = this;
console.log(self.updateInterval);
self.updateInterval = a.target.value * 1000; self.updateInterval = a.target.value * 1000;
}, },
checkEnabled: function (a) { checkEnabled: function (a) {
var myId = a.target.id; var myId = a.target.id;
@ -110,7 +141,12 @@ var dashboardView = Backbone.View.extend({
$.each(self.options.description.models[0].attributes.figures, function(k,v) { $.each(self.options.description.models[0].attributes.figures, function(k,v) {
if (v.identifier === client) { if (v.identifier === client) {
label = v.units; if (v.units === 'bytes') {
label = 'megabyte';
}
else {
label = v.units;
}
} }
}); });
@ -168,7 +204,12 @@ var dashboardView = Backbone.View.extend({
.axisLabel("") .axisLabel("")
$.each(self.options.description.models[0].attributes.figures, function(k,v) { $.each(self.options.description.models[0].attributes.figures, function(k,v) {
if (v.identifier === client) { if (v.identifier === client) {
label = v.units; if (v.units === 'bytes') {
label = 'megabyte';
}
else {
label = v.units;
}
} }
}); });
@ -236,35 +277,44 @@ var dashboardView = Backbone.View.extend({
var timeStamp = Math.round(+new Date()/1000); var timeStamp = Math.round(+new Date()/1000);
var myType;
//FIX FIX TODO $.each(self.options.description.models[0].attributes.figures, function(k,v) {
var myType; if (v.identifier === tempName) {
$.each(self.options.description.models[0].attributes.figures, function(k,v) { myType = v.type;
if (v.identifier === tempName) { if (v.units === 'bytes') {
myType = v.type; console.log(val);
if (val.sum === undefined) {
val = val / 1024 / 1024;
val = Math.round(val*100)/100;
}
else {
val.sum = val.sum / 1024 / 1024;
val.sum = Math.round(val.sum*100)/100;
}
} }
}); }
});
if (myType === "current") { if (myType === "current") {
tempArray.push({x:timeStamp, y:val}); tempArray.push({x:timeStamp, y:val});
return; return;
}
else {
if (val.sum === undefined) {
var calculatedSum = val - self.oldSum[tempName];
//Round value
calculatedSum = Math.round(calculatedSum*100)/100;
self.oldSum[tempName] = val;
tempArray.push({x:timeStamp, y:calculatedSum});
} }
else { else {
if (val.sum === undefined) { var calculatedSum = val.sum - self.oldSum[tempName];
var calculatedSum = val - self.oldSum[tempName]; //Round value
//Round value calculatedSum = Math.round(calculatedSum*100)/100;
calculatedSum = Math.round(calculatedSum*100)/100; self.oldSum[tempName] = val.sum;
self.oldSum[tempName] = val; tempArray.push({x:timeStamp, y:calculatedSum});
tempArray.push({x:timeStamp, y:calculatedSum});
}
else {
var calculatedSum = val.sum - self.oldSum[tempName];
//Round value
calculatedSum = Math.round(calculatedSum*100)/100;
self.oldSum[tempName] = val.sum;
tempArray.push({x:timeStamp, y:calculatedSum});
}
} }
}
} }
}); });
}, },
@ -289,7 +339,7 @@ var dashboardView = Backbone.View.extend({
'<div class="statChart" id="'+identifier+'Chart"><svg class="svgClass"/></div>' + '<div class="statChart" id="'+identifier+'Chart"><svg class="svgClass"/></div>' +
'</li>' '</li>'
); );
$('.client-entry').after( $('#lastDashDivider').before(
'<li><a><label class="checkbox">'+ '<li><a><label class="checkbox">'+
'<input type="checkbox" id='+identifier+'Checkbox checked>'+name+'</label></a></li>' '<input type="checkbox" id='+identifier+'Checkbox checked>'+name+'</label></a></li>'
); );
@ -301,31 +351,31 @@ var dashboardView = Backbone.View.extend({
'<div class="statChart" id="'+identifier+'Chart"><svg class="svgClass"/></div>' + '<div class="statChart" id="'+identifier+'Chart"><svg class="svgClass"/></div>' +
'</li>' '</li>'
); );
$('.system-entry').after( $('#firstDashDivider').before(
'<li><a><label class="checkbox">'+ '<li><a><label class="checkbox">'+
'<input type="checkbox" id='+identifier+'Checkbox checked>'+name+'</label></a></li>' '<input type="checkbox" id='+identifier+'Checkbox checked>'+name+'</label></a></li>'
); );
}, },
/* /*
renderSystem: function (identifier, name, desc, type, units) { renderSystem: function (identifier, name, desc, type, units) {
$('#system').append( $('#system').append(
'<div class="statSystem" id="'+identifier+'">' + '<div class="statSystem" id="'+identifier+'">' +
'<table><tr>' + '<table><tr>' +
'<th>'+ name +'</th>' + '<th>'+ name +'</th>' +
'<th class="updateValue">'+ 'counting...' +'</th>' + '<th class="updateValue">'+ 'counting...' +'</th>' +
'</tr></table>' + '</tr></table>' +
'</div>' '</div>'
); );
}, },
*/ */
updateClient: function (identifier, count, counts) { updateClient: function (identifier, count, counts) {
}, },
updateSystems: function () { updateSystems: function () {
$.each(this.collection.models[0].attributes.system, function(key, val) { $.each(this.collection.models[0].attributes.system, function(key, val) {
$('#'+key+' .updateValue').html(val); $('#'+key+' .updateValue').html(val);
}); });
} }
}); });