ethstats-server/public/js/filters.js

83 lines
1.7 KiB
JavaScript
Raw Normal View History

2015-01-20 19:29:31 +01:00
'use strict';
/* Filters */
2015-01-29 17:50:16 +01:00
angular.module('netStatsApp.filters', [])
2015-02-05 00:30:16 +01:00
.filter('nodesActiveClass', function() {
return function(active, total) {
var ratio = active/total;
if(ratio >= 0.9)
return 'text-success';
if(ratio >= 0.75)
return 'text-info';
if(ratio >= 0.5)
return 'text-warning';
return 'text-danger';
};
})
2015-01-30 22:37:38 +01:00
.filter('mainClass', function() {
2015-02-05 05:32:42 +01:00
return function(node, bestBlock) {
if( ! node.active)
return 'text-danger';
2015-01-30 22:37:38 +01:00
2015-02-05 05:32:42 +01:00
if(node.peers === 0)
return 'text-danger';
2015-01-30 22:37:38 +01:00
2015-02-05 05:32:42 +01:00
return timeClass(node.block.timestamp);
};
2015-01-30 22:37:38 +01:00
})
2015-01-29 17:50:16 +01:00
.filter('peerClass', function() {
2015-02-05 05:32:42 +01:00
return function(peers) {
return peerClass(peers);
};
2015-01-29 17:50:16 +01:00
})
.filter('miningClass', function() {
2015-02-05 05:32:42 +01:00
return function(mining) {
2015-02-05 05:59:24 +01:00
return (! mining ? 'text-danger' : 'text-success');
2015-02-05 05:32:42 +01:00
};
2015-01-29 17:50:16 +01:00
})
.filter('miningIconClass', function() {
2015-02-05 05:32:42 +01:00
return function(mining) {
return (! mining ? 'icon-cancel' : 'icon-check');
};
2015-01-29 17:50:16 +01:00
})
.filter('blockClass', function() {
2015-02-05 05:32:42 +01:00
return function(current, best) {
2015-02-05 05:59:24 +01:00
return (best - current <= 1 ? 'text-success' : (best - current > 1 && best - current < 4 ? 'text-warning' : 'text-danger'));
2015-02-05 05:32:42 +01:00
};
2015-02-05 02:33:58 +01:00
})
.filter('timeClass', function() {
return function(timestamp) {
2015-02-05 05:32:42 +01:00
return timeClass(timestamp);
};
2015-02-05 09:27:12 +01:00
}).filter('geoTooltip', function() {
return function(geo) {
return geo.city + ", " + geo.country;
};
2015-02-05 05:32:42 +01:00
});
2015-02-05 02:33:58 +01:00
2015-02-05 05:32:42 +01:00
function peerClass(peers)
{
return (peers <= 1 ? 'text-danger' : (peers > 1 && peers < 4 ? 'text-warning' : 'text-success'));
}
2015-02-05 02:33:58 +01:00
2015-02-05 05:32:42 +01:00
function timeClass(timestamp)
{
var time = Math.floor((new Date()).getTime() / 1000);
var diff = time - timestamp;
2015-02-05 02:33:58 +01:00
2015-02-05 05:32:42 +01:00
if(diff <= 12)
return 'text-success';
2015-02-05 02:33:58 +01:00
2015-02-05 05:32:42 +01:00
if(diff <= 20)
return 'text-info';
if(diff <= 30)
return 'text-warning';
return 'text-danger';
}