From 297240b59151c39533cda52c662b91ebab59bf10 Mon Sep 17 00:00:00 2001 From: Marian Oancea Date: Thu, 5 Feb 2015 06:32:42 +0200 Subject: [PATCH] fixes to filters --- public/js/controllers.js | 1 + public/js/filters.js | 70 +++++++++++++++++++++++----------------- 2 files changed, 41 insertions(+), 30 deletions(-) diff --git a/public/js/controllers.js b/public/js/controllers.js index 237713c..4282f85 100644 --- a/public/js/controllers.js +++ b/public/js/controllers.js @@ -25,5 +25,6 @@ function StatsCtrl($scope, socket, _) { $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; + $scope.apply(); } } \ No newline at end of file diff --git a/public/js/filters.js b/public/js/filters.js index 11f0d0f..6ef51b7 100644 --- a/public/js/filters.js +++ b/public/js/filters.js @@ -20,50 +20,60 @@ angular.module('netStatsApp.filters', []) }; }) .filter('mainClass', function() { - return function(node, bestBlock) { - if( ! node.active) - return 'text-danger'; + return function(node, bestBlock) { + if( ! node.active) + return 'text-danger'; - if(node.peers === 0) - return 'text-danger'; + if(node.peers === 0) + return 'text-danger'; - return (node.peers <= 1 ? 'text-danger' : (node.peers > 1 && node.peers < 4 ? 'text-warning' : 'text-success')); - }; + return timeClass(node.block.timestamp); + }; }) .filter('peerClass', function() { - return function(peers) { - return (peers <= 1 ? 'text-danger' : (peers > 1 && peers < 4 ? 'text-warning' : 'text-success')); - }; + return function(peers) { + return peerClass(peers); + }; }) .filter('miningClass', function() { - return function(mining) { - return (! mining ? 'text-danger' : ''); - }; + return function(mining) { + return (! mining ? 'text-danger' : ''); + }; }) .filter('miningIconClass', function() { - return function(mining) { - return (! mining ? 'icon-cancel' : 'icon-check'); - }; + 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')); - }; + return function(current, best) { + return (best - current <= 1 ? '' : (best - current > 1 && best - current < 4 ? 'text-warning' : 'text-danger')); + }; }) .filter('timeClass', function() { return function(timestamp) { - var time = Math.floor((new Date()).getTime() / 1000); - var diff = time - timestamp; + return timeClass(timestamp); + }; +}); - if(diff <= 12) - return 'text-success'; +function peerClass(peers) +{ + return (peers <= 1 ? 'text-danger' : (peers > 1 && peers < 4 ? 'text-warning' : 'text-success')); +} - if(diff <= 20) - return 'text-info'; +function timeClass(timestamp) +{ + var time = Math.floor((new Date()).getTime() / 1000); + var diff = time - timestamp; - if(diff <= 30) - return 'text-warning'; + if(diff <= 12) + return 'text-success'; - return 'text-danger'; - }; -}); \ No newline at end of file + if(diff <= 20) + return 'text-info'; + + if(diff <= 30) + return 'text-warning'; + + return 'text-danger'; +} \ No newline at end of file