From b347f825a461425a6ac8e596354d4b5e65ab2735 Mon Sep 17 00:00:00 2001 From: cubedro Date: Tue, 17 Feb 2015 20:14:38 +0200 Subject: [PATCH] added reconnect functionality --- public/js/controllers.js | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/public/js/controllers.js b/public/js/controllers.js index 07f342d..b74d506 100644 --- a/public/js/controllers.js +++ b/public/js/controllers.js @@ -51,14 +51,21 @@ function StatsCtrl($scope, $filter, socket, _, toastr) { switch(action) { case "init": $scope.nodes = data; - if($scope.nodes.length > 0){ + + if($scope.nodes.length > 0) + { toastr['success']("Got nodes list", "Got nodes!"); } break; case "add": - $scope.nodes.push(data); - toastr['success']("New node connected!", "New node!"); + if(addNewNode(data)) + { + toastr['success']("New node connected!", "New node!"); + } else { + toastr['info']("Node reconnected!", "Node is back!"); + } + break; case "update": @@ -78,6 +85,21 @@ function StatsCtrl($scope, $filter, socket, _, toastr) { 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() { if($scope.nodes.length)