From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <d.csapak@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id 3E37F7480F
 for <pve-devel@lists.proxmox.com>; Mon, 19 Apr 2021 13:00:51 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 395F614574
 for <pve-devel@lists.proxmox.com>; Mon, 19 Apr 2021 13:00:51 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [212.186.127.180])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS id BAB0D1443D
 for <pve-devel@lists.proxmox.com>; Mon, 19 Apr 2021 13:00:49 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 83B5645B65
 for <pve-devel@lists.proxmox.com>; Mon, 19 Apr 2021 13:00:49 +0200 (CEST)
From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Mon, 19 Apr 2021 13:00:41 +0200
Message-Id: <20210419110048.20791-2-d.csapak@proxmox.com>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20210419110048.20791-1-d.csapak@proxmox.com>
References: <20210419110048.20791-1-d.csapak@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.159 Adjusted score from AWL reputation of From: address
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 RCVD_IN_DNSWL_MED        -2.3 Sender listed at https://www.dnswl.org/,
 medium trust
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: [pve-devel] [PATCH widget-toolkit 1/4] Utils: add several render
 functions from PVE
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Mon, 19 Apr 2021 11:00:51 -0000

we need the 'render_cpu_model' and '*_usage' methods in PBS,
the rest are the dependencies

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 src/Utils.js | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)

diff --git a/src/Utils.js b/src/Utils.js
index 3fd8f91..9d785a8 100644
--- a/src/Utils.js
+++ b/src/Utils.js
@@ -841,6 +841,66 @@ utilities: {
 	return value;
     },
 
+    render_usage: function(val) {
+	return (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);
+    },
+
+    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}'),
+	    Proxmox.Utils.render_size(val), Proxmox.Utils.render_size(max)) + ')';
+    },
+
+    render_cpu: function(value, metaData, record, rowIndex, colIndex, store) {
+	if (!(record.data.uptime && Ext.isNumeric(value))) {
+	    return '';
+	}
+
+	var 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');
+    },
+
+    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')
+	    ) + ")";
+    },
+
+    /* this is different for nodes */
+    render_node_cpu_usage: function(value, record) {
+	return Proxmox.Utils.render_cpu_usage(value, record.cpus);
+    },
+
+    render_node_size_usage: function(record) {
+	return Proxmox.Utils.render_size_usage(record.used, record.total);
+    },
+
     loadTextFromFile: function(file, callback, maxBytes) {
 	let maxSize = maxBytes || 8192;
 	if (file.size > maxSize) {
-- 
2.20.1