fixed angular recursive bug in nested rpc calls

This commit is contained in:
hamza zia 2013-03-18 15:59:40 +01:00
parent 8b3b30dd4a
commit 4e9404f29e
2 changed files with 33 additions and 7 deletions

View File

@ -28,12 +28,27 @@ function(
// put it in stopped list if active,
// otherwise permanantly remove it
// d: the download ctx
scope.remove = function(d) {
scope.remove = function(d, cb) {
var method = 'remove';
if (scope.getType(d) == 'stopped')
method = 'removeDownloadResult';
rpc.once(method, [d.gid]);
rpc.once(method, [d.gid], cb);
// also remove it from client cache assuming that it will be deleted in the aria2 list,
// but we could be wrong but the cache will update in next global update
var downloads = [scope.active, scope.waiting, scope.stopped], ind = -1, i;
for (i = 0; i < downloads.length; i++) {
ind = downloads[i].indexOf(d);
if (ind != -1) break;
}
if (ind == -1) {
return;
}
downloads[i].splice(ind, 1);
}
scope.restart = function(d) {
@ -47,8 +62,8 @@ function(
}).value();
if (uris.length > 0) {
rpc.once('removeDownloadResult', [d.gid], function() {
rpc.once('addUri', uris);
scope.remove(d, function() {
rpc.once('addUri', uris, angular.noop, true);
});
}
}
@ -92,6 +107,10 @@ function(
scope.totalPages = Math.ceil(scope.totalDownloads / scope.pageSize)
// fix the bug when downloads are deleted until no left on a specific page
if (scope.currentPage > scope.totalPages)
scope.currentPage = scope.totalPages;
downloads = downloads.slice( (scope.currentPage - 1) * scope.pageSize );
downloads.splice( scope.pageSize );

View File

@ -59,20 +59,27 @@ function(syscall, time, alerts, utils, rootScope) {
utils.setCookie('aria2conf', currentConf);
var cbs = [];
_.each(data.result, function(d, i) {
var handle = subscriptions[i];
if (handle) {
if (d.code) {
alerts.addAlert(d.message, 'error');
}
handle.cb(d);
// run them later as the cb itself can mutate the subscriptions
cbs.push({cb: handle.cb, data: d});
if (handle.once) {
subscriptions[i] = null;
}
}
});
rootScope.$apply();
_.each(cbs, function(hnd) {
hnd.cb(hnd.data);
});
rootScope.$digest();
if (forceNextUpdate) {
forceNextUpdate = false;
@ -122,7 +129,7 @@ function(syscall, time, alerts, utils, rootScope) {
cb = cb || angular.noop;
params = params || [];
subscriptions.push({
subscriptions.unshift({
once: true,
name: 'aria2.' + name,
params: params,