public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH widget-toolkit 1/4] Utils: add several render functions from PVE
Date: Mon, 19 Apr 2021 13:00:41 +0200	[thread overview]
Message-ID: <20210419110048.20791-2-d.csapak@proxmox.com> (raw)
In-Reply-To: <20210419110048.20791-1-d.csapak@proxmox.com>

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





  reply	other threads:[~2021-04-19 11:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-19 11:00 [pve-devel] [PATCH widget-toolkit/pve-manager] move some code to widget-toolkit Dominik Csapak
2021-04-19 11:00 ` Dominik Csapak [this message]
2021-04-19 11:00 ` [pve-devel] [PATCH widget-toolkit 2/4] bring over some icons from PVE Dominik Csapak
2021-04-19 11:00 ` [pve-devel] [PATCH widget-toolkit 3/4] Utils: refactor updateColumns from pve-manager Dominik Csapak
2021-04-19 11:00 ` [pve-devel] [PATCH widget-toolkit 4/4] panel: add StatusView from PVE Dominik Csapak
2021-04-22 18:38   ` [pve-devel] applied: " Thomas Lamprecht
2021-04-19 11:00 ` [pve-devel] [PATCH manager 1/4] ui: Utils: use render functions from widget-toolkit Dominik Csapak
2021-04-19 11:00 ` [pve-devel] [PATCH manager 2/4] ui: use some icons " Dominik Csapak
2021-04-19 11:00 ` [pve-devel] [PATCH manager 3/4] ui: Utils: use updateColumns " Dominik Csapak
2021-04-19 11:00 ` [pve-devel] [PATCH manager 4/4] ui: panel/StatusView: use from widget-toolkit instead Dominik Csapak
2021-04-22 18:41 ` [pve-devel] applied: [PATCH widget-toolkit/pve-manager] move some code to widget-toolkit Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210419110048.20791-2-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal