2013-01-29 13:47:40 +01:00
|
|
|
angular
|
|
|
|
.module('webui.filters.bytes', [])
|
|
|
|
.filter('changeLength', function() {
|
2013-01-22 08:53:30 +01:00
|
|
|
return function(len, pref) {
|
|
|
|
len = parseFloat(len);
|
2013-03-16 09:13:06 +01:00
|
|
|
if (len <= (1<<10)) return len.toFixed(1) + " " + pref;
|
2013-01-22 08:53:30 +01:00
|
|
|
else if(len <= (1<<20)) return (len/(1<<10)).toFixed(1) + " K" + pref;
|
|
|
|
else if(len <= (1<<30)) return (len/(1<<20)).toFixed(1) + " M" + pref;
|
|
|
|
else return (len/(1<<30)).toFixed(1) + " G" + pref;
|
|
|
|
};
|
2013-01-29 13:47:40 +01:00
|
|
|
})
|
|
|
|
.filter('blength', ['$filter', function(filter) {
|
2013-01-22 08:53:30 +01:00
|
|
|
return function(len) {
|
|
|
|
return filter('changeLength')(len, 'B');
|
|
|
|
};
|
2013-01-29 13:47:40 +01:00
|
|
|
}])
|
|
|
|
.filter('bspeed', ['$filter', function(filter) {
|
2013-01-22 08:53:30 +01:00
|
|
|
return function(speed) {
|
|
|
|
return filter('changeLength')(speed, 'B/s');
|
|
|
|
};
|
2013-01-29 13:47:40 +01:00
|
|
|
}])
|
|
|
|
.filter('time', function() {
|
2013-01-22 08:53:30 +01:00
|
|
|
return function(time) {
|
|
|
|
time = parseFloat(time);
|
|
|
|
if (isNaN(time) || !isFinite(time)) return " infinite";
|
|
|
|
if (!time) return " infinite";
|
|
|
|
if (time < 60) return time.toFixed(2) + " s";
|
|
|
|
else if (time < 60*60) return (time/60).toFixed(2) + " min";
|
|
|
|
else if (time < 60*60*24) return (time/(60*60)).toFixed(2) + " hours";
|
|
|
|
else return (time/(60*60*24)).toFixed(2) + " days!";
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|