added angular filters for classes
This commit is contained in:
@@ -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']);
|
||||
@@ -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;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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'));
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user