mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Fix sorting of sizes on the statistics views by sorting raw values and prettifying on the client side. Includes Jasmine tests for the prettyfying function. Fixes #2315
This commit is contained in:
committed by
Dave Page
parent
c32bf7780e
commit
94b7fc483a
24
web/pgadmin/static/js/size_prettify.js
Normal file
24
web/pgadmin/static/js/size_prettify.js
Normal file
@@ -0,0 +1,24 @@
|
||||
define([],
|
||||
function () {
|
||||
var sizePrettify = function (rawSize) {
|
||||
var size = Math.abs(rawSize),
|
||||
limit = 10 * 1024,
|
||||
limit2 = limit - 1,
|
||||
cnt = 0,
|
||||
sizeUnits = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB'];
|
||||
|
||||
if (size < limit)
|
||||
return size + ' ' + sizeUnits[cnt]; // return in bytes format
|
||||
else
|
||||
{
|
||||
do {
|
||||
size = size / 1024;
|
||||
cnt += 1;
|
||||
} while (size > limit2);
|
||||
|
||||
return Math.round(size) + ' ' + sizeUnits[cnt];
|
||||
}
|
||||
};
|
||||
|
||||
return sizePrettify;
|
||||
});
|
||||
Reference in New Issue
Block a user