eta time added to active downloads

This commit is contained in:
Hamza Zia 2012-06-06 13:17:39 +08:00
parent 2ea153d644
commit 7b8cdc9d6b
2 changed files with 22 additions and 9 deletions

View File

@ -29,9 +29,10 @@
</div>
<div class="span6">
<b style='display:inline; float:right;'>
<span class="label label-success">Size: {{size}}</span> |
<span class="label label-success">Remaining: {{remaining}}</span> |
<span class="label label-success">Progress: {{percentage}}%</span> |
<span class="label label-success">Speed: {{down}}</span>
<span class="label label-success">Speed: {{down}}</span> |
<span class="label label-success">Time left: {{eta}}</span>
</b>
</div>
<div class="span2">

View File

@ -96,7 +96,8 @@ function newDownload() {
urls.push($(li[i]).text().trim());
}
alert(JSON.stringify(urls));
var inp_url = $('#newDownload_url').val().trim();
if(inp_url.length > 0) urls.push(inp_url);
addDownload([urls]);
}
@ -108,11 +109,16 @@ var d_files = {
function changeLength(len, pref) {
len = parseInt(len);
if(len <= 1000) return len + " " + pref;
else if(len <= 1000000) return Math.round(len/1000 * 100)/100 + " k" + pref;
else if(len <= 1000000000) return Math.round(len/1000000 *100)/100 + " m" + pref;
else if(len <= 1000000000000) return Math.round(len/1000000000 *100)/100 + " g" + pref;
else if(len <= 1000000) return Math.round(len/1000 * 10)/10 + " k" + pref;
else if(len <= 1000000000) return Math.round(len/1000000 *10)/10 + " m" + pref;
else if(len <= 1000000000000) return Math.round(len/1000000000 *10)/10 + " g" + pref;
}
function changeTime(time) {
time = parseInt(time);
if(time < 60) return time + " s";
else if(time < 60*60) return Math.round(time/60 *100)/100 + " min";
else if(time < 60*60*24) return Math.round(time/(60*60) *100)/100 + " hours";
else return Math.round(time/(60*60*24) *100)/100 + " days!!";
}
function updateActiveDownloads(data) {
@ -138,7 +144,9 @@ function updateActiveDownloads(data) {
percentage:percentage,
gid: data[i].gid,
size: changeLength(data[i].totalLength, "b"),
down: changeLength(data[i].downloadSpeed, "b/s")
down: changeLength(data[i].downloadSpeed, "b/s"),
remaining: changeLength(data[i].totalLength - data[i].completedLength, "b"),
eta: changeTime((data[i].totalLength-data[i].completedLength)/data[i].downloadSpeed)
};
var item = Mustache.render(down_template, ctx);
$('#active_downloads').append(item);
@ -195,7 +203,9 @@ function updateWaitingDownloads(data) {
percentage:percentage,
gid: data[i].gid,
size: changeLength(data[i].totalLength, "b"),
down: changeLength(data[i].downloadSpeed, "b/s")
down: changeLength(data[i].downloadSpeed, "b/s"),
remaining: changeLength(data[i].totalLength - data[i].completedLength, "b"),
eta: changeTime((data[i].totalLength-data[i].completedLength)/data[i].downloadSpeed)
};
var item = Mustache.render(down_template, ctx);
$('#waiting_downloads').append(item);
@ -253,7 +263,9 @@ function updateStoppedDownloads(data) {
percentage:percentage,
gid: data[i].gid,
size: changeLength(data[i].totalLength, "b"),
down: changeLength(data[i].downloadSpeed, "b/s")
down: changeLength(data[i].downloadSpeed, "b/s"),
remaining: changeLength(data[i].totalLength - data[i].completedLength, "b"),
eta: changeTime((data[i].totalLength-data[i].completedLength)/data[i].downloadSpeed)
};
var item = Mustache.render(down_template, ctx);
$('#stopped_downloads').append(item);