-
- - - - + + +
- {{download.name}} + + + + + + + + + + + + + + - - - - - - -
+ {{download.name}} + +
+ + + + -
    -
  • Time left: {{(download.totalLength-download.completedLength)/download.downloadSpeed}}
  • -
  • Download Speed: {{download.downloadSpeed}}
  • -
  • Progress: {{(download.completedLength / download.totalLength)*100}}%
  • + + + + -
    -
    +
    +
+
    + +
  • Status: {{download.status}}
  • +
  • ETA: {{download.eta}}
  • +
  • Size: {{download.totalLength}}
  • +
  • Downloaded: {{download.completedLength}}
  • +
  • Progress: {{download.percentage}}%
  • +
  • Speed: {{download.downloadSpeed}}
  • + +
  • Upload Speed: {{download.uploadSpeed}}
  • + +
  • Status: {{download.status}}
  • +
  • Size: {{download.totalLength}}
  • +
  • Downloaded: {{download.completedLength}}
  • +
  • Path: {{download.dir}}
  • + +
  • Status: {{download.status}}
  • +
  • Path: {{download.dir}}
  • +
  • Size: {{download.totalLength}}
  • + +
  • Status: {{download.status}}
  • +
  • Path: {{download.dir}}
  • +
  • Size: {{download.totalLength}}
  • + +
  • Status: {{download.status}}
  • +
  • Path: {{download.dir}}
  • +
  • Size: {{download.totalLength}}
  • + +
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+ +
    +
  • Status: {{download.status}}
  • +
  • GID: {{download.gid}}
  • +
  • Dir: {{download.dir}}
  • +
  • Size: {{download.totalLength}}
  • +
  • Downloaded: {{download.completedLength}}
  • +
  • Num of Pieces: {{download.numPieces}}
  • +
  • Piece Length: {{download.pieceLength}}
  • +
  • ETA: {{download.eta}}
  • +
  • Down Speed: {{download.downloadSpeed}}
  • + +
  • Upload Speed: {{download.uploadSpeed}}
  • +
  • Upload Length: {{download.uploadLength}}
  • + +
  • Connections: {{download.connections}}
  • +
+ +

Download Files

+
    +
  • {{download.download.path}} ({{download.download.length}})
  • +
+ +
+
-
-
- - - -
-
-
- -
    -
  • 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

-
    -
  • {{file.path}} ({{file.completedLength}})
  • -
