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 <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2021-04-22 17:46:18 +02:00
parent 0d58bef75c
commit 9e663a6a64

View File

@ -841,13 +841,14 @@ utilities: {
return value; return value;
}, },
render_usage: function(val) { render_usage: val => (val*100).toFixed(2) + '%',
return (val*100).toFixed(2) + '%';
},
render_cpu_usage: function(val, max) { render_cpu_usage: function(val, max) {
return Ext.String.format(gettext('{0}% of {1}') + return Ext.String.format(
' ' + gettext('CPU(s)'), (val*100).toFixed(2), max); `${gettext('{0}% of {1}')} ${gettext('CPU(s)')}`,
(val*100).toFixed(2),
max,
);
}, },
render_size_usage: function(val, max) { render_size_usage: function(val, max) {
@ -864,32 +865,25 @@ utilities: {
return ''; return '';
} }
var maxcpu = record.data.maxcpu || 1; let maxcpu = record.data.maxcpu || 1;
if (!Ext.isNumeric(maxcpu) && maxcpu >= 1) { if (!Ext.isNumeric(maxcpu) && maxcpu >= 1) {
return ''; return '';
} }
let cpuText = maxcpu > 1 ? 'CPUs' : 'CPU';
var per = value * 100; let ratio = (value * 100).toFixed(1);
return `${ratio}% of ${maxcpu.toString()} ${cpuText}`;
return per.toFixed(1) + '% of ' + maxcpu.toString() + (maxcpu > 1 ? 'CPUs' : 'CPU');
}, },
render_size: function(value, metaData, record, rowIndex, colIndex, store) { render_size: function(value, metaData, record, rowIndex, colIndex, store) {
if (!Ext.isNumeric(value)) { if (!Ext.isNumeric(value)) {
return ''; return '';
} }
return Proxmox.Utils.format_size(value); return Proxmox.Utils.format_size(value);
}, },
render_cpu_model: function(cpuinfo) { render_cpu_model: function(cpu) {
return cpuinfo.cpus + " x " + cpuinfo.model + " (" + let socketText = cpu.sockets > 1 ? gettext('Sockets') : gettext('Socket');
cpuinfo.sockets.toString() + " " + return `${cpu.cpus} x ${cpu.model} (${cpu.sockets.toString()} ${socketText})`;
(cpuinfo.sockets > 1
? gettext('Sockets')
: gettext('Socket')
) + ")";
}, },
/* this is different for nodes */ /* this is different for nodes */