[pve-devel] r5983 - in pve-manager/pve2/www/new: data grid node panel qemu
svn-commits at proxmox.com
svn-commits at proxmox.com
Mon May 16 13:16:36 CEST 2011
Author: dietmar
Date: 2011-05-16 13:16:36 +0200 (Mon, 16 May 2011)
New Revision: 5983
Modified:
pve-manager/pve2/www/new/data/ObjectStore.js
pve-manager/pve2/www/new/data/UpdateStore.js
pve-manager/pve2/www/new/grid/ObjectGrid.js
pve-manager/pve2/www/new/node/Config.js
pve-manager/pve2/www/new/panel/ConfigPanel.js
pve-manager/pve2/www/new/qemu/Config.js
Log:
cleanups
Modified: pve-manager/pve2/www/new/data/ObjectStore.js
===================================================================
--- pve-manager/pve2/www/new/data/ObjectStore.js 2011-05-16 08:45:38 UTC (rev 5982)
+++ pve-manager/pve2/www/new/data/ObjectStore.js 2011-05-16 11:16:36 UTC (rev 5983)
@@ -1,11 +1,14 @@
Ext.define('PVE.data.ObjectStore', {
- extend: 'Ext.data.Store',
+ extend: 'PVE.data.UpdateStore',
constructor: function(config) {
var me = this;
config = config || {};
-
+
+ if (!config.storeid)
+ config.storeid = 'pve-store-' + (++Ext.idSeed);
+
Ext.applyIf(config, {
model: 'KeyValue',
proxy: {
Modified: pve-manager/pve2/www/new/data/UpdateStore.js
===================================================================
--- pve-manager/pve2/www/new/data/UpdateStore.js 2011-05-16 08:45:38 UTC (rev 5982)
+++ pve-manager/pve2/www/new/data/UpdateStore.js 2011-05-16 11:16:36 UTC (rev 5983)
@@ -38,5 +38,9 @@
});
me.callParent([config]);
+
+ me.on('destroy', function() {
+ loadtask.cancel();
+ });
}
});
Modified: pve-manager/pve2/www/new/grid/ObjectGrid.js
===================================================================
--- pve-manager/pve2/www/new/grid/ObjectGrid.js 2011-05-16 08:45:38 UTC (rev 5982)
+++ pve-manager/pve2/www/new/grid/ObjectGrid.js 2011-05-16 11:16:36 UTC (rev 5983)
@@ -39,11 +39,10 @@
var rows = me.rows;
- var visible = false;
+ if (!me.rstore)
+ throw "no rstore specified";
- var rstore = new PVE.data.ObjectStore({
- url: me.url
- });
+ var rstore = me.rstore;
var store = Ext.create('Ext.data.Store', {
model: 'KeyValue',
@@ -78,74 +77,57 @@
});
}
- var first_load_done = false;
+ me.mon(rstore, 'load', function(s, records, success) {
- var loadtask;
- loadtask = new Ext.util.DelayedTask(function() {
- rstore.load({
- callback: function(records, operation, success) {
+ if (!success) {
+ me.setLoading("Data load error");
+ return;
+ } else {
+ me.setLoading(false);
+ }
- first_load_done = true;
+ store.suspendEvents();
- if (visible && me.interval)
- loadtask.delay(me.interval);
-
- me.setLoading(false);
-
- if (!success) {
- var error = operation.getError();
- var msg = "Data load error - server offline?";
- if (error && error.status && error.statusText)
- msg = "Error " + error.status + ": " + error.statusText;
- me.setLoading(msg);
- return;
+ // remove vanished items
+ store.each(function(olditem) {
+ var item = rstore.data.get(olditem.data.key);
+ if (!item) {
+ if (!(rows && rows[olditem.data.key] &&
+ Ext.isDefined(rows[olditem.data.key].defaultValue))) {
+ store.remove(olditem);
}
-
- store.suspendEvents();
-
- // remove vanished items
- store.each(function(olditem) {
- var item = rstore.data.get(olditem.data.key);
- if (!item) {
- if (!(rows && rows[olditem.data.key] &&
- Ext.isDefined(rows[olditem.data.key].defaultValue))) {
- store.remove(olditem);
- }
- }
- });
-
- // add/update items
-
- if (rows) {
- Ext.Object.each(rows, function(key, rowdef) {
- var olditem = (store.snapshot || store.data).get(key);
- var item = rstore.data.get(key);
- if (!item) {
- if (!Ext.isDefined(rowdef.defaultValue))
- return;
- var data = { key: key, value: rowdef.defaultValue };
- cond_add_item(data, olditem);
- } else
- cond_add_item(item.data, olditem);
- });
- } else {
- rstore.each(function(item) {
- var olditem = (store.snapshot || store.data).get(item.data.key);
- cond_add_item(item.data, olditem);
- });
- }
-
- store.filterBy(function(item) {
- if (rows && rows[item.data.key] &&
- (rows[item.data.key].visible === false))
- return false;
- return true;
- });
-
- store.resumeEvents();
- store.fireEvent('datachanged', store);
}
});
+
+ // add/update items
+ if (rows) {
+ Ext.Object.each(rows, function(key, rowdef) {
+ var olditem = (store.snapshot || store.data).get(key);
+ var item = rstore.data.get(key);
+ if (!item) {
+ if (!Ext.isDefined(rowdef.defaultValue))
+ return;
+ var data = { key: key, value: rowdef.defaultValue };
+ cond_add_item(data, olditem);
+ } else
+ cond_add_item(item.data, olditem);
+ });
+ } else {
+ rstore.each(function(item) {
+ var olditem = (store.snapshot || store.data).get(item.data.key);
+ cond_add_item(item.data, olditem);
+ });
+ }
+
+ store.filterBy(function(item) {
+ if (rows && rows[item.data.key] &&
+ (rows[item.data.key].visible === false))
+ return false;
+ return true;
+ });
+
+ store.resumeEvents();
+ store.fireEvent('datachanged', store);
});
Ext.applyIf(me, {
@@ -169,22 +151,7 @@
});
me.callParent();
+ }
- me.on('show', function() {
- visible = true;
- if (!first_load_done)
- me.setLoading(true);
- loadtask.delay(10);
- });
- me.on('hide', function() {
- visible = false;
- loadtask.cancel();
- });
-
- me.on('destroy', function() {
- visible = false;
- loadtask.cancel();
- });
- }
});
Modified: pve-manager/pve2/www/new/node/Config.js
===================================================================
--- pve-manager/pve2/www/new/node/Config.js 2011-05-16 08:45:38 UTC (rev 5982)
+++ pve-manager/pve2/www/new/node/Config.js 2011-05-16 11:16:36 UTC (rev 5983)
@@ -39,7 +39,6 @@
};
Ext.applyIf(me, {
- url: "/api2/json/nodes/" + me.nodename + "/status",
cwidth1: 150,
interval: 1000,
rows: rows
@@ -77,26 +76,10 @@
var rrdurl = "/api2/png/nodes/" + nodename + "/rrd";
- Ext.apply(me, {
- layout: {
- type: 'table',
- columns: 1
- },
- autoScroll: true,
- bodyStyle: 'padding:10px',
- defaults: {
- style: 'padding-bottom:10px'
- },
- listeners: {
- show: function() {
- me.items.each(function(item) { item.fireEvent('show', item); });
- },
- hide: function() {
- me.items.each(function(item) { item.fireEvent('hide', item); });
- }
- },
- tbar: [
- {
+ var tbar = Ext.create('Ext.toolbar.Toolbar', {
+ items: [
+ {
+ itemId: 'reboot',
text: 'Reboot',
handler: function() {
var msg = "Do you really want to reboot node '" + nodename + "'?";
@@ -108,6 +91,7 @@
}
},
{
+ itemId: 'shutdown',
text: 'Shutdown',
handler: function() {
var msg = "Do you really want to shutdown node '" + nodename + "'?";
@@ -119,6 +103,7 @@
}
},
{
+ itemId: 'shell',
text: 'Shell',
handler: function() {
var url = Ext.urlEncode({
@@ -133,13 +118,35 @@
{
xtype: 'pveRRDTypeSelector'
}
- ],
+ ]
+ });
+
+ me.mon(me.rstore, 'load', function(s, records, success) {
+ var uptimerec = s.data.get('uptime');
+ var uptime = uptimerec ? uptimerec.data.value : false;
+
+ tbar.down('#reboot').setDisabled(!uptime);
+ tbar.down('#shutdown').setDisabled(!uptime);
+ tbar.down('#shell').setDisabled(!uptime);
+ });
+
+ Ext.apply(me, {
+ layout: {
+ type: 'table',
+ columns: 1
+ },
+ autoScroll: true,
+ bodyStyle: 'padding:10px',
+ defaults: {
+ style: 'padding-bottom:10px'
+ },
+ tbar: tbar,
items: [
{
title: 'Status',
xtype: 'pveNodeStatusView',
- width: 800,
- nodename: nodename
+ rstore: me.rstore,
+ width: 800
},
{
xtype: 'pveRRDView',
@@ -183,6 +190,11 @@
if (!nodename)
throw "no node name specified";
+ me.rstore = Ext.create('PVE.data.ObjectStore', {
+ url: "/api2/json/nodes/" + nodename + "/status",
+ interval: 1000
+ });
+
Ext.apply(me, {
title: "Node '" + nodename + "'",
hstateid: 'nodetab',
@@ -226,5 +238,11 @@
});
me.callParent();
+
+ me.rstore.startUpdate();
+
+ me.on('destroy', function() {
+ me.rstore.stopUpdate();
+ });
}
});
Modified: pve-manager/pve2/www/new/panel/ConfigPanel.js
===================================================================
--- pve-manager/pve2/www/new/panel/ConfigPanel.js 2011-05-16 08:45:38 UTC (rev 5982)
+++ pve-manager/pve2/www/new/panel/ConfigPanel.js 2011-05-16 11:16:36 UTC (rev 5983)
@@ -22,8 +22,9 @@
defaults: {}
});
- // pass pveSelNode && viewFilter to all children
+ // pass rstore, pveSelNode and viewFilter to all children
Ext.apply(me.defaults, {
+ rstore: me.rstore,
pveSelNode: me.pveSelNode,
viewFilter: me.viewFilter,
border: false
@@ -63,8 +64,6 @@
me.callParent();
- me.items.get(0).fireEvent('show', me.items.get(0));
-
var statechange = function(sp, key, state) {
if (stateid && key === stateid) {
var atab = me.getActiveTab().itemId;
Modified: pve-manager/pve2/www/new/qemu/Config.js
===================================================================
--- pve-manager/pve2/www/new/qemu/Config.js 2011-05-16 08:45:38 UTC (rev 5982)
+++ pve-manager/pve2/www/new/qemu/Config.js 2011-05-16 11:16:36 UTC (rev 5983)
@@ -73,8 +73,125 @@
throw "no VM ID specified";
var rrdurl = "/api2/png/nodes/" + nodename + "/qemu/" + vmid + "/rrd";
-
+
+ var vm_command = function(cmd) {
+ me.setLoading(true, true);
+ PVE.Utils.API2Request({
+ params: { command: cmd },
+ url: '/nodes/' + nodename + '/qemu/' + vmid + "/status",
+ method: 'PUT',
+ callback: function() {
+ me.setLoading(false);
+ },
+ failure: function(response, opts) {
+ Ext.Msg.alert('Error', response.htmlStatus);
+ }
+ });
+ };
+
+ var tbar = Ext.create('Ext.toolbar.Toolbar', {
+ items: [
+ {
+ itemId: 'start',
+ text: 'Start',
+ handler: function() {
+ vm_command('start');
+ }
+ },
+ {
+ itemId: 'stop',
+ text: 'Stop',
+ handler: function() {
+ var msg = "Do you really want to stop the VM?";
+ Ext.Msg.confirm('Confirm', msg, function(btn) {
+ if (btn !== 'yes')
+ return;
+ vm_command("stop");
+ });
+ }
+ },
+ {
+ text: 'Reset',
+ itemId: 'reset',
+ handler: function() {
+ var msg = "Do you really want to reset the VM?";
+ Ext.Msg.confirm('Confirm', msg, function(btn) {
+ if (btn !== 'yes')
+ return;
+ vm_command("reset");
+ });
+ }
+ },
+ {
+ itemId: 'shutdown',
+ text: 'Shutdown',
+ handler: function() {
+ var msg = "Do you really want to shutdown the VM?";
+ Ext.Msg.confirm('Confirm', msg, function(btn) {
+ if (btn !== 'yes')
+ return;
+ vm_command('shutdown');
+ });
+ }
+ },
+ {
+ itemId: 'remove',
+ text: 'Remove',
+ handler: function() {
+ var msg = 'Are you sure you want to remove VM ' +
+ vmid + '? This will permanently erase all VM data.';
+ Ext.Msg.confirm('Confirm', msg, function(btn) {
+ if (btn !== 'yes')
+ return;
+
+ me.setLoading(true, true);
+ PVE.Utils.API2Request({
+ url: '/nodes/' + nodename + '/qemu/' + vmid,
+ method: 'DELETE',
+ callback: function() {
+ me.setLoading(false);
+ },
+ failure: function(response, opts) {
+ Ext.Msg.alert('Error', response.htmlStatus);
+ }
+ });
+ });
+ }
+ },
+ {
+ itemId: 'console',
+ text: 'Console',
+ handler: function() {
+ var url = Ext.urlEncode({
+ console: 'kvm',
+ vmid: vmid,
+ node: nodename
+ });
+ var nw = window.open("?" + url, '_blank',
+ "innerWidth=745,innerheight=427");
+ nw.focus();
+ }
+ }, '->',
+ {
+ xtype: 'pveRRDTypeSelector'
+ }
+ ]
+ });
+
+ me.mon(me.rstore, 'load', function(s, records, success) {
+ var statusrec = s.data.get('status');
+ var status = statusrec ? statusrec.data.value : 'unknown';
+
+ tbar.down('#start').setDisabled(status === 'running');
+ tbar.down('#reset').setDisabled(status !== 'running');
+ tbar.down('#shutdown').setDisabled(status !== 'running');
+ tbar.down('#stop').setDisabled(status === 'stopped');
+ tbar.down('#console').setDisabled(status !== 'running');
+ tbar.down('#remove').setDisabled(status !== 'stopped');
+ });
+
Ext.apply(me, {
+ tbar: tbar,
layout: {
type: 'table',
columns: 1
@@ -82,31 +199,14 @@
autoScroll: true,
bodyStyle: 'padding:10px',
defaults: {
- pveSelNode: me.pveSelNode,
style: 'padding-bottom:10px'
},
- listeners: {
- show: function() {
- me.items.each(function(item) { item.fireEvent('show', item); });
- },
- hide: function() {
- me.items.each(function(item) { item.fireEvent('hide', item); });
- }
- },
items: [
{
layout: {
type: 'hbox',
align: 'stretchmax'
},
- listeners: {
- show: function() {
- this.items.each(function(item) { item.fireEvent('show', item); });
- },
- hide: function() {
- this.items.each(function(item) { item.fireEvent('hide', item); });
- }
- },
width: 800,
border: false,
items: [
@@ -114,33 +214,37 @@
title: 'Status',
xtype: 'pveQemuStatusView',
pveSelNode: me.pveSelNode,
+ rstore: me.rstore,
width: 400
},
{
title: 'Comments',
style: 'padding-left:10px',
pveSelNode: me.pveSelNode,
+ rstore: me.rstore,
html: "test",
width: 400
}
]
},
-
{
xtype: 'pveRRDView',
title: "CPU usage %",
+ pveSelNode: me.pveSelNode,
datasource: 'cpu',
rrdurl: rrdurl
},
{
xtype: 'pveRRDView',
title: "Memory usage",
+ pveSelNode: me.pveSelNode,
datasource: 'mem,maxmem',
rrdurl: rrdurl
},
{
xtype: 'pveRRDView',
title: "Network traffic",
+ pveSelNode: me.pveSelNode,
datasource: 'netin,netout',
rrdurl: rrdurl
}
@@ -166,22 +270,11 @@
if (!vmid)
throw "no VM ID specified";
- var vm_command = function(cmd) {
+ me.rstore = Ext.create('PVE.data.ObjectStore', {
+ url: "/api2/json/nodes/" + nodename + "/qemu/" + vmid + "/status",
+ interval: 1000
+ });
- me.setLoading(true, true);
- PVE.Utils.API2Request({
- params: { command: cmd },
- url: '/nodes/' + nodename + '/qemu/' + vmid + "/status",
- method: 'PUT',
- callback: function() {
- me.setLoading(false);
- },
- failure: function(response, opts) {
- Ext.Msg.alert('Error', response.htmlStatus);
- }
- });
- };
-
var vmname = me.pveSelNode.data.name;
var descr = vmname ? "'" + vmname + "' " : '';
Ext.apply(me, {
@@ -192,84 +285,7 @@
{
title: 'Summary',
xtype: 'pveQemuSummary',
- itemId: 'summary',
- tbar: [
- {
- text: 'Start',
- handler: function() {
- vm_command('start');
- }
- },
- {
- text: 'Stop',
- handler: function() {
- var msg = "Do you really want to stop the VM?";
- Ext.Msg.confirm('Confirm', msg, function(btn) {
- if (btn !== 'yes')
- return;
- vm_command("stop");
- });
- }
- },
- {
- text: 'Reset',
- handler: function() {
- var msg = "Do you really want to reset the VM?";
- Ext.Msg.confirm('Confirm', msg, function(btn) {
- if (btn !== 'yes')
- return;
- vm_command("reset");
- });
- }
- },
- {
- text: 'Shutdown',
- handler: function() {
- var msg = "Do you really want to shutdown the VM?";
- Ext.Msg.confirm('Confirm', msg, function(btn) {
- if (btn !== 'yes')
- return;
- vm_command('shutdown');
- });
- }
- },
- {
- text: 'Remove',
- handler: function() {
- var msg = 'Are you sure you want to remove VM ' +
- vmid + '? This will permanently erase all VM data.';
- Ext.Msg.confirm('Confirm', msg, function(btn) {
- if (btn !== 'yes')
- return;
-
- me.setLoading(true, true);
- PVE.Utils.API2Request({
- url: '/nodes/' + nodename + '/qemu/' + vmid,
- method: 'DELETE',
- callback: function() {
- me.setLoading(false);
- },
- failure: function(response, opts) {
- Ext.Msg.alert('Error', response.htmlStatus);
- }
- });
- });
- }
- }, '->',
- {
- text: 'Console',
- handler: function() {
- var url = Ext.urlEncode({
- console: 'kvm',
- vmid: vmid,
- node: nodename
- });
- var nw = window.open("?" + url, '_blank',
- "innerWidth=745,innerheight=427");
- nw.focus();
- }
- }
- ]
+ itemId: 'summary'
},
{
title: 'Hardware',
@@ -298,5 +314,11 @@
});
me.callParent();
+
+ me.rstore.startUpdate();
+
+ me.on('destroy', function() {
+ me.rstore.stopUpdate();
+ });
}
});
More information about the pve-devel
mailing list