- -
-
-
-
-
- - -
- -
+ +
diff --git a/index.html b/index.html index c50c6b5..1342b3e 100755 --- a/index.html +++ b/index.html @@ -102,9 +102,9 @@ @@ -188,23 +188,23 @@
  • Status: {{status}}
  • GID: {{gid}}
  • Dir: {{dir}}
  • -
  • Size: {{size}}
  • -
  • Downloaded: {{downloaded}}
  • +
  • Size: {{totalLength}}
  • +
  • Downloaded: {{completedLength}}
  • Num of Pieces: {{numPieces}}
  • Piece Length: {{pieceLength}}
  • ETA: {{eta}}
  • -
  • Down Speed: {{down_speed}}
  • - {{#bittorrent}} -
  • Upload Speed: {{upload_speed}}
  • +
  • Down Speed: {{downloadSpeed}}
  • + {{#booleans.bittorrent}} +
  • Upload Speed: {{uploadSpeed}}
  • Upload Length: {{uploadLength}}
  • - {{/bittorrent}} + {{/booleans.bittorrent}}
  • Connections: {{connections}}
  • Download Files

    diff --git a/js/ctrls/download.js b/js/ctrls/download.js index a7ba727..195de17 100644 --- a/js/ctrls/download.js +++ b/js/ctrls/download.js @@ -1,6 +1,5 @@ app.controller('DownloadCtrl', [ '$scope', '$rpc', '$utils', function(scope, rpc, utils) { - scope.utils = utils; scope.props = [ 'gid', 'status', 'totalLength', 'completedLength', 'uploadLength', 'downloadSpeed', 'uploadSpeed', @@ -33,11 +32,10 @@ function(scope, rpc, utils) { }); scope.getDownloads = function() { - var rets = scope.active + var downs = scope.active .concat(scope.waiting).concat(scope.stopped); - window.scope = scope; - return rets; + return downs; } scope.mapDownloads = function(downs, mdowns) { if (!mdowns) mdowns = []; @@ -53,6 +51,7 @@ function(scope, rpc, utils) { scope.getCtx(downs[i], mdowns[i]); } + // insert newly created downloads while (i < downs.length) { mdowns.push(scope.getCtx(downs[i++])); } @@ -60,21 +59,66 @@ function(scope, rpc, utils) { return mdowns; } + scope.getCtx = function(d, ctx) { ctx = ctx || {}; - _.each(scope.props, function(p) { - ctx[p] = d[p]; + + ctx.status = d.status; + ctx.gid = d.gid; + ctx.numPieces = d.numPieces; + ctx.connections = d.connections; + ctx.dir = d.dir.replace(/\\/g, '/'); + + ctx.files = _.map(d.files, function(e) { + e.length = utils.changeLength(e.length, "B"); + e.path = e.path.replace(/\\/g, '/').replace(ctx.dir, '.'); + return e; }); - var path = (d.files[0].path || d.files[0].uris[0].uri); - ctx.name = utils.getFileName(path); + _.each(['downloadSpeed', 'uploadSpeed'], function(e) { + ctx[e] = utils.changeLength(d[e], 'B/s'); + }); + + _.each([ + 'totalLength', /*'remainingLength',*/ 'completedLength', + 'uploadLength', 'pieceLength' + ], function(e) { + ctx[e] = utils.changeLength(d[e], 'B'); + }); + + ctx.eta = utils.changeTime( + (d.remainingLength) / d.downloadSpeed + ); + + var percentage = (d.completedLength / d.totalLength)*100; + percentage = percentage.toFixed(2); + if(!percentage) percentage = 0; + + ctx.percentage = percentage; if (d.bittorrent && d.bittorrent.info) { - name = d.bittorrent.info.name; + ctx.name = d.bittorrent.info.name; + } + else { + ctx.name = utils.getFileName(ctx.files[0].path || ctx.files[0].uris[0].uri); } - ctx.remainingLength = d.totalLength - d.completedLength; - ctx.eta = ctx.remainingLength / ctx.downloadSpeed; + 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", + is_removed: ctx.status === "removed", + has_settings: ["active", "waiting", "paused"].indexOf(ctx.status) != -1, + can_pause: type == "active", + can_play: type == "waiting", + bittorrent: !!d.bittorrent, + can_restart: type == "stopped" + }; return ctx; } diff --git a/js/script.js b/js/script.js index 26187f1..a5bd9b6 100755 --- a/js/script.js +++ b/js/script.js @@ -359,58 +359,69 @@ function getChunksFromHex(bitfield, numOfPieces) { return chunks; } function getTemplateCtx(data) { - var percentage =(data.completedLength / data.totalLength)*100; + var obj = { + status: data.status, + gid: data.gid, + numPieces: data.numPieces, + connections: data.connections, + bittorrent: data.bittorrent + }; + + obj.files = data.files.map(function(e) { + e.length = changeLength(e.length, "B"); + e.path = e.path.replace(/\\/g, '/').replace(obj.dir, '.'); + return e; + }); + + _.each(['downloadSpeed', 'uploadSpeed'], function(e) { + obj[e] = changeLength(data[e], 'B/s'); + }); + + _.each([ + 'totalLength', 'completedLength', 'uploadLength', 'pieceLength' + ], function(e) { + obj[e] = changeLength(data[e], 'B'); + }); + + obj.eta = changeTime((data.totalLength-data.completedLength)/data.downloadSpeed); + + var percentage = (data.completedLength / data.totalLength)*100; percentage = percentage.toFixed(2); if(!percentage) percentage = 0; - var name; - var seed = (data.files[0].path || data.files[0].uris[0].uri).split(/[/\\]/); - name = seed[seed.length - 1]; - if (data.bittorrent && data.bittorrent.info) { - name = data.bittorrent.info.name; - } - var chunks = percentage !== 100 && data.bitfield ? getChunksFromHex(data.bitfield, data.numPieces) : []; - var eta = changeTime((data.totalLength-data.completedLength)/data.downloadSpeed); + obj.percentage = percentage; + + if (obj.bittorrent && obj.bittorrent.info) { + obj.name = obj.bittorrent.info.name; + } + else { + var seed = (obj.files[0].path || obj.files[0].uris[0].uri).split(/[/\\]/); + obj.name = seed[seed.length - 1]; + } + var type = data.status; if (type == "paused") type = "waiting"; - if (type == "error" || type == "removed" || type == "complete") type = "stopped"; + if (["error", "removed", "complete"].indexOf(type) != -1) + type = "stopped"; - data.dir = data.dir.replace(/\\/g, '/'); - return { - name: name, - sett_name: name.substr(0,name.lastIndexOf('.')) || name, - status: data.status, - type: type, - percentage:percentage, - gid: data.gid, - size: changeLength(data.totalLength, "B"), - down_speed: changeLength(data.downloadSpeed, "B/s"), - remaining: changeLength(data.totalLength - data.completedLength, "B"), - eta: eta, - downloaded: changeLength(data.completedLength, "B"), - dir: data.dir, - numPieces: data.numPieces, - pieceLength: changeLength(data.pieceLength, "B"), - uploadLength: changeLength(data.uploadLength, "B"), - connections: data.connections, - upload_speed: changeLength(data.uploadSpeed, "B/s"), - booleans: { - is_error: data.status === "error", - is_complete: data.status === "complete", - is_removed: data.status === "removed", - has_settings: ["active", "waiting", "paused"].indexOf(data.status) != -1, - can_pause: type == "active", - can_play: type == "waiting", - can_restart: type == "stopped" - }, - chunks: chunks, - files: data.files.map(function(e) { - e.size = changeLength(e.length, "B"); - e.path = e.path.replace(/\\/g, '/').replace(data.dir, '.'); - return e - }), - bittorrent: !!data.bittorrent + obj.type = type; + + obj.dir = data.dir.replace(/\\/g, '/'); + + obj.chunks = percentage !== 100 && data.bitfield ? getChunksFromHex(data.bitfield, data.numPieces) : []; + + obj.booleans = { + is_error: obj.status === "error", + is_complete: obj.status === "complete", + is_removed: obj.status === "removed", + has_settings: ["active", "waiting", "paused"].indexOf(obj.status) != -1, + can_pause: type == "active", + can_play: type == "waiting", + bittorrent: !!obj.bittorrent, + can_restart: type == "stopped" }; + + return obj; } function updateDownloadTemplates(elem, ctx) { elem = $(elem);