added angular filters for classes

This commit is contained in:
Marian Oancea
2015-01-29 18:50:16 +02:00
parent 5114d05c32
commit 3dd2e34371
5 changed files with 43 additions and 60 deletions

View File

@@ -1,3 +1,3 @@
'use strict';
var app = angular.module('netStatsApp', ['underscore', 'angularMoment', 'netStatsApp.directives']);
var app = angular.module('netStatsApp', ['underscore', 'angularMoment', 'netStatsApp.filters', 'netStatsApp.directives']);

View File

@@ -9,9 +9,21 @@ function StatsCtrl($scope, socket, _) {
socket.on('init', function(data){
$scope.nodes = data.nodes;
updateStats();
});
socket.on('update', function(data){
$scope.nodes[data.node.id] = data.node;
updateStats();
});
function updateStats()
{
$scope.nodesTotal = $scope.nodes.length;
$scope.nodesActive = _.filter($scope.nodes, function(node){ return node.stats.active == true; }).length;
$scope.bestBlock = _.max($scope.nodes, function(node){ return parseInt(node.stats.block.height); }).stats.block.height;
$scope.lastBlock = _.max($scope.nodes, function(node){ return parseInt(node.stats.block.timestamp); }).stats.block.timestamp;
});
}
}

View File

@@ -2,8 +2,24 @@
/* Filters */
// angular.module('netStatsApp').filter('fromNow', function() {
// return function(time) {
// return moment.unix(time).fromNow();
// }
// });
angular.module('netStatsApp.filters', [])
.filter('peerClass', function() {
return function(peers) {
return (peers <= 1 ? 'text-danger' : (peers > 1 && peers < 4 ? 'text-warning' : 'text-success'));
}
})
.filter('miningClass', function() {
return function(mining) {
return (! mining ? 'text-danger' : '');
}
})
.filter('miningIconClass', function() {
return function(mining) {
return (! mining ? 'icon-cancel' : 'icon-check');
}
})
.filter('blockClass', function() {
return function(current, best) {
return (best - current <= 1 ? '' : (best - current > 1 && best - current < 4 ? 'text-warning' : 'text-danger'));
}
});