mirror of
https://git.proxmox.com/git/proxmox-widget-toolkit
synced 2025-05-11 21:29:58 +00:00
bandwidth/utils: move out SizeUnits definition to more common module
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
52a0eae95a
commit
1fad0e8822
16
src/Utils.js
16
src/Utils.js
@ -664,6 +664,22 @@ utilities: {
|
|||||||
return `${size.toFixed(commaDigits)} ${unit}B`;
|
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) {
|
render_upid: function(value, metaData, record) {
|
||||||
let task = record.data;
|
let task = record.data;
|
||||||
let type = task.type || task.worker_type;
|
let type = task.type || task.worker_type;
|
||||||
|
@ -21,18 +21,6 @@ Ext.define('Proxmox.form.SizeField', {
|
|||||||
hideLabel: true,
|
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)
|
// display unit (TODO: make (optionally) selectable)
|
||||||
unit: 'MiB',
|
unit: 'MiB',
|
||||||
unitPostfix: '',
|
unitPostfix: '',
|
||||||
@ -67,7 +55,7 @@ Ext.define('Proxmox.form.SizeField', {
|
|||||||
let vm = fieldContainer.getViewModel();
|
let vm = fieldContainer.getViewModel();
|
||||||
let unit = vm.get('unit');
|
let unit = vm.get('unit');
|
||||||
|
|
||||||
v /= fieldContainer.units[unit];
|
v /= Proxmox.Utils.SizeUnits[unit];
|
||||||
v *= fieldContainer.backendFactor;
|
v *= fieldContainer.backendFactor;
|
||||||
|
|
||||||
this._transformed = true;
|
this._transformed = true;
|
||||||
@ -95,10 +83,9 @@ Ext.define('Proxmox.form.SizeField', {
|
|||||||
let vm = fieldContainer.getViewModel();
|
let vm = fieldContainer.getViewModel();
|
||||||
let unit = vm.get('unit');
|
let unit = vm.get('unit');
|
||||||
|
|
||||||
v = parseFloat(v) * fieldContainer.units[unit];
|
v = parseFloat(v) * Proxmox.Utils.SizeUnits[unit];
|
||||||
v /= fieldContainer.backendFactor;
|
|
||||||
|
|
||||||
return String(Math.floor(v));
|
return String(Math.floor(v / fieldContainer.backendFactor));
|
||||||
},
|
},
|
||||||
listeners: {
|
listeners: {
|
||||||
// our setValue gets only called if we have a value, avoid
|
// our setValue gets only called if we have a value, avoid
|
||||||
@ -127,16 +114,16 @@ Ext.define('Proxmox.form.SizeField', {
|
|||||||
let me = this;
|
let me = this;
|
||||||
|
|
||||||
me.unit = me.unit || 'MiB';
|
me.unit = me.unit || 'MiB';
|
||||||
if (!(me.unit in me.units)) {
|
if (!(me.unit in Proxmox.Utils.SizeUnits)) {
|
||||||
throw "unknown unit: " + me.unit;
|
throw "unknown unit: " + me.unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
me.backendFactor = 1;
|
me.backendFactor = 1;
|
||||||
if (me.backendUnit !== undefined) {
|
if (me.backendUnit !== undefined) {
|
||||||
if (!(me.unit in me.units)) {
|
if (!(me.unit in Proxmox.Utils.SizeUnits)) {
|
||||||
throw "unknown backend unit: " + me.backendUnit;
|
throw "unknown backend unit: " + me.backendUnit;
|
||||||
}
|
}
|
||||||
me.backendFactor = me.units[me.backendUnit];
|
me.backendFactor = Proxmox.Utils.SizeUnits[me.backendUnit];
|
||||||
}
|
}
|
||||||
|
|
||||||
me.callParent(arguments);
|
me.callParent(arguments);
|
||||||
|
Loading…
Reference in New Issue
Block a user