]> git.proxmox.com Git - proxmox-widget-toolkit.git/commitdiff
utils: code cleanup and refactoring
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 22 Apr 2021 15:46:18 +0000 (17:46 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 22 Apr 2021 15:47:41 +0000 (17:47 +0200)
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>
src/Utils.js

index adff5f4886fe03f9a5510eac18319b91ed021946..5f4f2aed8744f239a319b756588e089f4a59fa61 100644 (file)
@@ -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 */