From: Noel Ullreich <n.ullreich@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH pve-manager 2/2] ui: fix: change units of memory/swap for containers
Date: Fri, 16 Jun 2023 11:54:10 +0200 [thread overview]
Message-ID: <20230616095410.33426-3-n.ullreich@proxmox.com> (raw)
In-Reply-To: <20230616095410.33426-1-n.ullreich@proxmox.com>
This patch adds a dropdown-menu (in the web interface) of units, MiB, GiB,
and TiB, (although PiB could easily be added in the future) for ram
and swapsize of containers.
Signed-off-by: Noel Ullreich <n.ullreich@proxmox.com>
---
www/manager6/lxc/ResourceEdit.js | 136 ++++++++++++++++++++++++++-----
1 file changed, 117 insertions(+), 19 deletions(-)
diff --git a/www/manager6/lxc/ResourceEdit.js b/www/manager6/lxc/ResourceEdit.js
index 9f4f7e08d..a5437e292 100644
--- a/www/manager6/lxc/ResourceEdit.js
+++ b/www/manager6/lxc/ResourceEdit.js
@@ -1,10 +1,10 @@
-var labelWidth = 120;
+let labelWidth = 100;
Ext.define('PVE.lxc.MemoryEdit', {
extend: 'Proxmox.window.Edit',
initComponent: function() {
- var me = this;
+ let me = this;
Ext.apply(me, {
subject: gettext('Memory'),
@@ -102,7 +102,7 @@ Ext.define('PVE.lxc.CPUInputPanel', {
],
initComponent: function() {
- var me = this;
+ let me = this;
me.column1 = [
{
@@ -122,6 +122,12 @@ Ext.define('PVE.lxc.CPUInputPanel', {
},
});
+let unitScalingFactor = [
+ { 'name': gettext('MiB'), 'factor': 1 },
+ { 'name': gettext('GiB'), 'factor': 1024 },
+ { 'name': gettext('TiB'), 'factor': 1024**2 },
+];
+
Ext.define('PVE.lxc.MemoryInputPanel', {
extend: 'Proxmox.panel.InputPanel',
alias: 'widget.pveLxcMemoryInputPanel',
@@ -130,29 +136,121 @@ Ext.define('PVE.lxc.MemoryInputPanel', {
insideWizard: false,
+ onGetValues: function(values) {
+ let me = this;
+ let ret = {};
+
+ ret.memory = values.memory*values.memorySize;
+ ret.swap = values.swap*values.swapSize;
+
+ return ret;
+ },
+
+ onSetValues: function(values) {
+ let me = this;
+ let ret = structuredClone(values);
+
+ for (let i in unitScalingFactor) {
+ if (Object.prototype.hasOwnProperty.call(unitScalingFactor, i)) {
+ if (values.memory%unitScalingFactor[i].factor===0) {
+ ret.memory = values.memory/unitScalingFactor[i].factor;
+ ret.memorySize = unitScalingFactor[i];
+ }
+ if (values.swap%unitScalingFactor[i].factor===0 && values.swap) {
+ ret.swap = values.swap/unitScalingFactor[i].factor;
+ ret.swapSize = unitScalingFactor[i];
+ }
+ }
+ }
+
+ return ret;
+ },
+
initComponent: function() {
- var me = this;
+ let me = this;
- var items = [
+ let items = [
{
- xtype: 'proxmoxintegerfield',
- name: 'memory',
- minValue: 16,
- value: '512',
- step: 32,
- fieldLabel: gettext('Memory') + ' (MiB)',
+ xtype: 'fieldcontainer',
+ layout: 'hbox',
labelWidth: labelWidth,
- allowBlank: false,
+ fieldLabel: gettext('Memory'),
+ items: [
+ {
+ xtype: 'proxmoxintegerfield',
+ name: 'memory',
+ flex: 2,
+ minValue: 16,
+ value: '512',
+ step: 32,
+ labelWidth: labelWidth,
+ allowBlank: false,
+ },
+ {
+ xtype: 'combobox',
+ name: 'memorySize',
+ itemId: 'memorySize',
+ value: unitScalingFactor[0], //set to MiB by default
+ flex: 1,
+ editable: false,
+ allowBlank: false,
+ store: unitScalingFactor,
+ displayField: 'name',
+ valueField: 'factor',
+ listeners: {
+ change: function(f, value) {
+ let mf = me.down('field[name=memory]');
+ if (value===1) {
+ mf.setMinValue(16);
+ mf.step=32;
+ } else {
+ mf.setMinValue(1);
+ mf.step=1;
+ }
+ mf.validate();
+ },
+ },
+ },
+ ],
},
{
- xtype: 'proxmoxintegerfield',
- name: 'swap',
- minValue: 0,
- value: '512',
- step: 32,
- fieldLabel: gettext('Swap') + ' (MiB)',
+ xtype: 'fieldcontainer',
+ layout: 'hbox',
labelWidth: labelWidth,
- allowBlank: false,
+ fieldLabel: gettext('Swap'),
+ items: [
+ {
+ xtype: 'proxmoxintegerfield',
+ name: 'swap',
+ flex: 2,
+ minValue: 0,
+ value: '512',
+ step: 32,
+ labelWidth: labelWidth,
+ allowBlank: false,
+ },
+ {
+ xtype: 'combobox',
+ name: 'swapSize',
+ itemId: 'swapSize',
+ value: unitScalingFactor[0], //set to MiB by default
+ flex: 1,
+ editable: false,
+ allowBlank: false,
+ store: unitScalingFactor,
+ displayField: 'name',
+ valueField: 'factor',
+ listeners: {
+ change: function(f, value) {
+ let sf = me.down('field[name=swap]');
+
+ sf.step = value===1 ? 32 : 1;
+
+ sf.validate();
+ },
+ },
+ },
+ ],
},
];
--
2.30.2
next prev parent reply other threads:[~2023-06-16 9:54 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-16 9:54 [pve-devel] [PATCH pve-manager 0/2] ui: fix #3760: change units of ram/swap Noel Ullreich
2023-06-16 9:54 ` [pve-devel] [PATCH pve-manager 1/2] ui: fix #3760: change unit of memory of a VM Noel Ullreich
2023-06-16 9:54 ` Noel Ullreich [this message]
2023-07-03 12:08 ` [pve-devel] [PATCH pve-manager 0/2] ui: fix #3760: change units of ram/swap Noel Ullreich
2023-07-07 12:29 ` Fiona Ebner
2023-07-27 10:30 [pve-devel] [PATCH pve-manager 0/2] change unit of memory for ct/vm Noel Ullreich
2023-07-27 10:30 ` [pve-devel] [PATCH pve-manager 2/2] ui: fix: change units of memory/swap for containers Noel Ullreich
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=20230616095410.33426-3-n.ullreich@proxmox.com \
--to=n.ullreich@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