Link metadata with the actual downloads
This commit is contained in:
parent
7ca141a41f
commit
5d1af829fd
|
@ -295,6 +295,10 @@
|
||||||
</pagination>
|
</pagination>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<form>
|
||||||
|
<label><input type="checkbox" ng-model="hideLinkedMetadata" id="hide-linked-metadata"> Hide linked meta-data</label>
|
||||||
|
</form>
|
||||||
|
|
||||||
<table
|
<table
|
||||||
ng-repeat="download in getDownloads()"
|
ng-repeat="download in getDownloads()"
|
||||||
class="row download" data-gid="{{download.gid}}">
|
class="row download" data-gid="{{download.gid}}">
|
||||||
|
|
|
@ -16,9 +16,11 @@ function(
|
||||||
|
|
||||||
var re_slashes = /\\/g;
|
var re_slashes = /\\/g;
|
||||||
var slash = "/";
|
var slash = "/";
|
||||||
|
var allStopped = [];
|
||||||
|
|
||||||
scope.active = [], scope.waiting = [], scope.stopped = [];
|
scope.active = [], scope.waiting = [], scope.stopped = [];
|
||||||
scope.gstats = {};
|
scope.gstats = {};
|
||||||
|
scope.hideLinkedMetadata = true;
|
||||||
|
|
||||||
// pause the download
|
// pause the download
|
||||||
// d: the download ctx
|
// d: the download ctx
|
||||||
|
@ -42,21 +44,22 @@ function(
|
||||||
if (scope.getType(d) == 'stopped')
|
if (scope.getType(d) == 'stopped')
|
||||||
method = 'removeDownloadResult';
|
method = 'removeDownloadResult';
|
||||||
|
|
||||||
|
if (d.followedFrom) {
|
||||||
|
scope.remove(d.followedFrom, function() {});
|
||||||
|
d.followedFrom = null;
|
||||||
|
}
|
||||||
rpc.once(method, [d.gid], cb);
|
rpc.once(method, [d.gid], cb);
|
||||||
|
|
||||||
// also remove it from client cache assuming that it will be deleted in the aria2 list,
|
var lists = [scope.active, scope.waiting, scope.stopped], ind = -1, i;
|
||||||
// but we could be wrong but the cache will update in next global update
|
for (var i = 0; i < lists.length; ++i) {
|
||||||
var downloads = [scope.active, scope.waiting, scope.stopped], ind = -1, i;
|
var list = lists[i];
|
||||||
for (i = 0; i < downloads.length; i++) {
|
var idx = list.indexOf(d);
|
||||||
ind = downloads[i].indexOf(d);
|
if (idx < 0) {
|
||||||
if (ind != -1) break;
|
continue;
|
||||||
}
|
}
|
||||||
|
list.splice(idx, 1);
|
||||||
if (ind == -1) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
downloads[i].splice(ind, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
scope.restart = function(d) {
|
scope.restart = function(d) {
|
||||||
|
@ -79,27 +82,58 @@ function(
|
||||||
// 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() {
|
||||||
utils.mergeMap(data[0], scope.active, scope.getCtx);
|
utils.mergeMap(data[0], scope.active, scope.getCtx);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
rpc.subscribe('tellWaiting', [0, 1000], function(data) {
|
rpc.subscribe('tellWaiting', [0, 1000], function(data) {
|
||||||
|
scope.$apply(function() {
|
||||||
utils.mergeMap(data[0], scope.waiting, scope.getCtx);
|
utils.mergeMap(data[0], scope.waiting, scope.getCtx);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
rpc.subscribe('tellStopped', [0, 1000], function(data) {
|
rpc.subscribe('tellStopped', [0, 1000], function(data) {
|
||||||
|
scope.$apply(function() {
|
||||||
|
if (!scope.hideLinkedMetadata) {
|
||||||
utils.mergeMap(data[0], scope.stopped, scope.getCtx);
|
utils.mergeMap(data[0], scope.stopped, scope.getCtx);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
utils.mergeMap(data[0], allStopped, scope.getCtx);
|
||||||
|
var gids = {};
|
||||||
|
_.forEach(allStopped, function(e) {
|
||||||
|
gids[e.gid] = e;
|
||||||
|
});
|
||||||
|
_.forEach(scope.active, function(e) {
|
||||||
|
gids[e.gid] = e;
|
||||||
|
});
|
||||||
|
_.forEach(scope.waiting, function(e) {
|
||||||
|
gids[e.gid] = e;
|
||||||
|
});
|
||||||
|
scope.stopped = _.filter(allStopped, function(e) {
|
||||||
|
if (!e.metadata || !e.followedBy || !(e.followedBy in gids)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
var linked = gids[e.followedBy];
|
||||||
|
linked.followedFrom = e;
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
rpc.subscribe('getGlobalStat', [], function(data) {
|
rpc.subscribe('getGlobalStat', [], function(data) {
|
||||||
|
scope.$apply(function() {
|
||||||
scope.gstats = data[0];
|
scope.gstats = data[0];
|
||||||
window.document.title = utils.getTitle(scope.gstats);
|
window.document.title = utils.getTitle(scope.gstats);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
rpc.once('getVersion', [], function(data) {
|
rpc.once('getVersion', [], function(data) {
|
||||||
|
scope.$apply(function() {
|
||||||
scope.miscellaneous = data[0];
|
scope.miscellaneous = data[0];
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// total number of downloads, updates dynamically as downloads are
|
// total number of downloads, updates dynamically as downloads are
|
||||||
// stored in scope
|
// stored in scope
|
||||||
|
@ -243,6 +277,9 @@ function(
|
||||||
dir: d.dir,
|
dir: d.dir,
|
||||||
status: d.status,
|
status: d.status,
|
||||||
gid: d.gid,
|
gid: d.gid,
|
||||||
|
followedBy: (d.followedBy && d.followedBy.length == 1
|
||||||
|
? d.followedBy[0] : null),
|
||||||
|
followedFrom: null,
|
||||||
numPieces: d.numPieces,
|
numPieces: d.numPieces,
|
||||||
connections: d.connections,
|
connections: d.connections,
|
||||||
bitfield: d.bitfield,
|
bitfield: d.bitfield,
|
||||||
|
@ -266,6 +303,9 @@ function(
|
||||||
ctx.dir = d.dir;
|
ctx.dir = d.dir;
|
||||||
ctx.status = d.status;
|
ctx.status = d.status;
|
||||||
ctx.gid = d.gid;
|
ctx.gid = d.gid;
|
||||||
|
ctx.followedBy = (d.followedBy && d.followedBy.length == 1
|
||||||
|
? d.followedBy[0] : null);
|
||||||
|
ctx.followedFrom = null;
|
||||||
ctx.numPieces = d.numPieces;
|
ctx.numPieces = d.numPieces;
|
||||||
ctx.connections = d.connections;
|
ctx.connections = d.connections;
|
||||||
ctx.bitfield = d.bitfield;
|
ctx.bitfield = d.bitfield;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user