Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added some tricky methods to restart error tasks #490

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/index-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@

<li class="dropdown" dropdown>
<a class="dropdown-toggle" href="#" dropdown-toggle> {{ 'Manage' | translate }} <span class="caret"></span></a>
<ul class="dropdown-menu">
<ul class="dropdown-menu multilevel">
<li>
<a href="#" ng-click="forcePauseAll()"><svg class="icon icon-fw"><use xlink:href="#icon-pause"></use></svg> {{ 'Pause All' | translate }}</a>
</li>
Expand All @@ -207,6 +207,16 @@
ng-click="removeAll()"><span class="fa fa-fw fa-fire">&nbsp;</span> Remove All</a>
</li>
-->
<li class="dropdown-submenu" dropdown>
<a class="dropdown-toggle" href="#" data-toggle="dropdown" dropdown-toggle> {{ 'Additions' | translate }}</a>
<ul class="dropdown-menu">
<li>
<a href="#" ng-click="restartError(0, 10)"><svg class="icon icon-fw"><use xlink:href="#icon-repeat"></use></svg> {{ 'Restart 10 Error Tasks' | translate }}</a>
<a href="#" ng-click="restartError(0, 20)"><svg class="icon icon-fw"><use xlink:href="#icon-repeat"></use></svg> {{ 'Restart 20 Error Tasks' | translate }}</a>
<a href="#" ng-click="restartError(0, 50)"><svg class="icon icon-fw"><use xlink:href="#icon-repeat"></use></svg> {{ 'Restart 50 Error Tasks' | translate }}</a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
Expand Down
26 changes: 26 additions & 0 deletions src/js/ctrls/nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,31 @@ export default angular
scope.shutDownServer = function() {
rpc.once("shutdown", []);
};

scope.restartError = function(offset, limit) {
// offset, limit, like sql
// count
var fetch = function(off, lim, count) {
console.log("fetching: " + off + " limit: " + lim);
rpc.once("tellStopped", [off, count], function(data) {
var errors = _.filter(data[0], function(d) {
return d["status"] == "error";
});
errors = errors.slice(0, lim);
console.log("restart: " + errors.length);
_.forEach(errors, function(d) {
rhelpers.restart(d);
// console.log(d.status);
});

if (errors.length < lim && data[0].length == count) {
fetch(off + count, lim - errors.length, count);
} else {
console.log("end");
}
});
};
fetch(offset, limit, 100);
};
}
]).name;
79 changes: 79 additions & 0 deletions src/js/services/rpc/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
};
}
Expand Down
26 changes: 26 additions & 0 deletions src/scss/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,29 @@
@import "style";
@import "download";
@import "modals";

.dropdown-submenu {
position: relative;
}

.dropdown-submenu:hover > .dropdown-menu {
display: block;
}

.dropdown-submenu > a:after {
display: block;
content: " ";
float: right;
width: 0;
height: 0;
border-color: transparent;
border-style: solid;
border-width: 5px 0 5px 5px;
border-left-color: #ccc;
margin-top: 5px;
margin-right: -10px;
}

.dropdown-submenu:hover > a:after {
border-left-color: #fff;
}