angular improvements

This commit is contained in:
cubedro 2015-06-09 12:39:13 +03:00
parent d9ae085890
commit 4b5bdf3e3e
6 changed files with 73 additions and 35 deletions

2
dist/index.html vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -71,24 +71,22 @@ History.prototype.add = function(block, id)
if(historyBlock.hash !== block.hash || historyBlock.totalDifficulty !== block.totalDifficulty || historyBlock.transactions.length !== block.transactions.length)
{
index = _.findIndex( this._items, { height: block.number } );
this._items[index].hash = block.hash;
this._items[index].parentHash = block.parentHash;
this._items[index].nonce = block.nonce;
this._items[index].sha3Uncles = block.sha3Uncles;
this._items[index].transactionsRoot = block.transactionsRoot;
this._items[index].stateRoot = block.stateRoot;
this._items[index].miner = block.miner;
this._items[index].difficulty = block.difficulty;
this._items[index].totalDifficulty = block.totalDifficulty;
this._items[index].size = block.size;
this._items[index].extraData = block.extraData;
this._items[index].gasLimit = block.gasLimit;
this._items[index].gasUsed = block.gasUsed;
this._items[index].timestamp = block.timestamp;
this._items[index].transactions = block.transactions;
this._items[index].uncles = block.uncles;
historyBlock.hash = block.hash;
historyBlock.parentHash = block.parentHash;
historyBlock.nonce = block.nonce;
historyBlock.sha3Uncles = block.sha3Uncles;
historyBlock.transactionsRoot = block.transactionsRoot;
historyBlock.stateRoot = block.stateRoot;
historyBlock.miner = block.miner;
historyBlock.difficulty = block.difficulty;
historyBlock.totalDifficulty = block.totalDifficulty;
historyBlock.size = block.size;
historyBlock.extraData = block.extraData;
historyBlock.gasLimit = block.gasLimit;
historyBlock.gasUsed = block.gasUsed;
historyBlock.timestamp = block.timestamp;
historyBlock.transactions = block.transactions;
historyBlock.uncles = block.uncles;
changed = true;
}

View File

@ -116,12 +116,12 @@ netStatsApp.controller('StatsCtrl', function($scope, $filter, $localStorage, soc
console.log('We are scheduling a reconnect operation', opts);
})
.on('data', function incoming(data) {
socketAction(data.action, data.data);
$scope.$apply(socketAction(data.action, data.data));
});
socket.on('init', function(data)
{
socketAction("init", data.nodes);
$scope.$apply(socketAction("init", data.nodes));
});
socket.on('client-latency', function(data)
@ -142,7 +142,10 @@ netStatsApp.controller('StatsCtrl', function($scope, $filter, $localStorage, soc
_.forEach($scope.nodes, function (node, index) {
// Init hashrate
if( _.isUndefined(node.stats.hashrate) )
$scope.nodes[index].stats.hashrate = 0;
node.stats.hashrate = 0;
// Init latency
latencyFilter(node);
// Init history
if( _.isUndefined(data.history) )
@ -152,7 +155,7 @@ netStatsApp.controller('StatsCtrl', function($scope, $filter, $localStorage, soc
}
// Init or recover pin
$scope.nodes[index].pinned = ($scope.pinned.indexOf(node.id) >= 0 ? true : false);
node.pinned = ($scope.pinned.indexOf(node.id) >= 0 ? true : false);
});
if( $scope.nodes.length > 0 )
@ -281,6 +284,9 @@ netStatsApp.controller('StatsCtrl', function($scope, $filter, $localStorage, soc
if( _.isUndefined($scope.nodes[index].pinned) )
$scope.nodes[index].pinned = false;
// Init latency
latencyFilter($scope.nodes[index]);
updateActiveNodes();
}
@ -353,15 +359,19 @@ netStatsApp.controller('StatsCtrl', function($scope, $filter, $localStorage, soc
break;
case "latency":
var index = findIndex({id: data.id});
if( !_.isUndefined(data.id) && index >= 0 )
if( !_.isUndefined(data.id) && !_.isUndefined(data.latency) )
{
var node = $scope.nodes[index];
var index = findIndex({id: data.id});
if( !_.isUndefined(node) && !_.isUndefined(node.stats) && !_.isUndefined(node.stats.latency) )
if( index >= 0 )
{
$scope.nodes[index].stats.latency = data.latency;
var node = $scope.nodes[index];
if( !_.isUndefined(node) && !_.isUndefined(node.stats) && !_.isUndefined(node.stats.latency) && node.stats.latency !== data.latency )
{
node.stats.latency = data.latency;
latencyFilter(node);
}
}
}
@ -376,7 +386,7 @@ netStatsApp.controller('StatsCtrl', function($scope, $filter, $localStorage, soc
break;
}
$scope.$apply();
// $scope.$apply();
}
function findIndex(search)
@ -497,4 +507,34 @@ netStatsApp.controller('StatsCtrl', function($scope, $filter, $localStorage, soc
}
}
}
function latencyFilter(node)
{
if( _.isUndefined(node.readable) )
node.readable = {};
if( _.isUndefined(node.stats) ) {
node.readable.latencyClass = 'text-danger';
node.readable.latency = 'offline';
}
if (node.stats.active === false)
{
node.readable.latencyClass = 'text-danger';
node.readable.latency = 'offline';
}
else
{
if (node.stats.latency <= 100)
node.readable.latencyClass = 'text-success';
if (node.stats.latency > 100 && node.stats.latency <= 1000)
node.readable.latencyClass = 'text-warning';
if (node.stats.latency > 1000)
node.readable.latencyClass = 'text-danger';
node.readable.latency = node.stats.latency + ' ms';
}
}
});

View File

@ -184,7 +184,7 @@ block content
th
i.icon-bulb(data-toggle="tooltip", data-placement="top", title="Up-time", ng-click="orderTable(['-stats.uptime'], false)")
tbody(ng-cloak)
tr(ng-repeat='node in nodes | orderBy:predicate track by node.id', class="{{ node.stats | mainClass : bestBlock }}")
tr(ng-repeat='node in nodes | orderBy:predicate track by node.id', class="{{ node.stats | mainClass : bestBlock }}", id="node_{{node.id}}")
td.td-nodecheck
i(ng-click="pinNode(node.id)", class="{{ node.pinned | nodePinClass }}", data-toggle="tooltip", data-placement="right", data-original-title="Click to {{ node.pinned ? 'un' : '' }}pin")
td.nodeInfo(rel="{{node.id}}")
@ -194,8 +194,8 @@ block content
i.icon-warning-o
td
div.small(ng-bind-html="node.info.node | nodeVersion")
td(class="{{ node.stats | latencyClass }}")
span.small {{node.stats | latencyFilter}}
td(class="{{ node.readable.latencyClass }}")
span.small {{ node.readable.latency }}
td(class="{{ node.stats.mining | hashrateClass : node.stats.active }}", ng-bind-html="node.stats.hashrate | hashrateFilter : node.stats.mining")
td(class="{{ node.stats.peers | peerClass : node.stats.active }}", style="padding-left: 11px;") {{node.stats.peers}}
td(style="padding-left: 15px;") {{node.stats.pending}}