From 4854d732d4a72764f10765d509e8f4263859c2d0 Mon Sep 17 00:00:00 2001 From: sprhawk <465558+sprhawk@users.noreply.github.com> Date: Fri, 4 Jan 2019 13:06:11 +0800 Subject: [PATCH 1/4] added restart first 10 error tasks --- src/index-template.html | 3 ++ src/js/ctrls/nav.js | 9 ++++ src/js/services/rpc/helpers.js | 79 ++++++++++++++++++++++++++++++++++ src/js/translate/en_US.js | 4 +- 4 files changed, 93 insertions(+), 2 deletions(-) diff --git a/src/index-template.html b/src/index-template.html index b5731fae..840ca16a 100644 --- a/src/index-template.html +++ b/src/index-template.html @@ -207,6 +207,9 @@ ng-click="removeAll()">  Remove All --> +
  • + {{ 'Restart Error Tasks' | translate }} +
  • diff --git a/src/js/ctrls/nav.js b/src/js/ctrls/nav.js index 9c6d09b8..a95f84cf 100644 --- a/src/js/ctrls/nav.js +++ b/src/js/ctrls/nav.js @@ -146,5 +146,14 @@ export default angular scope.shutDownServer = function() { rpc.once("shutdown", []); }; + + scope.restartError = function(num) { + console.log(num); + rpc.once("tellStopped", [0, 10], function(data) { + _.forEach(data[0], function(d) { + rhelpers.restart(d); + }); + }); + }; } ]).name; diff --git a/src/js/services/rpc/helpers.js b/src/js/services/rpc/helpers.js index 1dec4964..0e04c23c 100644 --- a/src/js/services/rpc/helpers.js +++ b/src/js/services/rpc/helpers.js @@ -15,6 +15,7 @@ export default angular rpc.once("getVersion", [], function(data) { miscellaneous = data[0]; }); + return { isFeatureEnabled: function(feature) { return miscellaneous.enabledFeatures.indexOf(feature) != -1; @@ -61,6 +62,84 @@ export default angular // now dispatch all addUri syscalls rpc.forceUpdate(); + }, + // copied from main.js + restart: function(d) { + // assumes downloads which are started by URIs, not torrents. + // the preferences are also not transferred, just simple restart + var thisService = this; + rpc.once("getOption", [d.gid], function(data) { + var prefs = data[0]; + rpc.once("getFiles", [d.gid], function(data) { + var files = data[0]; + var uris = _.chain(files) + .map(function(f) { + return f.uris; + }) + .filter(function(uris) { + return uris && uris.length; + }) + .map(function(uris) { + var u = _.chain(uris) + .map(function(u) { + return u.uri; + }) + .uniq() + .value(); + return u; + }) + .value(); + + if (uris.length > 0) { + console.log("adding uris:", uris, prefs); + thisService.remove( + d, + function() { + thisService.addUris(uris, prefs); + }, + true + ); + } + }); + }); + }, + canRestart: function(d) { + return ["active", "paused"].indexOf(d.status) == -1 && !d.bittorrent; + }, + // remove the download, + // put it in stopped list if active, + // otherwise permanantly remove it + // d: the download ctx + remove: function(d, cb, noConfirm) { + // HACK to make sure an angular digest is not running, as only one can happen at a time, and confirm is a blocking + var thisService = this; + // call so an rpc response can also trigger a digest call + setTimeout(function() { + if ( + !noConfirm && + !confirm( + filter("translate")("Remove {{name}} and associated meta-data?", { name: d.name }) + ) + ) { + return; + } + + var method = "remove"; + + if (thisService.getType(d) == "stopped") method = "removeDownloadResult"; + + if (d.followedFrom) { + thisService.remove(d.followedFrom, function() {}, true); + d.followedFrom = null; + } + rpc.once(method, [d.gid], cb); + }, 0); + }, + getType: function(d) { + var type = d.status; + if (type == "paused") type = "waiting"; + if (["error", "removed", "complete"].indexOf(type) != -1) type = "stopped"; + return type; } }; } diff --git a/src/js/translate/en_US.js b/src/js/translate/en_US.js index a174f603..7a15f5b3 100644 --- a/src/js/translate/en_US.js +++ b/src/js/translate/en_US.js @@ -11,8 +11,8 @@ translations.en_US = { "By Torrents": "By Torrents", "By Metalinks": "By Metalinks", Manage: "Manage", - "Pause All": "Pause All", - "Resume Paused": "Resume Paused", + "Pause All": "Pause aaaah All", + "Resume Paused": "Resume yyyy Paused", "Purge Completed": "Purge Completed", Settings: "Settings", "Connection Settings": "Connection Settings", From ca50806d23de0b79ae71ec380be8eb94a1659391 Mon Sep 17 00:00:00 2001 From: sprhawk <465558+sprhawk@users.noreply.github.com> Date: Sat, 5 Jan 2019 02:13:45 +0800 Subject: [PATCH 2/4] search all stopped tasks to find error tasks --- src/index-template.html | 13 ++++++++++--- src/js/ctrls/nav.js | 30 ++++++++++++++++++++++++------ src/scss/app.scss | 26 ++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 9 deletions(-) diff --git a/src/index-template.html b/src/index-template.html index 840ca16a..350e0393 100644 --- a/src/index-template.html +++ b/src/index-template.html @@ -187,7 +187,7 @@