- {{name}}
+ name {{download.gid}}
- - Time left: {{eta}}
- - Download Speed: {{down_speed}}
- - Progress: {{percentage}}%
+ - Time left: {{(download.totalLength-download.completedLength)/download.downloadSpeed}}
+ - Download Speed: {{download.downloadSpeed}}
+ - Progress: {{(download.completedLength / download.totalLength)*100}}%
|
@@ -171,23 +171,18 @@
- - Status: {{status}}
- - GID: {{gid}}
- - Dir: {{dir}}
- - Size: {{size}}
- - Downloaded: {{downloaded}}
- - Num of Pieces: {{numPieces}}
- - Piece Length: {{pieceLength}}
- - ETA: {{eta}}
- - Down Speed: {{down_speed}}
- - Upload Speed: {{upload_speed}}
- - Upload Length: {{uploadLength}}
- - Connections: {{connections}}
+ - Status: {{download.status}}
+ - GID: {{download.gid}}
+ - Dir: {{download.dir}}
+ - Size: {{download.totalLength}}
+ - Downloaded: {{download.downloadSpeed}}
+ - Num of Pieces: {{download.numPieces}}
+ - Piece Length: {{download.pieceLength}}
Download Files
- - {{path}} ({{size}})
+ - {{file.path}} ({{file.completedLength}})
diff --git a/css/download.css b/css/download.css
index 82f7c07..03d43a8 100644
--- a/css/download.css
+++ b/css/download.css
@@ -1,23 +1,7 @@
.download-name {
font-size: 12px;
}
-.active-download {
- width: 100%;
- margin-bottom: 10px;
- background-color: rgb(245, 245, 245);
- border: 1px solid rgba(0, 0, 0, 0.05);
- border-radius: 4px 4px 4px 4px;
- box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.05);
-}
-.waiting-download {
- width: 100%;
- margin-bottom: 10px;
- background-color: rgb(245, 245, 245);
- border: 1px solid rgba(0, 0, 0, 0.05);
- border-radius: 4px 4px 4px 4px;
- box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.05);
-}
-.stopped-download {
+.active-download, .waiting-download, .stopped-download, .download {
width: 100%;
margin-bottom: 10px;
background-color: rgb(245, 245, 245);
diff --git a/js/ctrls/download.js b/js/ctrls/download.js
index a2c5d89..41edfd3 100644
--- a/js/ctrls/download.js
+++ b/js/ctrls/download.js
@@ -1,36 +1,82 @@
app.controller('DownloadCtrl', [ '$scope', '$rpc', '$utils',
function(scope, rpc, utils) {
- scope.active = scope.waiting = scope.stopped = [];
+ scope.utils = 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 = [];
rpc.subscribe('tellActive', [], function(data) {
console.log('got active data');
scope.$apply(function() {
- scope.active = data[0].map(scope.normalize);
+ scope.mapDownloads(data[0], scope.active);
});
});
rpc.subscribe('tellWaiting', [0, 100], function(data) {
scope.$apply(function() {
- scope.waiting = data[0].map(scope.normalize);
+ scope.mapDownloads(data[0], scope.waiting);
});
});
rpc.subscribe('tellStopped', [0, 100], function(data) {
scope.$apply(function() {
- scope.stopped = data[0].map(scope.normalize);
+ scope.mapDownloads(data[0], scope.stopped);
});
});
scope.getDownloads = function() {
var rets = scope.active
- .concat(scope.waiting).concat(scope.stopped)
+ .concat(scope.waiting).concat(scope.stopped);
+ window.scope = scope;
+
return rets;
}
+ scope.mapDownloads = function(downs, mdowns) {
+ if (!mdowns) mdowns = [];
- scope.normalize = function(d) {
- return d;
+ for (i = 0; i < mdowns.length; i++) {
+ if (i >= downs.length) {
+ // remove the deleted downloads
+ mdowns.splice(i, mdowns.length - downs.length);
+ break;
+ }
+ if (!mdowns[i]) mdowns[i] = {};
+
+ scope.getCtx(downs[i], mdowns[i]);
+ }
+
+ while (i < downs.length) {
+ mdowns.push(scope.getCtx(downs[i++]));
+ }
+
+ return mdowns;
+ }
+
+ scope.getCtx = function(d, ctx) {
+ ctx = ctx || {};
+ _.each(scope.props, function(p) {
+ ctx[p] = d[p];
+ });
+
+ var path = (data.files[0].path || data.files[0].uris[0].uri);
+ ctx.name = utils.getFileName(path);
+
+ if (d.bittorrent && d.bittorrent.info) {
+ name = d.bittorrent.info.name;
+ }
+
+ ctx.remainingLength = d.totalLength - d.completedLength;
+ ctx.eta = ctx.remainingLength / ctx.downloadSpeed;
+
+ return ctx;
}
}]);
diff --git a/js/services/utils.js b/js/services/utils.js
index ad24233..7faa1d2 100644
--- a/js/services/utils.js
+++ b/js/services/utils.js
@@ -1,5 +1,9 @@
app.factory('$utils', function() {
return {
+ getFileName: function(path) {
+ var seed = path.split(/[/\\]/);
+ return seed[seed.length - 1];
+ },
randStr: function() {
var str = [];
var hexDigits = "0123456789abcdef";
|