[pve-devel] [PATCH manager] fix 'NaN%' when max value is 0

Dominik Csapak d.csapak at proxmox.com
Wed Oct 12 12:04:36 CEST 2016


when we get a max value of 0
(for example when a storage is not active)

the render function would show:
'NaN% (0B of 0B)'

because of a division by 0

this patch simply returns 'N/A' because
a max value of 0 should never be valid

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 www/manager6/Utils.js | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/www/manager6/Utils.js b/www/manager6/Utils.js
index 4ec7d5b..f9f780b 100644
--- a/www/manager6/Utils.js
+++ b/www/manager6/Utils.js
@@ -1037,6 +1037,9 @@ Ext.define('PVE.Utils', { statics: {
     },
 
     render_size_usage: function(val, max) {
+	if (max === 0) {
+	    return gettext('N/A');
+	}
 	return (val*100/max).toFixed(2) + '% '+ '(' +
 	    Ext.String.format(gettext('{0} of {1}'),
 	    PVE.Utils.render_size(val), PVE.Utils.render_size(max)) + ')';
-- 
2.1.4





More information about the pve-devel mailing list