Improve bytes formatting.
Also may or may not perform a bit better. Most likely the former.
This commit is contained in:
parent
09120284c5
commit
0f4ddbd155
|
@ -1,22 +1,28 @@
|
||||||
angular
|
(function() {
|
||||||
.module('webui.filters.bytes', [])
|
function fmtlen(len) {
|
||||||
.filter('changeLength', function() {
|
len = +len; // coerce to number
|
||||||
return function(len, pref) {
|
if (len <= 1024) {
|
||||||
len = parseFloat(len);
|
return len.toFixed(0) + " B";
|
||||||
if (len <= (1<<10)) return len.toFixed(1) + " " + pref;
|
}
|
||||||
else if(len <= (1<<20)) return (len/(1<<10)).toFixed(1) + " K" + pref;
|
len /= 1024;
|
||||||
else if(len <= (1<<30)) return (len/(1<<20)).toFixed(1) + " M" + pref;
|
if (len <= 1024) {
|
||||||
else return (len/(1<<30)).toFixed(1) + " G" + pref;
|
return len.toFixed(1) + " KB"
|
||||||
};
|
}
|
||||||
})
|
len /= 1024;
|
||||||
|
if (len <= 1024) {
|
||||||
|
return len.toFixed(2) + " MB";
|
||||||
|
}
|
||||||
|
len /= 1024;
|
||||||
|
return len.toFixed(3) + " GB";
|
||||||
|
}
|
||||||
|
|
||||||
|
angular .module('webui.filters.bytes', [])
|
||||||
.filter('blength', ['$filter', function(filter) {
|
.filter('blength', ['$filter', function(filter) {
|
||||||
return function(len) {
|
return fmtlen;
|
||||||
return filter('changeLength')(len, 'B');
|
|
||||||
};
|
|
||||||
}])
|
}])
|
||||||
.filter('bspeed', ['$filter', function(filter) {
|
.filter('bspeed', ['$filter', function(filter) {
|
||||||
return function(speed) {
|
return function(speed) {
|
||||||
return filter('changeLength')(speed, 'B/s');
|
return fmtlen(speed) + "/s";
|
||||||
};
|
};
|
||||||
}])
|
}])
|
||||||
.filter('time', function() {
|
.filter('time', function() {
|
||||||
|
@ -37,4 +43,5 @@ angular
|
||||||
return days + "::" + pad(hrs) + ":" + pad(mins) + ":" + pad(secs);
|
return days + "::" + pad(hrs) + ":" + pad(mins) + ":" + pad(secs);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
})();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user