[pve-devel] [PATCH] added renderer for hd strings in hardware overview
tgrodzinski
t.grodzinski at profihost.ag
Wed Aug 22 16:09:35 CEST 2012
Signed-off-by: tgrodzinski <t.grodzinski at profihost.ag>
---
www/manager/qemu/HardwareView.js | 108 +++++++++++++++++++++++---------------
1 file changed, 67 insertions(+), 41 deletions(-)
diff --git a/www/manager/qemu/HardwareView.js b/www/manager/qemu/HardwareView.js
index 4d27b84..8de6038 100644
--- a/www/manager/qemu/HardwareView.js
+++ b/www/manager/qemu/HardwareView.js
@@ -94,56 +94,82 @@ Ext.define('PVE.qemu.HardwareView', {
}
};
+ var renderer_hd = function (value) {
+ if (typeof value === 'string') {
+ var units = ['', 'K', 'M', 'G', 'T'];
+ var parts = value.split( ',' );
+ var formattedValue = '';
+ for (i = 0; i < parts.length; i++) {
+ var bpsMatch = parts[i].match( /^bps_..=(\d+)/ );
+ if (bpsMatch) {
+ var bps = bpsMatch[1];
+ var pow = Math.floor( Math.log( bps ) / Math.log( 1024 ) );
+ pow = Math.min( pow, units.length - 1 );
+ var bpsNew = Math.round( bps / Math.pow( 1024, pow ) * 100 ) / 100;
+ formattedValue += parts[i].replace( bps, bpsNew + units[pow] );
+ } else {
+ formattedValue += parts[i];
+ }
+ if (i != parts.length - 1) formattedValue += ', ';
+ }
+ return formattedValue;
+ }
+ return value;
+ };
+
for (i = 0; i < 4; i++) {
- confid = "ide" + i;
- rows[confid] = {
- group: 1,
- tdCls: 'pve-itype-icon-storage',
- editor: 'PVE.qemu.HDEdit',
- never_delete: caps.vms['VM.Config.Disk'] ? false : true,
- header: gettext('Hard Disk') + ' (' + confid +')',
- cdheader: gettext('CD/DVD Drive') + ' (' + confid +')'
- };
+ confid = "ide" + i;
+ rows[confid] = {
+ group: 1,
+ tdCls: 'pve-itype-icon-storage',
+ editor: 'PVE.qemu.HDEdit',
+ never_delete: caps.vms['VM.Config.Disk'] ? false : true,
+ header: gettext('Hard Disk') + ' (' + confid +')',
+ cdheader: gettext('CD/DVD Drive') + ' (' + confid +')',
+ renderer: renderer_hd
+ };
}
for (i = 0; i < 16; i++) {
- confid = "scsi" + i;
- rows[confid] = {
- group: 1,
- tdCls: 'pve-itype-icon-storage',
- editor: 'PVE.qemu.HDEdit',
- never_delete: caps.vms['VM.Config.Disk'] ? false : true,
- header: gettext('Hard Disk') + ' (' + confid +')',
- cdheader: gettext('CD/DVD Drive') + ' (' + confid +')'
- };
+ confid = "scsi" + i;
+ rows[confid] = {
+ group: 1,
+ tdCls: 'pve-itype-icon-storage',
+ editor: 'PVE.qemu.HDEdit',
+ never_delete: caps.vms['VM.Config.Disk'] ? false : true,
+ header: gettext('Hard Disk') + ' (' + confid +')',
+ cdheader: gettext('CD/DVD Drive') + ' (' + confid +')',
+ renderer: renderer_hd
+ };
}
for (i = 0; i < 16; i++) {
- confid = "virtio" + i;
- rows[confid] = {
- group: 1,
- tdCls: 'pve-itype-icon-storage',
- editor: 'PVE.qemu.HDEdit',
- never_delete: caps.vms['VM.Config.Disk'] ? false : true,
- header: gettext('Hard Disk') + ' (' + confid +')',
- cdheader: gettext('CD/DVD Drive') + ' (' + confid +')'
- };
+ confid = "virtio" + i;
+ rows[confid] = {
+ group: 1,
+ tdCls: 'pve-itype-icon-storage',
+ editor: 'PVE.qemu.HDEdit',
+ never_delete: caps.vms['VM.Config.Disk'] ? false : true,
+ header: gettext('Hard Disk') + ' (' + confid +')',
+ cdheader: gettext('CD/DVD Drive') + ' (' + confid +')',
+ renderer: renderer_hd
+ };
}
for (i = 0; i < 32; i++) {
- confid = "net" + i;
- rows[confid] = {
- group: 2,
- tdCls: 'pve-itype-icon-network',
- editor: caps.vms['VM.Config.Network'] ? 'PVE.qemu.NetworkEdit' : undefined,
- never_delete: caps.vms['VM.Config.Network'] ? false : true,
- header: gettext('Network Device') + ' (' + confid +')'
- };
+ confid = "net" + i;
+ rows[confid] = {
+ group: 2,
+ tdCls: 'pve-itype-icon-network',
+ editor: caps.vms['VM.Config.Network'] ? 'PVE.qemu.NetworkEdit' : undefined,
+ never_delete: caps.vms['VM.Config.Network'] ? false : true,
+ header: gettext('Network Device') + ' (' + confid +')'
+ };
}
for (i = 0; i < 8; i++) {
- rows["unused" + i] = {
- group: 3,
- tdCls: 'pve-itype-icon-storage',
- editor: caps.vms['VM.Config.Disk'] ? 'PVE.qemu.HDEdit' : undefined,
- header: gettext('Unused Disk') + ' ' + i
- };
+ rows["unused" + i] = {
+ group: 3,
+ tdCls: 'pve-itype-icon-storage',
+ editor: caps.vms['VM.Config.Disk'] ? 'PVE.qemu.HDEdit' : undefined,
+ header: gettext('Unused Disk') + ' ' + i
+ };
}
var sorterFn = function(rec1, rec2) {
--
1.7.9.5
More information about the pve-devel
mailing list