From b1f7d01a716be3f23abd34e86b6ce35fe7e255ee Mon Sep 17 00:00:00 2001 From: ralf Date: Sun, 11 Feb 2024 13:56:53 +0200 Subject: [PATCH] fix invalid display for negative values (eg. showing growth/shrinkage) and preserve empty ("" or undefined), not show 0B --- api/js/etemplate/et2_widget_vfs.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/api/js/etemplate/et2_widget_vfs.ts b/api/js/etemplate/et2_widget_vfs.ts index f490614992..941b7a7f90 100644 --- a/api/js/etemplate/et2_widget_vfs.ts +++ b/api/js/etemplate/et2_widget_vfs.ts @@ -510,7 +510,7 @@ export class et2_vfsSize extends et2_description { static readonly _attributes : any = { "value": { - "type": "integer" + "type": "any" // not using "integer", as we use parseInt on everything not a number, but want to show empty of "" or undefined, not 0B } }; /** @@ -531,9 +531,15 @@ export class et2_vfsSize extends et2_description { size = parseInt(size); } - if(!size) + if(Number.isNaN(size)) { - size = 0; + return ''; + } + let sign = ''; + if (size < 0) + { + sign = '-'; + size = -size; } const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; let i = 0; @@ -542,7 +548,7 @@ export class et2_vfsSize extends et2_description size /= 1024; ++i; } - return size.toFixed(i == 0 ? 0 : 1) + ' ' + units[i]; + return sign+size.toFixed(i == 0 ? 0 : 1) + ' ' + units[i]; } set_value(_value)