improved download restart by preserving the preferences of the original download

This commit is contained in:
hamza zia 2014-06-03 12:58:40 +08:00
parent 1b6969cf81
commit 8f0500c78e

View File

@ -1,16 +1,16 @@
angular angular
.module('webui.ctrls.download', [ .module('webui.ctrls.download', [
"ui.bootstrap", "ui.bootstrap",
'webui.services.utils', 'webui.services.rpc', 'webui.services.alerts', 'webui.services.utils', 'webui.services.rpc', 'webui.services.rpc.helpers', 'webui.services.alerts',
'webui.services.settings', 'webui.services.modals', 'webui.services.configuration', 'webui.services.settings', 'webui.services.modals', 'webui.services.configuration',
]) ])
.controller('MainCtrl', [ .controller('MainCtrl', [
'$scope', '$name', '$enable', '$rpc', '$utils', '$alerts', '$modals', '$scope', '$name', '$enable', '$rpc', '$rpchelpers', '$utils', '$alerts', '$modals',
'$fileSettings', '$activeInclude', '$waitingExclude', '$pageSize', '$fileSettings', '$activeInclude', '$waitingExclude', '$pageSize',
// for document title // for document title
'$window', '$window',
function( function(
scope, name, enable, rpc, utils, alerts, modals, scope, name, enable, rpc, rhelpers, utils, alerts, modals,
fsettings, activeInclude, waitingExclude, pageSize, fsettings, activeInclude, waitingExclude, pageSize,
window window
) { ) {
@ -42,24 +42,27 @@ function(
// assumes downloads which are started by URIs, not torrents. // assumes downloads which are started by URIs, not torrents.
// the preferences are also not transferred, just simple restart // the preferences are also not transferred, just simple restart
rpc.once('getFiles', [d.gid], function(data) { rpc.once('getOption', [d.gid], function(data) {
var files = data[0]; var prefs = data[0];
var uris = rpc.once('getFiles', [d.gid], function(data) {
_.chain(files).map(function(f) { return f.uris }) var files = data[0];
.filter(function(uris) { return uris && uris.length }) var uris =
.map(function(uris) { _.chain(files).map(function(f) { return f.uris })
var u = _.chain(uris) .filter(function(uris) { return uris && uris.length })
.map(function(u) { return u.uri }) .map(function(uris) {
.uniq().value(); var u = _.chain(uris)
return u; .map(function(u) { return u.uri })
}).value(); .uniq().value();
return u;
}).value();
if (uris.length > 0) { if (uris.length > 0) {
console.log('adding uris:', uris); console.log('adding uris:', uris, prefs);
scope.remove(d, function() { scope.remove(d, function() {
rpc.once('addUri', uris, angular.noop, true); rhelpers.addUris(uris, prefs);
}, true); }, true);
} }
});
}); });
} }
@ -75,23 +78,27 @@ function(
// otherwise permanantly remove it // otherwise permanantly remove it
// d: the download ctx // d: the download ctx
scope.remove = function(d, cb, noConfirm) { scope.remove = function(d, cb, noConfirm) {
if (!noConfirm && !confirm("Remove %s and associated meta-data?".replace("%s", d.name))) { // HACK to make sure an angular digest is not running, as only one can happen at a time, and confirm is a blocking
return; // call so an rpc response can also trigger a digest call
} setTimeout(function() {
if (!noConfirm && !confirm("Remove %s and associated meta-data?".replace("%s", d.name))) {
return;
}
var method = 'remove'; var method = 'remove';
if (scope.getType(d) == 'stopped') if (scope.getType(d) == 'stopped')
method = 'removeDownloadResult'; method = 'removeDownloadResult';
if (d.followedFrom) { if (d.followedFrom) {
scope.remove(d.followedFrom, function() {}, true); scope.remove(d.followedFrom, function() {}, true);
d.followedFrom = null; d.followedFrom = null;
} }
rpc.once(method, [d.gid], cb); rpc.once(method, [d.gid], cb);
}, 0);
} }
// start filling in the model of active, // start filling in the model of active,
// waiting and stopped download // waiting and stopped download
rpc.subscribe('tellActive', [], function(data) { rpc.subscribe('tellActive', [], function(data) {
scope.$apply(function() { scope.$apply(function() {
@ -506,16 +513,17 @@ function(
rpc.once('getOption', [d.gid], function(data) { rpc.once('getOption', [d.gid], function(data) {
var vals = data[0]; var vals = data[0];
for (var i in fsettings) { var sets = _.cloneDeep(fsettings);
for (var i in sets) {
if (type == 'active' && activeInclude.indexOf(i) == -1) continue; if (type == 'active' && activeInclude.indexOf(i) == -1) continue;
if (type == 'waiting' && waitingExclude.indexOf(i) != -1) continue; if (type == 'waiting' && waitingExclude.indexOf(i) != -1) continue;
settings[i] = fsettings[i]; settings[i] = sets[i];
settings[i].val = vals[i] || settings[i].val; settings[i].val = vals[i] || settings[i].val;
} }
modals.invoke('settings', settings, scope.name + ' settings', function(settings) { modals.invoke('settings', settings, d.name + ' settings', 'Change', function(settings) {
var sets = {}; var sets = {};
for (var i in settings) { sets[i] = settings[i].val }; for (var i in settings) { sets[i] = settings[i].val };