]> git.proxmox.com Git - proxmox-widget-toolkit.git/commitdiff
bandwidth/utils: move out SizeUnits definition to more common module
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Sat, 20 Nov 2021 20:35:26 +0000 (21:35 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Sat, 20 Nov 2021 20:35:26 +0000 (21:35 +0100)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/Utils.js
src/form/BandwidthSelector.js

index 9703bd9f2537fc165cdb82ef8ebb950f64bd9184..b8ffd851a1bb20f5eef8a55b938c367e06aa7990 100644 (file)
@@ -664,6 +664,22 @@ utilities: {
        return `${size.toFixed(commaDigits)} ${unit}B`;
     },
 
+    SizeUnits: {
+       'B': 1,
+
+       'KiB': 1024,
+       'MiB': 1024*1024,
+       'GiB': 1024*1024*1024,
+       'TiB': 1024*1024*1024*1024,
+       'PiB': 1024*1024*1024*1024*1024,
+
+       'KB': 1000,
+       'MB': 1000*1000,
+       'GB': 1000*1000*1000,
+       'TB': 1000*1000*1000*1000,
+       'PB': 1000*1000*1000*1000*1000,
+    },
+
     render_upid: function(value, metaData, record) {
        let task = record.data;
        let type = task.type || task.worker_type;
index ce941cd64a6e804b038bdaa24ed71aeeeb2b0d2d..d49cd52b79c3e2650f920828b9fbbf7776bc0b58 100644 (file)
@@ -21,18 +21,6 @@ Ext.define('Proxmox.form.SizeField', {
        hideLabel: true,
     },
 
-    units: {
-       'B': 1,
-       'KiB': 1024,
-       'MiB': 1024*1024,
-       'GiB': 1024*1024*1024,
-       'TiB': 1024*1024*1024*1024,
-       'KB': 1000,
-       'MB': 1000*1000,
-       'GB': 1000*1000*1000,
-       'TB': 1000*1000*1000*1000,
-    },
-
     // display unit (TODO: make (optionally) selectable)
     unit: 'MiB',
     unitPostfix: '',
@@ -67,7 +55,7 @@ Ext.define('Proxmox.form.SizeField', {
                    let vm = fieldContainer.getViewModel();
                    let unit = vm.get('unit');
 
-                   v /= fieldContainer.units[unit];
+                   v /= Proxmox.Utils.SizeUnits[unit];
                    v *= fieldContainer.backendFactor;
 
                    this._transformed = true;
@@ -95,10 +83,9 @@ Ext.define('Proxmox.form.SizeField', {
                let vm = fieldContainer.getViewModel();
                let unit = vm.get('unit');
 
-               v = parseFloat(v) * fieldContainer.units[unit];
-               v /= fieldContainer.backendFactor;
+               v = parseFloat(v) * Proxmox.Utils.SizeUnits[unit];
 
-               return String(Math.floor(v));
+               return String(Math.floor(v / fieldContainer.backendFactor));
            },
            listeners: {
                // our setValue gets only called if we have a value, avoid
@@ -127,16 +114,16 @@ Ext.define('Proxmox.form.SizeField', {
        let me = this;
 
        me.unit = me.unit || 'MiB';
-       if (!(me.unit in me.units)) {
+       if (!(me.unit in Proxmox.Utils.SizeUnits)) {
            throw "unknown unit: " + me.unit;
        }
 
        me.backendFactor = 1;
        if (me.backendUnit !== undefined) {
-           if (!(me.unit in me.units)) {
+           if (!(me.unit in Proxmox.Utils.SizeUnits)) {
                throw "unknown backend unit: " + me.backendUnit;
            }
-           me.backendFactor = me.units[me.backendUnit];
+           me.backendFactor = Proxmox.Utils.SizeUnits[me.backendUnit];
        }
 
        me.callParent(arguments);