added basic download control functionally in angular
This commit is contained in:
parent
d2f82365f1
commit
5ec45b0aac
|
@ -153,11 +153,11 @@
|
||||||
<td class="download-controls" rowspan="2">
|
<td class="download-controls" rowspan="2">
|
||||||
<div class="btn-group">
|
<div class="btn-group">
|
||||||
|
|
||||||
<button ng-show="download.booleans.can_pause" class="btn download_pause"><i class="icon-pause"></i></button>
|
<button ng-show="download.booleans.can_pause" class="btn download_pause" ng-click="pause(download)"><i class="icon-pause"></i></button>
|
||||||
<button ng-show="download.booleans.can_play" class="btn download_play"><i class="icon-play"></i></button>
|
<button ng-show="download.booleans.can_play" class="btn download_play" ng-click="resume(download)"><i class="icon-play"></i></button>
|
||||||
<button ng-show="download.booleans.can_restart" class="btn download_restart"><i class="icon-repeat"></i></button>
|
<button ng-show="download.booleans.can_restart" class="btn download_restart"><i class="icon-repeat"></i></button>
|
||||||
|
|
||||||
<button class="btn download_remove hidden-phone"><i class="icon-stop"></i></button>
|
<button class="btn download_remove hidden-phone" ng-click="remove(download)"><i class="icon-stop"></i></button>
|
||||||
|
|
||||||
<button ng-show="download.booleans.has_settings" class="btn download_settings hidden-phone"><i class="icon-cog"></i></button>
|
<button ng-show="download.booleans.has_settings" class="btn download_settings hidden-phone"><i class="icon-cog"></i></button>
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,32 @@
|
||||||
app.controller('DownloadCtrl', [ '$scope', '$rpc', '$utils',
|
app.controller('DownloadCtrl', [ '$scope', '$rpc', '$utils',
|
||||||
function(scope, rpc, utils) {
|
function(scope, rpc, utils) {
|
||||||
scope.props = [
|
|
||||||
'gid', 'status', 'totalLength', 'completedLength',
|
|
||||||
'uploadLength', 'downloadSpeed', 'uploadSpeed',
|
|
||||||
'errorCode' , 'followedBy', 'belongsTo', 'bitfield',
|
|
||||||
'infoHash', 'numSeeders', 'pieceLength',
|
|
||||||
'numPieces', 'connections', 'dir', 'files', 'bittorrent'
|
|
||||||
];
|
|
||||||
|
|
||||||
scope.active = [], scope.waiting = [], scope.stopped = [];
|
scope.active = [], scope.waiting = [], scope.stopped = [];
|
||||||
|
|
||||||
|
// pause the download
|
||||||
|
// d: the download ctx
|
||||||
|
scope.pause = function(d) {
|
||||||
|
rpc.once('forcePause', [d.gid]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// resume the download
|
||||||
|
// d: the download ctx
|
||||||
|
scope.resume = function(d) {
|
||||||
|
rpc.once('unpause', [d.gid]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove the download,
|
||||||
|
// put it in stopped list if active,
|
||||||
|
// otherwise permanantly remove it
|
||||||
|
// d: the download ctx
|
||||||
|
scope.remove = function(d) {
|
||||||
|
var method = d.type == 'stopped' ? 'removeDownloadResult' : 'remove';
|
||||||
|
rpc.once(method, [d.gid]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// start filling in the model of active,
|
||||||
|
// waiting and stopped download
|
||||||
rpc.subscribe('tellActive', [], function(data) {
|
rpc.subscribe('tellActive', [], function(data) {
|
||||||
console.log('got active data');
|
console.log('got active data');
|
||||||
scope.$apply(function() {
|
scope.$apply(function() {
|
||||||
|
@ -31,13 +47,14 @@ function(scope, rpc, utils) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// actual downloads used by the view
|
||||||
scope.getDownloads = function() {
|
scope.getDownloads = function() {
|
||||||
var downs = scope.active
|
return scope.active
|
||||||
.concat(scope.waiting).concat(scope.stopped);
|
.concat(scope.waiting).concat(scope.stopped);
|
||||||
|
|
||||||
return downs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// convert the donwload form aria2 to once used by the view,
|
||||||
|
// minor additions of some fields and checks
|
||||||
scope.getCtx = function(d, ctx) {
|
scope.getCtx = function(d, ctx) {
|
||||||
ctx = ctx || {};
|
ctx = ctx || {};
|
||||||
|
|
||||||
|
@ -49,21 +66,25 @@ function(scope, rpc, utils) {
|
||||||
ctx[e] = d[e];
|
ctx[e] = d[e];
|
||||||
});
|
});
|
||||||
|
|
||||||
ctx.dir = d.dir.replace(/\\/g, '/');
|
|
||||||
ctx.files = _.map(d.files, function(e) {
|
|
||||||
e.path = e.path.replace(/\\/g, '/').replace(ctx.dir, '.');
|
|
||||||
return e;
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ctx.eta = (d.totalLength-d.completedLength) / d.downloadSpeed;
|
|
||||||
|
|
||||||
var percentage = (d.completedLength / d.totalLength)*100;
|
var percentage = (d.completedLength / d.totalLength)*100;
|
||||||
percentage = percentage.toFixed(2);
|
percentage = percentage.toFixed(2);
|
||||||
if(!percentage) percentage = 0;
|
if(!percentage) percentage = 0;
|
||||||
|
|
||||||
ctx.percentage = percentage;
|
ctx.percentage = percentage;
|
||||||
|
ctx.dir = d.dir.replace(/\\/g, '/');
|
||||||
|
ctx.eta = (d.totalLength-d.completedLength) / d.downloadSpeed;
|
||||||
|
|
||||||
|
var type = d.status;
|
||||||
|
if (type == "paused") type = "waiting";
|
||||||
|
if (["error", "removed", "complete"].indexOf(type) != -1)
|
||||||
|
type = "stopped";
|
||||||
|
ctx.type = type;
|
||||||
|
|
||||||
|
ctx.files = _.map(d.files, function(e) {
|
||||||
|
e.path = e.path.replace(/\\/g, '/').replace(ctx.dir, '.');
|
||||||
|
return e;
|
||||||
|
});
|
||||||
|
|
||||||
if (d.bittorrent && d.bittorrent.info) {
|
if (d.bittorrent && d.bittorrent.info) {
|
||||||
ctx.name = d.bittorrent.info.name;
|
ctx.name = d.bittorrent.info.name;
|
||||||
|
@ -72,12 +93,6 @@ function(scope, rpc, utils) {
|
||||||
ctx.name = utils.getFileName(ctx.files[0].path || ctx.files[0].uris[0].uri);
|
ctx.name = utils.getFileName(ctx.files[0].path || ctx.files[0].uris[0].uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
var type = d.status;
|
|
||||||
if (type == "paused") type = "waiting";
|
|
||||||
if (["error", "removed", "complete"].indexOf(type) != -1)
|
|
||||||
type = "stopped";
|
|
||||||
ctx.type = type;
|
|
||||||
|
|
||||||
ctx.booleans = {
|
ctx.booleans = {
|
||||||
is_error: ctx.status === "error",
|
is_error: ctx.status === "error",
|
||||||
is_complete: ctx.status === "complete",
|
is_complete: ctx.status === "complete",
|
||||||
|
|
|
@ -68,6 +68,9 @@ app.factory('$rpc', ['$syscall', '$globalTimeout', function(syscall, time) {
|
||||||
},
|
},
|
||||||
// syscall is done only once
|
// syscall is done only once
|
||||||
once: function(name, params, cb) {
|
once: function(name, params, cb) {
|
||||||
|
cb = cb || angular.noop;
|
||||||
|
params = params || [];
|
||||||
|
|
||||||
subscriptions.push({
|
subscriptions.push({
|
||||||
once: true,
|
once: true,
|
||||||
name: 'aria2.' + name,
|
name: 'aria2.' + name,
|
||||||
|
@ -81,6 +84,9 @@ app.factory('$rpc', ['$syscall', '$globalTimeout', function(syscall, time) {
|
||||||
// callback is called each time with updated syscall data
|
// callback is called each time with updated syscall data
|
||||||
// after the global timeout
|
// after the global timeout
|
||||||
subscribe: function(name, params, cb) {
|
subscribe: function(name, params, cb) {
|
||||||
|
cb = cb || angular.noop;
|
||||||
|
params = params || [];
|
||||||
|
|
||||||
var handle = {
|
var handle = {
|
||||||
once: false,
|
once: false,
|
||||||
name: 'aria2.' + name,
|
name: 'aria2.' + name,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user