From 9e663a6a64735874c699ef43c2aa4f41d8c4897e Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Thu, 22 Apr 2021 17:46:18 +0200 Subject: [PATCH] utils: code cleanup and refactoring Looks like more change than it actually is, see `--word-diff=color --word-diff-regex='\w+'`. The single semantic change is the added space in the render_cpu, between the maxcpu value and CPU/s text Signed-off-by: Thomas Lamprecht --- src/Utils.js | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/src/Utils.js b/src/Utils.js index adff5f4..5f4f2ae 100644 --- a/src/Utils.js +++ b/src/Utils.js @@ -841,13 +841,14 @@ utilities: { return value; }, - render_usage: function(val) { - return (val*100).toFixed(2) + '%'; - }, + render_usage: val => (val*100).toFixed(2) + '%', render_cpu_usage: function(val, max) { - return Ext.String.format(gettext('{0}% of {1}') + - ' ' + gettext('CPU(s)'), (val*100).toFixed(2), max); + return Ext.String.format( + `${gettext('{0}% of {1}')} ${gettext('CPU(s)')}`, + (val*100).toFixed(2), + max, + ); }, render_size_usage: function(val, max) { @@ -864,32 +865,25 @@ utilities: { return ''; } - var maxcpu = record.data.maxcpu || 1; - + let maxcpu = record.data.maxcpu || 1; if (!Ext.isNumeric(maxcpu) && maxcpu >= 1) { return ''; } - - var per = value * 100; - - return per.toFixed(1) + '% of ' + maxcpu.toString() + (maxcpu > 1 ? 'CPUs' : 'CPU'); + let cpuText = maxcpu > 1 ? 'CPUs' : 'CPU'; + let ratio = (value * 100).toFixed(1); + return `${ratio}% of ${maxcpu.toString()} ${cpuText}`; }, render_size: function(value, metaData, record, rowIndex, colIndex, store) { if (!Ext.isNumeric(value)) { return ''; } - return Proxmox.Utils.format_size(value); }, - render_cpu_model: function(cpuinfo) { - return cpuinfo.cpus + " x " + cpuinfo.model + " (" + - cpuinfo.sockets.toString() + " " + - (cpuinfo.sockets > 1 - ? gettext('Sockets') - : gettext('Socket') - ) + ")"; + render_cpu_model: function(cpu) { + let socketText = cpu.sockets > 1 ? gettext('Sockets') : gettext('Socket'); + return `${cpu.cpus} x ${cpu.model} (${cpu.sockets.toString()} ${socketText})`; }, /* this is different for nodes */ -- 2.39.2