[pve-devel] r6067 - in pve-manager/pve2: . www www/apidoc

svn-commits at proxmox.com svn-commits at proxmox.com
Wed Jun 1 14:32:51 CEST 2011


Author: dietmar
Date: 2011-06-01 14:32:50 +0200 (Wed, 01 Jun 2011)
New Revision: 6067

Added:
   pve-manager/pve2/www/apidoc/
   pve-manager/pve2/www/apidoc/Makefile.am
   pve-manager/pve2/www/apidoc/PVEAPI.js
   pve-manager/pve2/www/apidoc/apidoc.html
   pve-manager/pve2/www/apidoc/extractapi.pl
Modified:
   pve-manager/pve2/configure.in
   pve-manager/pve2/www/Makefile.am
Log:
impl. API documentation viewer


Modified: pve-manager/pve2/configure.in
===================================================================
--- pve-manager/pve2/configure.in	2011-05-31 10:20:48 UTC (rev 6066)
+++ pve-manager/pve2/configure.in	2011-06-01 12:32:50 UTC (rev 6067)
@@ -58,6 +58,7 @@
 www/css/Makefile
 www/ext4/Makefile
 www/manager/Makefile
+www/apidoc/Makefile
 www/images/Makefile
 www/templates/pve.conf
 ])

Modified: pve-manager/pve2/www/Makefile.am
===================================================================
--- pve-manager/pve2/www/Makefile.am	2011-05-31 10:20:48 UTC (rev 6066)
+++ pve-manager/pve2/www/Makefile.am	2011-06-01 12:32:50 UTC (rev 6067)
@@ -1,6 +1,6 @@
 include $(top_builddir)/common.mk
 
-SUBDIRS = templates images ext4 css manager
+SUBDIRS = templates images ext4 css manager apidoc
 
 install-data-hook:
 	chown -R www-data:www-data ${DESTDIR}${WWW_BASEDIR}

Added: pve-manager/pve2/www/apidoc/Makefile.am
===================================================================
--- pve-manager/pve2/www/apidoc/Makefile.am	                        (rev 0)
+++ pve-manager/pve2/www/apidoc/Makefile.am	2011-06-01 12:32:50 UTC (rev 6067)
@@ -0,0 +1,22 @@
+include $(top_builddir)/common.mk
+
+apidata.js: extractapi.pl
+	./extractapi.pl >$@
+
+JSSRC= 				       	\
+	apidata.js			\
+	PVEAPI.js
+
+apidoc.js: ${JSSRC}
+	cat ${JSSRC} >$@
+
+pvelib_DATA = apidoc.js apidoc.html
+pvelibdir = ${WWW_ROOTDIR}
+
+install-data-hook: 
+	chown -R www-data:www-data ${DESTDIR}/${pvelibdir}
+
+clean-local:
+	-rm -rf *~ apidata.js apidoc.js
+
+

