From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 C0A5474884 for ; Mon, 19 Apr 2021 13:00:53 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 41C8914620 for ; Mon, 19 Apr 2021 13:00:53 +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)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 6241D144CB for ; Mon, 19 Apr 2021 13:00:50 +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 289F745AFE for ; Mon, 19 Apr 2021 13:00:50 +0200 (CEST) From: Dominik Csapak To: pve-devel@lists.proxmox.com Date: Mon, 19 Apr 2021 13:00:44 +0200 Message-Id: <20210419110048.20791-5-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 4/4] panel: add StatusView from PVE X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Apr 2021 11:00:53 -0000 with 2 minor fixups: * one lint error * binding of the 'updateValues' function in the event (we want to avoid breaking this when used in a context where a controller exists, in that case using a string will only look in the controller and not in the component itself anymore, so use the function directly) Signed-off-by: Dominik Csapak --- src/Makefile | 1 + src/panel/StatusView.js | 125 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 src/panel/StatusView.js diff --git a/src/Makefile b/src/Makefile index f97c74a..9e3ad4e 100644 --- a/src/Makefile +++ b/src/Makefile @@ -53,6 +53,7 @@ JSSRC= \ panel/ACMEAccount.js \ panel/ACMEPlugin.js \ panel/ACMEDomains.js \ + panel/StatusView.js \ window/Edit.js \ window/PasswordEdit.js \ window/SafeDestroy.js \ diff --git a/src/panel/StatusView.js b/src/panel/StatusView.js new file mode 100644 index 0000000..059508a --- /dev/null +++ b/src/panel/StatusView.js @@ -0,0 +1,125 @@ +Ext.define('Proxmox.panel.StatusView', { + extend: 'Ext.panel.Panel', + alias: 'widget.pmxStatusView', + + layout: { + type: 'column', + }, + + title: gettext('Status'), + + getRecordValue: function(key, store) { + if (!key) { + throw "no key given"; + } + var me = this; + + if (store === undefined) { + store = me.getStore(); + } + + var rec = store.getById(key); + if (rec) { + return rec.data.value; + } + + return ''; + }, + + fieldRenderer: function(val, max) { + if (max === undefined) { + return val; + } + + if (!Ext.isNumeric(max) || max === 1) { + return Proxmox.Utils.render_usage(val); + } + return Proxmox.Utils.render_size_usage(val, max); + }, + + fieldCalculator: function(used, max) { + if (!Ext.isNumeric(max) && Ext.isNumeric(used)) { + return used; + } else if (!Ext.isNumeric(used)) { + /* we come here if the field is from a node + * where the records are not mem and maxmem + * but mem.used and mem.total + */ + if (used.used !== undefined && + used.total !== undefined) { + return used.used/used.total; + } + } + + return used/max; + }, + + updateField: function(field) { + var me = this; + var renderer = me.fieldRenderer; + if (Ext.isFunction(field.renderer)) { + renderer = field.renderer; + } + if (field.multiField === true) { + field.updateValue(renderer.call(field, me.getStore().getRecord())); + } else if (field.textField !== undefined) { + field.updateValue(renderer.call(field, me.getRecordValue(field.textField))); + } else if (field.valueField !== undefined) { + var used = me.getRecordValue(field.valueField); + /* string and int */ + var max = field.maxField !== undefined ? me.getRecordValue(field.maxField) : 1; + + var calculate = me.fieldCalculator; + + if (Ext.isFunction(field.calculate)) { + calculate = field.calculate; + } + field.updateValue(renderer.call(field, used, max), calculate(used, max)); + } + }, + + getStore: function() { + var me = this; + if (!me.rstore) { + throw "there is no rstore"; + } + + return me.rstore; + }, + + updateTitle: function() { + var me = this; + me.setTitle(me.getRecordValue('name')); + }, + + updateValues: function(store, records, success) { + if (!success) { + return; // do not update if store load was not successful + } + var me = this; + var itemsToUpdate = me.query('pmxInfoWidget'); + + itemsToUpdate.forEach(me.updateField, me); + + me.updateTitle(store); + }, + + initComponent: function() { + var me = this; + + if (!me.rstore) { + throw "no rstore given"; + } + + if (!me.title) { + throw "no title given"; + } + + Proxmox.Utils.monStoreErrors(me, me.rstore); + + me.callParent(); + + me.mon(me.rstore, 'load', me.updateValues, me); + }, + +}); -- 2.20.1