[pve-devel] r5987 - in pve-manager/pve2/www/new: . node

svn-commits at proxmox.com svn-commits at proxmox.com
Tue May 17 10:30:29 CEST 2011


Author: dietmar
Date: 2011-05-17 10:30:29 +0200 (Tue, 17 May 2011)
New Revision: 5987

Added:
   pve-manager/pve2/www/new/node/ServiceView.js
Modified:
   pve-manager/pve2/www/new/Makefile.am
   pve-manager/pve2/www/new/node/Config.js
Log:
implement ServiceView


Modified: pve-manager/pve2/www/new/Makefile.am
===================================================================
--- pve-manager/pve2/www/new/Makefile.am	2011-05-17 06:25:40 UTC (rev 5986)
+++ pve-manager/pve2/www/new/Makefile.am	2011-05-17 08:30:29 UTC (rev 5987)
@@ -33,6 +33,7 @@
 	node/TimeEdit.js				\
 	node/StatusView.js				\
 	node/Summary.js					\
+	node/ServiceView.js				\
 	node/Config.js					\
 	qemu/StatusView.js				\
 	qemu/Summary.js					\

Modified: pve-manager/pve2/www/new/node/Config.js
===================================================================
--- pve-manager/pve2/www/new/node/Config.js	2011-05-17 06:25:40 UTC (rev 5986)
+++ pve-manager/pve2/www/new/node/Config.js	2011-05-17 08:30:29 UTC (rev 5987)
@@ -21,8 +21,7 @@
 		{
 		    title: 'Services',
 		    itemId: 'services',
-		    //xtype: 'pveNodeServiceView',
-		    html: 'services'
+		    xtype: 'pveNodeServiceView'
 		},
 		{
 		    title: 'Network',

Added: pve-manager/pve2/www/new/node/ServiceView.js
===================================================================
--- pve-manager/pve2/www/new/node/ServiceView.js	                        (rev 0)
+++ pve-manager/pve2/www/new/node/ServiceView.js	2011-05-17 08:30:29 UTC (rev 5987)
@@ -0,0 +1,144 @@
+Ext.define('PVE.node.ServiceView', {
+    extend: 'Ext.grid.GridPanel',
+
+    alias: ['widget.pveNodeServiceView'],
+
+    initComponent : function() {
+	var me = this;
+
+	var nodename = me.pveSelNode.data.node;
+	if (!nodename) 
+	    throw "no node name specified";
+
+	var store = Ext.create('Ext.data.Store', {
+	    fields: [ 'service', 'name', 'desc', 'state' ],
+            proxy: {
+                type: 'pve',
+                url: "/api2/json/nodes/" + nodename + "/services",
+            }
+	});
+
+	var prev_selection;
+	store.on('beforeload', function() {
+	    var sm = me.getSelectionModel();
+	    prev_selection = sm.getLastSelected();
+	});
+
+	store.on("load", function() {
+	    if (prev_selection) {
+		var rec = store.find('service', prev_selection.data.service);
+		if (rec) {
+		    var sm = me.getSelectionModel();
+		    sm.select(rec);
+		}
+	    }
+	}); 
+
+	var service_cmd = function(cmd) {
+	    var sm = me.getSelectionModel();
+	    var rec = sm.getLastSelected();
+	    PVE.Utils.API2Request({
+		url: "/nodes/" + nodename + "/services/" + rec.data.service,
+		params: { command: cmd },
+		method: 'PUT',
+		failure: function(response, opts) {
+		    Ext.Msg.alert('Error', response.htmlStatus);
+		    store.load();
+		},
+		success: function(response, opts) {
+		    store.load();
+		}
+	    });
+	};
+
+	var start_btn = new Ext.Button({
+	    text: 'Start',
+	    disabled: true,
+	    handler: function(){
+		service_cmd("start");
+	    }
+	});
+
+	var stop_btn = new Ext.Button({
+	    text: 'Stop',
+	    disabled: true,
+	    handler: function(){
+		service_cmd("stop");
+	    }
+	});
+
+	var restart_btn = new Ext.Button({
+	    text: 'Restart',
+	    disabled: true,
+	    handler: function(){
+		service_cmd("restart");
+	    }
+	});
+
+	Ext.apply(me, {
+	    store: store,
+	    stateful: false,
+	    tbar: [ start_btn, stop_btn, restart_btn ],
+	    columns: [
+		{
+		    header: 'Name',
+		    width: 100,
+		    sortable: true,
+		    dataIndex: 'name'
+		},
+		{
+		    header: 'State',
+		    width: 100,
+		    sortable: true,
+		    dataIndex: 'state'
+		},
+		{
+		    header: 'Description',
+		    dataIndex: 'desc',
+		    flex: 1
+		}
+	    ],
+	    listeners: {
+		selectionchange: function(t, selections) {
+		    var rec = selections[0];
+		    if (!rec) {
+			start_btn.disable();
+			stop_btn.disable();
+			restart_btn.disable();
+			return;
+		    }
+		    var service = rec.data.service;
+		    var state = rec.data.state;
+		    if (service == 'apache' ||
+			service == 'pvecluster' ||
+			service == 'pvedaemon') {
+			if (state == 'running') {
+			    start_btn.disable();
+			    restart_btn.enable();
+			} else {
+			    start_btn.enable();
+			    restart_btn.disable();
+			}
+			stop_btn.disable();
+		    } else {
+			if (state == 'running') {
+			    start_btn.disable();
+			    restart_btn.enable();
+			    stop_btn.enable();
+			} else {
+			    start_btn.enable();
+			    restart_btn.disable();
+			    stop_btn.disable();
+			}
+		    }
+		},
+		show: function() {
+		    store.load();
+		}
+	    }
+	});
+
+	me.callParent();
+    }
+});
+    
\ No newline at end of file




More information about the pve-devel mailing list