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

@ -38,7 +38,7 @@ Node.prototype.update = function()
}
if(this.info.stats.peers != null) {
this.info.stats.block.height = eth.number;
this.info.stats.block.height = parseInt(eth.number);
var block = eth.block(this.info.stats.block.height)
this.info.stats.block.hash = block.hash;
this.info.stats.block.timestamp = block.timestamp;

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'));
}
});

View File

@ -52,8 +52,7 @@ block content
div.clearfix
div.col-sm-12
h1= title
p Welcome to #{title}
h1 Nodes in detail
table.table.table-striped
thead
@ -77,55 +76,11 @@ block content
tr(ng-repeat='node in nodes', class="{{ node.stats.active ? 'text-success' : 'text-danger' }}")
td(rel="{{node.id}}") {{node.name}}
td {{node.type}}
td {{node.stats.peers}}
td(class="{{(node.stats.mining === false) ? 'text-danger' : 'text-success'}}")
i(class="{{(node.stats.mining === false) ? 'icon-cancel' : 'icon-check'}}")
td {{'#' + node.stats.block.height}}
td.hidden-sm.hidden-xs
td(class="{{ node.stats.peers | peerClass }}") {{node.stats.peers}}
td(class="{{ node.stats.mining | miningClass }}")
i(class="{{ node.stats.mining | miningIconClass }}")
td(class="{{ node.stats.block.height | blockClass : bestBlock }}") {{'#' + node.stats.block.height}}
td(class="{{ node.stats.block.height | blockClass : bestBlock }}").hidden-sm.hidden-xs
span.small {{node.stats.block.hash}}
td(am-time-ago="node.stats.block.timestamp", am-preprocess="unix")
td 100%
//- tr.text-success
//- td poc-7.ethdev.com
//- td C++
//- td 7
//- td
//- i.icon-check
//- td #8196
//- td.hidden-sm.hidden-xs
//- span.small 06d1a2c709f23678e716ae8bea400161815a37a16aeced3a4ffed79b96f63566
//- td 16 sec
//- td 98.3%
//- tr.text-warning
//- td poc-6.ethdev.com
//- td C++
//- td 4
//- td
//- i.icon-warning-o
//- td #8186
//- td.hidden-sm.hidden-xs
//- span.small 1545f88598e54e56ec5570b08c592f8c8403e3e1c9ec0eec2f9ba619729ec85e
//- td 3 min
//- td 94.1%
//- tr.text-danger
//- td poc-5.ethdev.com
//- td C++
//- td 0
//- td
//- i.icon-cancel
//- td #3196
//- td.hidden-sm.hidden-xs
//- span.small 45f4e588bf9a03ba0d7146dd83a6a8faf00df471d7484b92d904b77014d10e01
//- td 2 days
//- td 79.4%
//- tr.text-danger
//- td poc-4.ethdev.com
//- td C++
//- td 0
//- td
//- i.icon-cancel
//- td #1196
//- td.hidden-sm.hidden-xs
//- span.small 36d6fe290d52da4518f9017fa7b5dd407007053e345463e7a6fdc905b8d9b2a3
//- td 1 mon
//- td 21.8%
td {{ node.stats.active ? '100%' : '0%' }}