Fix status updates for remote nodes

This commit is contained in:
Jakob Borg 2014-07-29 11:54:00 +02:00
parent ee005fbc8e
commit 6115631746
3 changed files with 40 additions and 19 deletions

File diff suppressed because one or more lines are too long

View File

@ -34,6 +34,7 @@ syncthing.controller('EventCtrl', function ($scope, $http) {
if (lastID > 0) { if (lastID > 0) {
data.forEach(function (event) { data.forEach(function (event) {
console.log("event", event.id, event.type, event.data);
$scope.$emit(event.type, event); $scope.$emit(event.type, event);
}); });
}; };
@ -142,7 +143,7 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca
// Update completion status for all nodes that we share this repo with. // Update completion status for all nodes that we share this repo with.
$scope.repos[data.repo].Nodes.forEach(function (nodeCfg) { $scope.repos[data.repo].Nodes.forEach(function (nodeCfg) {
debouncedRefreshCompletion(nodeCfg.NodeID, data.repo); refreshCompletion(nodeCfg.NodeID, data.repo);
}); });
}); });
@ -188,27 +189,37 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca
} }
}) })
var debouncedFuncs = {};
function refreshRepo(repo) { function refreshRepo(repo) {
$http.get(urlbase + '/model?repo=' + encodeURIComponent(repo)).success(function (data) { var key = "refreshRepo" + repo;
$scope.model[repo] = data; if (!debouncedFuncs[key]) {
}); debouncedFuncs[key] = debounce(function () {
$http.get(urlbase + '/model?repo=' + encodeURIComponent(repo)).success(function (data) {
$scope.model[repo] = data;
console.log("refreshRepo", repo, data);
});
}, 1000, true);
}
debouncedFuncs[key]();
} }
function refreshSystem() { function refreshSystem() {
$http.get(urlbase + '/system').success(function (data) { $http.get(urlbase + '/system').success(function (data) {
$scope.myID = data.myID; $scope.myID = data.myID;
$scope.system = data; $scope.system = data;
console.log("refreshSystem", data);
}); });
} }
var completionFuncs = {};
function refreshCompletion(node, repo) { function refreshCompletion(node, repo) {
if (node === $scope.myID) { if (node === $scope.myID) {
return return
} }
if (!completionFuncs[node+repo]) { var key = "refreshCompletion" + node + repo;
completionFuncs[node+repo] = debounce(function () { if (!debouncedFuncs[key]) {
debouncedFuncs[key] = debounce(function () {
$http.get(urlbase + '/completion?node=' + node + '&repo=' + encodeURIComponent(repo)).success(function (data) { $http.get(urlbase + '/completion?node=' + node + '&repo=' + encodeURIComponent(repo)).success(function (data) {
if (!$scope.completion[node]) { if (!$scope.completion[node]) {
$scope.completion[node] = {}; $scope.completion[node] = {};
@ -217,14 +228,19 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca
var tot = 0, cnt = 0; var tot = 0, cnt = 0;
for (var cmp in $scope.completion[node]) { for (var cmp in $scope.completion[node]) {
if (cmp === "_total") {
continue;
}
tot += $scope.completion[node][cmp]; tot += $scope.completion[node][cmp];
cnt += 1; cnt += 1;
} }
$scope.completion[node]._total = tot / cnt; $scope.completion[node]._total = tot / cnt;
console.log("refreshCompletion", node, repo, $scope.completion[node]);
}); });
}); }, 1000, true);
} }
completionFuncs[node+repo](); debouncedFuncs[key]();
} }
function refreshConnectionStats() { function refreshConnectionStats() {
@ -247,12 +263,14 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca
} }
} }
$scope.connections = data; $scope.connections = data;
console.log("refreshConnections", data);
}); });
} }
function refreshErrors() { function refreshErrors() {
$http.get(urlbase + '/errors').success(function (data) { $http.get(urlbase + '/errors').success(function (data) {
$scope.errors = data; $scope.errors = data;
console.log("refreshErrors", data);
}); });
} }
@ -277,6 +295,8 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca
if (!hasConfig) { if (!hasConfig) {
$scope.$emit('ConfigLoaded'); $scope.$emit('ConfigLoaded');
} }
console.log("refreshConfig", data);
}); });
$http.get(urlbase + '/config/sync').success(function (data) { $http.get(urlbase + '/config/sync').success(function (data) {
@ -837,8 +857,8 @@ function isEmptyObject(obj) {
return true; return true;
} }
function debounce(func, wait, immediate) { function debounce(func, wait) {
var timeout, args, context, timestamp, result; var timeout, args, context, timestamp, result, again;
var later = function() { var later = function() {
var last = Date.now() - timestamp; var last = Date.now() - timestamp;
@ -846,9 +866,10 @@ function debounce(func, wait, immediate) {
timeout = setTimeout(later, wait - last); timeout = setTimeout(later, wait - last);
} else { } else {
timeout = null; timeout = null;
if (!immediate) { if (again) {
result = func.apply(context, args); result = func.apply(context, args);
context = args = null; context = args = null;
again = false;
} }
} }
}; };
@ -857,13 +878,13 @@ function debounce(func, wait, immediate) {
context = this; context = this;
args = arguments; args = arguments;
timestamp = Date.now(); timestamp = Date.now();
var callNow = immediate && !timeout; var callNow = !timeout;
if (!timeout) { if (!timeout) {
timeout = setTimeout(later, wait); timeout = setTimeout(later, wait);
}
if (callNow) {
result = func.apply(context, args); result = func.apply(context, args);
context = args = null; context = args = null;
} else {
again = true;
} }
return result; return result;

View File

@ -294,7 +294,7 @@
<span translate>Up to Date</span> (100%) <span translate>Up to Date</span> (100%)
</span> </span>
<span ng-if="connections[nodeCfg.NodeID] && completion[nodeCfg.NodeID]._total < 100"> <span ng-if="connections[nodeCfg.NodeID] && completion[nodeCfg.NodeID]._total < 100">
<span translate>Syncing</span> ({{connections[nodeCfg.NodeID].Completion}}%) <span translate>Syncing</span> ({{completion[nodeCfg.NodeID]._total | number:0}}%)
</span> </span>
<span translate ng-if="!connections[nodeCfg.NodeID]">Disconnected</span> <span translate ng-if="!connections[nodeCfg.NodeID]">Disconnected</span>
</span> </span>
@ -312,7 +312,7 @@
</tr> </tr>
<tr> <tr>
<th><span class="glyphicon glyphicon-comment"></span>&emsp;<span translate>Synchronization</span></th> <th><span class="glyphicon glyphicon-comment"></span>&emsp;<span translate>Synchronization</span></th>
<td class="text-right">{{completion[nodeCfg.NodeID]._total | alwaysNumber}}%</td> <td class="text-right">{{completion[nodeCfg.NodeID]._total | alwaysNumber | number:0}}%</td>
</tr> </tr>
<tr> <tr>
<th><span class="glyphicon glyphicon-compressed"></span>&emsp;<span translate>Use Compression</span></th> <th><span class="glyphicon glyphicon-compressed"></span>&emsp;<span translate>Use Compression</span></th>