added reconnect functionality

This commit is contained in:
cubedro 2015-02-17 20:14:38 +02:00
parent 9f93f7059b
commit b347f825a4

View File

@ -51,14 +51,21 @@ function StatsCtrl($scope, $filter, socket, _, toastr) {
switch(action) { switch(action) {
case "init": case "init":
$scope.nodes = data; $scope.nodes = data;
if($scope.nodes.length > 0){
if($scope.nodes.length > 0)
{
toastr['success']("Got nodes list", "Got nodes!"); toastr['success']("Got nodes list", "Got nodes!");
} }
break; break;
case "add": case "add":
$scope.nodes.push(data); if(addNewNode(data))
toastr['success']("New node connected!", "New node!"); {
toastr['success']("New node connected!", "New node!");
} else {
toastr['info']("Node reconnected!", "Node is back!");
}
break; break;
case "update": case "update":
@ -78,6 +85,21 @@ function StatsCtrl($scope, $filter, socket, _, toastr) {
return _.findIndex($scope.nodes, search); return _.findIndex($scope.nodes, search);
} }
function addNewNode(data)
{
var index = findIndex({id: data.id});
if(index < 0)
{
$scope.nodes.push(data);
return true;
}
$scope.nodes[index] = data;
return false;
}
function updateStats() function updateStats()
{ {
if($scope.nodes.length) if($scope.nodes.length)