Added: pve-manager/pve2/www/apidoc/PVEAPI.js
===================================================================
--- pve-manager/pve2/www/apidoc/PVEAPI.js	                        (rev 0)
+++ pve-manager/pve2/www/apidoc/PVEAPI.js	2011-06-01 12:32:50 UTC (rev 6067)
@@ -0,0 +1,260 @@
+Ext.require([
+    'Ext.tree.*',
+    'Ext.data.*',
+    'Ext.window.MessageBox'
+]);
+
+Ext.onReady(function() {
+
+    Ext.define('pve-param-schema', {
+        extend: 'Ext.data.Model',
+        fields:  [ 
+	    'name', 'type', 'typetext', 'description', 'enum', 
+	    'minimum', 'maximum', 'minLength', 'maxLength',
+	    'pattern', 'title', 'requires', 'format', 'default',
+	    'disallow', 'extends', 'links',
+	    {
+		name: 'optional',
+		type: 'boolean'
+	    }
+	]
+    });
+
+    var store = Ext.create('Ext.data.TreeStore', {
+	model: Ext.define('pve-api-doc', {
+            extend: 'Ext.data.Model',
+            fields:  [ 
+		'path', 'info', 'text',
+	    ]
+	}),
+        proxy: {
+            type: 'memory',
+            data: pveapi
+        },
+        sorters: [{
+            property: 'leaf',
+            direction: 'ASC'
+        }, {
+            property: 'text',
+            direction: 'ASC'
+        }]
+    });
+    
+    var render_text = function(value, metaData, record) {
+	var pdef = record.data;
+
+	metaData.style = 'white-space:pre-wrap;'
+
+	return  value;
+    };
+
+    var render_type = function(value, metaData, record) {
+	var pdef = record.data;
+
+	return pdef['enum'] ? 'enum' : (pdef.type || 'string');
+    };
+
+    var render_format = function(value, metaData, record) {
+	var pdef = record.data;
+
+	metaData.style = 'white-space:normal;'
+
+	if (pdef.typetext)
+	    return pdef.typetext;
+
+	if (pdef['enum'])
+	    return pdef['enum'].join(' | ');
+
+	if (pdef.format) 
+	    return pdef.format;
+
+	if (pdef.pattern) 
+	    return pdef.pattern;
+
+	return '';
+    };
+
+    var render_docu = function(data) {
+	var md = data.info;
+
+	console.log(data);
+
+	var items = [];
+
+	Ext.Array.each(['GET', 'POST', 'PUT', 'DELETE'], function(method) {
+	    var info = md[method];
+	    if (info) {
+
+		var sections = [
+		    {
+			title: 'Description',
+			html: info.description,
+			bodyPadding: 10
+		    }
+		];
+
+		if (info.parameters && info.parameters.properties) {
+
+		    var pstore = Ext.create('Ext.data.Store', {
+			model: 'pve-param-schema',
+			proxy: {
+			    type: 'memory'
+			},
+			sorters: [
+			    {
+				property: 'name',
+				direction: 'ASC'
+			    }
+			]
+		    });
+
+		    Ext.Object.each(info.parameters.properties, function(name, pdef) {
+			pdef.name = name;
+			pstore.add(pdef);
+		    });
+
+		    pstore.sort();
+
+		    sections.push({
+			xtype: 'gridpanel',
+			title: 'Parameters',
+			store: pstore,
+			viewConfig: {
+			    trackOver: false,
+			    stripeRows: true
+			},
+			columns: [
+			    { 
+				header: 'Name',
+				dataIndex: 'name'
+			    },
+			    { 
+				header: 'Optional',
+				dataIndex: 'optional'
+			    },
+			    { 
+				header: 'Type',
+				dataIndex: 'type',
+				renderer: render_type,
+			    },
+			    { 
+				header: 'Format',
+				dataIndex: 'type',
+				renderer: render_format,
+				flex: 1
+			    },
+			    { 
+				header: 'Description',
+				dataIndex: 'description',
+				renderer: render_text,
+				flex: 1
+			    }
+			]
+		    });
+
+		}
+
+		if (info.returns) {
+
+		    var rtype = info.returns.type;
+		    if (!rtype && info.returns.items)
+			rtype = 'array';
+		    if (!rtype)
+			rtype = 'object';
+
+		    sections.push({
+			title: 'Returns: ' + rtype,
+		    });
+		}
+
+		var permhtml = '';
+		if (!info.permissions) {
+		    permhtml = "Root only.";
+		} else if (info.permissions.user) {
+		    if (info.permissions.user === 'world') {
+			permhtml += "Accessible without any authententification.";
+		    } else if (info.permissions.user === 'all') {
+			permhtml += "Accessible by all authententicated users.";
+		    } else {
+			permhtml += 'Onyl accessible by user "' + 
+			    info.permissions.user + '"';
+		    }
+		} else if (info.permissions.path && info.permissions.privs) {
+		    permhtml += '<table><tr><td>Path:</td><td>' + 
+			info.permissions.path + '</td></tr>' +
+			'<tr><td style="padding-right:10px;">Permissions:</td><td>' + 
+			info.permissions.privs.join(' ') + 
+			'</td></tr></table>';
+		} else {
+		    permhtml += "Root only.";
+		}
+
+		sections.push({
+		    title: 'Required permissions',
+		    bodyPadding: 10,
+		    html: permhtml
+		});
+    
+  
+		items.push({
+		    title: method,
+		    autoScroll: true,
+		    layout: {
+			type: 'table',
+			columns: 1,
+			tableAttrs: {
+			    style: {
+				width: '100%'
+			    }
+			}
+		    },
+		    defaults: {
+			border: false
+		    },		
+		    items: sections
+		});
+	    }
+	});
+
+	var ct = Ext.getCmp('docview');
+	ct.setTitle("Path: " + data.path);
+	ct.removeAll(true);
+	ct.add(items);
+    };
+
+    var tree = Ext.create('Ext.tree.Panel', {
+        title: 'Resource Tree',
+        store: store,
+	width: 200,
+        region: 'west',
+        split: true,
+        margins: '5 0 5 5',
+        rootVisible: false,
+	listeners: {
+	    selectionchange: function(v, selections) {
+		if (!selections[0])
+		    return;
+		var rec = selections[0];
+		render_docu(rec.data);
+	    }
+	}
+    });
+
+    Ext.create('Ext.container.Viewport', {
+	layout: 'border',
+	renderTo: Ext.getBody(),
+	items: [
+	    tree,
+	    {
+		xtype: 'tabpanel',
+		title: 'Documentation',
+		id: 'docview',
+		region: 'center',
+		margins: '5 5 5 0',
+		layout: 'fit',
+		items: []
+	    }
+	]
+    });
+
+});

Added: pve-manager/pve2/www/apidoc/apidoc.html
===================================================================
--- pve-manager/pve2/www/apidoc/apidoc.html	                        (rev 0)
+++ pve-manager/pve2/www/apidoc/apidoc.html	2011-06-01 12:32:50 UTC (rev 6067)
@@ -0,0 +1,14 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+    <title>Proxmox VE API Documentation</title>
+    <link rel="stylesheet" type="text/css" href="/pve2/ext4/resources/css/ext-all.css" />
+
+    <script type="text/javascript" src="/pve2/ext4/ext-all-debug.js"></script>
+    <script type="text/javascript" src="apidoc.js"></script>
+    
+</head>
+<body>
+</body>
+</html>

Added: pve-manager/pve2/www/apidoc/extractapi.pl
===================================================================
--- pve-manager/pve2/www/apidoc/extractapi.pl	                        (rev 0)
+++ pve-manager/pve2/www/apidoc/extractapi.pl	2011-06-01 12:32:50 UTC (rev 6067)
@@ -0,0 +1,12 @@
+#!/usr/bin/perl -w
+
+use strict;
+use PVE::RESTHandler;
+use PVE::API2;
+use JSON;
+
+my $tree = PVE::RESTHandler::api_dump('PVE::API2');
+
+print "var pveapi = " . to_json($tree, {pretty => 1}) . ";\n\n";
+
+exit(0);


Property changes on: pve-manager/pve2/www/apidoc/extractapi.pl
___________________________________________________________________
Added: svn:executable
   + *




More information about the pve-devel mailing list