diff --git a/angular.html b/angular.html index a724aa7..33abb58 100644 --- a/angular.html +++ b/angular.html @@ -153,11 +153,11 @@
- - + + - + diff --git a/js/ctrls/download.js b/js/ctrls/download.js index cc6bf59..0900cd7 100644 --- a/js/ctrls/download.js +++ b/js/ctrls/download.js @@ -1,16 +1,32 @@ app.controller('DownloadCtrl', [ '$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 = []; + // 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) { console.log('got active data'); scope.$apply(function() { @@ -31,13 +47,14 @@ function(scope, rpc, utils) { }); }); + // actual downloads used by the view scope.getDownloads = function() { - var downs = scope.active + return scope.active .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) { ctx = ctx || {}; @@ -49,21 +66,25 @@ function(scope, rpc, utils) { 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; percentage = percentage.toFixed(2); if(!percentage) percentage = 0; 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) { 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); } - var type = d.status; - if (type == "paused") type = "waiting"; - if (["error", "removed", "complete"].indexOf(type) != -1) - type = "stopped"; - ctx.type = type; - ctx.booleans = { is_error: ctx.status === "error", is_complete: ctx.status === "complete", diff --git a/js/services/rpc/rpc.js b/js/services/rpc/rpc.js index 269737d..0f9874e 100644 --- a/js/services/rpc/rpc.js +++ b/js/services/rpc/rpc.js @@ -68,6 +68,9 @@ app.factory('$rpc', ['$syscall', '$globalTimeout', function(syscall, time) { }, // syscall is done only once once: function(name, params, cb) { + cb = cb || angular.noop; + params = params || []; + subscriptions.push({ once: true, name: 'aria2.' + name, @@ -81,6 +84,9 @@ app.factory('$rpc', ['$syscall', '$globalTimeout', function(syscall, time) { // callback is called each time with updated syscall data // after the global timeout subscribe: function(name, params, cb) { + cb = cb || angular.noop; + params = params || []; + var handle = { once: false, name: 'aria2.' + name,