rounding of statistics changed to fixed decimal places
This commit is contained in:
parent
8253f611ef
commit
4f6c98c563
10
index.html
10
index.html
|
@ -22,6 +22,7 @@
|
||||||
<script src="js/libs/bootstrap.js"></script>
|
<script src="js/libs/bootstrap.js"></script>
|
||||||
<script src="js/libs/mustache.js"></script>
|
<script src="js/libs/mustache.js"></script>
|
||||||
|
|
||||||
|
<!--{{{ active downloads template start -->
|
||||||
<script type="text/mustache" id="download_active_template">
|
<script type="text/mustache" id="download_active_template">
|
||||||
<div class="row download_active_item" data-gid="{{gid}}">
|
<div class="row download_active_item" data-gid="{{gid}}">
|
||||||
<div class="span4" style="overflow: hidden;">
|
<div class="span4" style="overflow: hidden;">
|
||||||
|
@ -47,6 +48,9 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</script>
|
</script>
|
||||||
|
<!-- active downloads template end }}}-->
|
||||||
|
|
||||||
|
<!--{{{ waiting downloads template start -->
|
||||||
<script type="text/mustache" id="download_waiting_template">
|
<script type="text/mustache" id="download_waiting_template">
|
||||||
<div class="row download_waiting_item" data-gid="{{gid}}">
|
<div class="row download_waiting_item" data-gid="{{gid}}">
|
||||||
<div class="span4" style="overflow: hidden;">
|
<div class="span4" style="overflow: hidden;">
|
||||||
|
@ -56,6 +60,7 @@
|
||||||
<span class="badge badge-warning">Status: {{status}}</span>
|
<span class="badge badge-warning">Status: {{status}}</span>
|
||||||
<b style='display:inline; float:right;'>
|
<b style='display:inline; float:right;'>
|
||||||
<span class="label label-warning">Size: {{size}}</span> |
|
<span class="label label-warning">Size: {{size}}</span> |
|
||||||
|
<span class="label label-warning">Remaining: {{remaining}}</span> |
|
||||||
<span class="label label-warning">Progress: {{percentage}}%</span>
|
<span class="label label-warning">Progress: {{percentage}}%</span>
|
||||||
</b>
|
</b>
|
||||||
</div>
|
</div>
|
||||||
|
@ -71,6 +76,9 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</script>
|
</script>
|
||||||
|
<!-- waiting downloads template end }}}-->
|
||||||
|
|
||||||
|
<!--{{{ stopped downloads template start -->
|
||||||
<script type="text/mustache" id="download_stopped_template">
|
<script type="text/mustache" id="download_stopped_template">
|
||||||
<div class="row download_stopped_item" data-gid="{{gid}}">
|
<div class="row download_stopped_item" data-gid="{{gid}}">
|
||||||
<div class="span4" style="overflow: hidden;">
|
<div class="span4" style="overflow: hidden;">
|
||||||
|
@ -80,6 +88,7 @@
|
||||||
<span class="badge badge-important">Status: {{status}}</span>
|
<span class="badge badge-important">Status: {{status}}</span>
|
||||||
<b style='display:inline; float:right;'>
|
<b style='display:inline; float:right;'>
|
||||||
<span class="label label-important">Size: {{size}}</span> |
|
<span class="label label-important">Size: {{size}}</span> |
|
||||||
|
<span class="label label-important">Downloaded: {{downloaded}}</span> |
|
||||||
<span class="label label-important">Progress: {{percentage}}%</span>
|
<span class="label label-important">Progress: {{percentage}}%</span>
|
||||||
</b>
|
</b>
|
||||||
</div>
|
</div>
|
||||||
|
@ -95,6 +104,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</script>
|
</script>
|
||||||
|
<!-- stopped downloads template end }}}-->
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
|
|
101
js/script.js
101
js/script.js
|
@ -159,18 +159,44 @@ var d_files = {
|
||||||
function changeLength(len, pref) {
|
function changeLength(len, pref) {
|
||||||
len = parseInt(len);
|
len = parseInt(len);
|
||||||
if(len <= 1000) return len + " " + pref;
|
if(len <= 1000) return len + " " + pref;
|
||||||
else if(len <= 1000000) return Math.round(len/1000 * 10)/10 + " k" + pref;
|
else if(len <= 1000000) return (len/1000).toFixed(1) + " k" + pref;
|
||||||
else if(len <= 1000000000) return Math.round(len/1000000 *10)/10 + " m" + pref;
|
else if(len <= 1000000000) return (len/1000000).toFixed(1) + " m" + pref;
|
||||||
else if(len <= 1000000000000) return Math.round(len/1000000000 *10)/10 + " g" + pref;
|
else if(len <= 1000000000000) return (len/1000000000).toFixed(1) + " g" + pref;
|
||||||
}
|
}
|
||||||
function changeTime(time) {
|
function changeTime(time) {
|
||||||
time = parseInt(time);
|
time = parseInt(time);
|
||||||
if(time < 60) return time + " s";
|
if(time < 60) return time + " s";
|
||||||
else if(time < 60*60) return Math.round(time/60 *100)/100 + " min";
|
else if(time < 60*60) return (time/60).toFixed(2) + " min";
|
||||||
else if(time < 60*60*24) return Math.round(time/(60*60) *100)/100 + " hours";
|
else if(time < 60*60*24) return (time/(60*60)).toFixed(2) + " hours";
|
||||||
else return Math.round(time/(60*60*24) *100)/100 + " days!!";
|
else return (time/(60*60*24)).toFixed(2) + " days!!";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
function getTemplateCtx(data) {
|
||||||
|
var percentage =(data.completedLength / data.totalLength)*100;
|
||||||
|
percentage = percentage.toFixed(2);
|
||||||
|
if(!percentage) percentage = 0;
|
||||||
|
var name;
|
||||||
|
if(data.files[0].uris.length) {
|
||||||
|
name = data.files[0].uris[0].uri.replace(/^.*[\\\/]/, '');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
name = data.files[0].path.replace(/^.*[\\\/\]]/, '');
|
||||||
|
}
|
||||||
|
|
||||||
|
var eta = changeTime((data.totalLength-data.completedLength)/data.downloadSpeed);
|
||||||
|
if(!eta) eta = "infinite";
|
||||||
|
return {
|
||||||
|
name: name,
|
||||||
|
status: data.status,
|
||||||
|
percentage:percentage,
|
||||||
|
gid: data.gid,
|
||||||
|
size: changeLength(data.totalLength, "b"),
|
||||||
|
down: changeLength(data.downloadSpeed, "b/s"),
|
||||||
|
remaining: changeLength(data.totalLength - data.completedLength, "b"),
|
||||||
|
eta: eta,
|
||||||
|
downloaded: changeLength(data.completedLength, "b")
|
||||||
|
};
|
||||||
|
}
|
||||||
function updateActiveDownloads(data) {
|
function updateActiveDownloads(data) {
|
||||||
var down_template = $('#download_active_template').text();
|
var down_template = $('#download_active_template').text();
|
||||||
$('#active_downloads').html("");
|
$('#active_downloads').html("");
|
||||||
|
@ -178,26 +204,7 @@ function updateActiveDownloads(data) {
|
||||||
$('#active_downloads').append('no active downloads yet!!!!');
|
$('#active_downloads').append('no active downloads yet!!!!');
|
||||||
}
|
}
|
||||||
for(var i = 0; i < data.length; i++) {
|
for(var i = 0; i < data.length; i++) {
|
||||||
var percentage =(data[i].completedLength / data[i].totalLength)*100;
|
var ctx = getTemplateCtx(data[i]);
|
||||||
percentage = Math.round(percentage*100)/100;
|
|
||||||
if(!percentage) percentage = 0;
|
|
||||||
var name;
|
|
||||||
if(data[i].files[0].uris.length) {
|
|
||||||
name = data[i].files[0].uris[0].uri.replace(/^.*[\\\/]/, '');
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
name = data[i].files[0].path.replace(/^.*[\\\/\]]/, '');
|
|
||||||
}
|
|
||||||
ctx = {
|
|
||||||
name: name,
|
|
||||||
status: data[i].status,
|
|
||||||
percentage:percentage,
|
|
||||||
gid: data[i].gid,
|
|
||||||
size: changeLength(data[i].totalLength, "b"),
|
|
||||||
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);
|
var item = Mustache.render(down_template, ctx);
|
||||||
$('#active_downloads').append(item);
|
$('#active_downloads').append(item);
|
||||||
}
|
}
|
||||||
|
@ -237,26 +244,7 @@ function updateWaitingDownloads(data) {
|
||||||
$('#waiting_downloads').append('no waiting downloads yet!!!!');
|
$('#waiting_downloads').append('no waiting downloads yet!!!!');
|
||||||
}
|
}
|
||||||
for(var i = 0; i < data.length; i++) {
|
for(var i = 0; i < data.length; i++) {
|
||||||
var percentage =(data[i].completedLength / data[i].totalLength)*100;
|
var ctx = getTemplateCtx(data[i]);
|
||||||
percentage = Math.round(percentage*100)/100;
|
|
||||||
if(!percentage) percentage = 0;
|
|
||||||
var name;
|
|
||||||
if(data[i].files[0].uris.length) {
|
|
||||||
name = data[i].files[0].uris[0].uri.replace(/^.*[\\\/]/, '');
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
name = data[i].files[0].path.replace(/^.*[\\\/\]]/, '');
|
|
||||||
}
|
|
||||||
ctx = {
|
|
||||||
name: name,
|
|
||||||
status: data[i].status,
|
|
||||||
percentage:percentage,
|
|
||||||
gid: data[i].gid,
|
|
||||||
size: changeLength(data[i].totalLength, "b"),
|
|
||||||
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);
|
var item = Mustache.render(down_template, ctx);
|
||||||
$('#waiting_downloads').append(item);
|
$('#waiting_downloads').append(item);
|
||||||
}
|
}
|
||||||
|
@ -297,26 +285,7 @@ function updateStoppedDownloads(data) {
|
||||||
$('#stopped_downloads').append('no stopped downloads yet!!!!');
|
$('#stopped_downloads').append('no stopped downloads yet!!!!');
|
||||||
}
|
}
|
||||||
for(var i = 0; i < data.length; i++) {
|
for(var i = 0; i < data.length; i++) {
|
||||||
var percentage =(data[i].completedLength / data[i].totalLength)*100;
|
var ctx = getTemplateCtx(data[i]);
|
||||||
percentage = Math.round(percentage*100)/100;
|
|
||||||
if(!percentage) percentage = 0;
|
|
||||||
var name;
|
|
||||||
if(data[i].files[0].uris.length) {
|
|
||||||
name = data[i].files[0].uris[0].uri.replace(/^.*[\\\/]/, '');
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
name = data[i].files[0].path.replace(/^.*[\\\/\]]/, '');
|
|
||||||
}
|
|
||||||
ctx = {
|
|
||||||
name: name,
|
|
||||||
status: data[i].status,
|
|
||||||
percentage:percentage,
|
|
||||||
gid: data[i].gid,
|
|
||||||
size: changeLength(data[i].totalLength, "b"),
|
|
||||||
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);
|
var item = Mustache.render(down_template, ctx);
|
||||||
$('#stopped_downloads').append(item);
|
$('#stopped_downloads').append(item);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user