]>
git.proxmox.com Git - pve-docs.git/blob - api-viewer/PVEAPI.js
1 // avoid errors when running without development tools
2 if (!Ext
.isDefined(Ext
.global
.console
)) {
9 Ext
.onReady(function() {
11 Ext
.define('pve-param-schema', {
12 extend
: 'Ext.data.Model',
14 'name', 'type', 'typetext', 'description', 'verbose_description',
15 'enum', 'minimum', 'maximum', 'minLength', 'maxLength',
16 'pattern', 'title', 'requires', 'format', 'default',
17 'disallow', 'extends', 'links',
25 var store
= Ext
.define('pve-updated-treestore', {
26 extend
: 'Ext.data.TreeStore',
27 model
: Ext
.define('pve-api-doc', {
28 extend
: 'Ext.data.Model',
30 'path', 'info', 'text',
45 doFilter: function(node
) {
46 this.filterNodes(node
, this.getFilters().getFilterFn(), true);
49 filterNodes: function(node
, filterFn
, parentVisible
) {
51 bottomUpFiltering
= me
.filterer
=== 'bottomup',
52 match
= filterFn(node
) && parentVisible
|| (node
.isRoot() && !me
.getRootVisible()),
53 childNodes
= node
.childNodes
,
54 len
= childNodes
&& childNodes
.length
, i
, matchingChildren
;
57 for (i
= 0; i
< len
; ++i
) {
58 matchingChildren
= me
.filterNodes(childNodes
[i
], filterFn
, match
|| bottomUpFiltering
) || matchingChildren
;
60 if (bottomUpFiltering
) {
61 match
= matchingChildren
|| match
;
65 node
.set("visible", match
, me
._silentOptions
);
71 var render_description = function(value
, metaData
, record
) {
72 var pdef
= record
.data
;
74 value
= pdef
.verbose_description
|| value
;
76 // TODO: try to render asciidoc correctly
78 metaData
.style
= 'white-space:pre-wrap;'
80 return Ext
.htmlEncode(value
);
83 var render_type = function(value
, metaData
, record
) {
84 var pdef
= record
.data
;
86 return pdef
['enum'] ? 'enum' : (pdef
.type
|| 'string');
89 var render_format = function(value
, metaData
, record
) {
90 var pdef
= record
.data
;
92 metaData
.style
= 'white-space:normal;'
95 return Ext
.htmlEncode(pdef
.typetext
);
98 return pdef
['enum'].join(' | ');
104 return Ext
.htmlEncode(pdef
.pattern
);
109 var render_docu = function(data
) {
112 // console.dir(data);
123 Ext
.Array
.each(['GET', 'POST', 'PUT', 'DELETE'], function(method
) {
124 var info
= md
[method
];
129 usage
+= "<table><tr><td>HTTP: </td><td>" + method
+ " /api2/json" + data
.path
+ "</td></tr><tr><td> </td></tr>";
130 usage
+= "<tr><td>CLI:</td><td>pvesh " + clicmdhash
[method
] + " " + data
.path
+ "</td></tr></table>";
134 title
: 'Description',
135 html
: Ext
.htmlEncode(info
.description
),
145 if (info
.parameters
&& info
.parameters
.properties
) {
147 var pstore
= Ext
.create('Ext.data.Store', {
148 model
: 'pve-param-schema',
152 groupField
: 'optional',
161 Ext
.Object
.each(info
.parameters
.properties
, function(name
, pdef
) {
168 var groupingFeature
= Ext
.create('Ext.grid.feature.Grouping',{
169 enableGroupingMenu
: false,
170 groupHeaderTpl
: '<tpl if="groupValue">Optional</tpl><tpl if="!groupValue">Required</tpl>'
176 features
: [groupingFeature
],
191 renderer
: render_type
,
196 dataIndex
: 'default',
202 renderer
: render_format
,
206 header
: 'Description',
207 dataIndex
: 'description',
208 renderer
: render_description
,
218 var retinf
= info
.returns
;
219 var rtype
= retinf
.type
;
220 if (!rtype
&& retinf
.items
)
225 var rpstore
= Ext
.create('Ext.data.Store', {
226 model
: 'pve-param-schema',
230 groupField
: 'optional',
240 if (rtype
=== 'array' && retinf
.items
.properties
) {
241 properties
= retinf
.items
.properties
;
244 if (rtype
=== 'object' && retinf
.properties
) {
245 properties
= retinf
.properties
;
248 Ext
.Object
.each(properties
, function(name
, pdef
) {
255 var groupingFeature
= Ext
.create('Ext.grid.feature.Grouping',{
256 enableGroupingMenu
: false,
257 groupHeaderTpl
: '<tpl if="groupValue">Optional</tpl><tpl if="!groupValue">Obligatory</tpl>'
261 returnhtml
= '<pre>items: ' + Ext
.htmlEncode(JSON
.stringify(retinf
.items
, null, 4)) + '</pre>';
264 if (retinf
.properties
) {
265 returnhtml
= returnhtml
|| '';
266 returnhtml
+= '<pre>properties:' + Ext
.htmlEncode(JSON
.stringify(retinf
.properties
, null, 4)) + '</pre>';
269 var rawSection
= Ext
.create('Ext.panel.Panel', {
270 bodyPadding
: '0px 10px 10px 10px',
277 title
: 'Returns: ' + rtype
,
278 features
: [groupingFeature
],
293 renderer
: render_type
,
298 dataIndex
: 'default',
304 renderer
: render_format
,
308 header
: 'Description',
309 dataIndex
: 'description',
310 renderer
: render_description
,
318 handler: function(btn
) {
319 rawSection
.setVisible(!rawSection
.isVisible());
320 btn
.setText(rawSection
.isVisible() ? 'Hide RAW' : 'Show RAW');
325 sections
.push(rawSection
);
331 if (!info
.permissions
) {
332 permhtml
= "Root only.";
334 if (info
.permissions
.description
) {
335 permhtml
+= "<div style='white-space:pre-wrap;padding-bottom:10px;'>" +
336 Ext
.htmlEncode(info
.permissions
.description
) + "</div>";
339 if (info
.permissions
.user
) {
340 if (!info
.permissions
.description
) {
341 if (info
.permissions
.user
=== 'world') {
342 permhtml
+= "Accessible without any authentication.";
343 } else if (info
.permissions
.user
=== 'all') {
344 permhtml
+= "Accessible by all authenticated users.";
346 permhtml
+= 'Onyl accessible by user "' +
347 info
.permissions
.user
+ '"';
350 } else if (info
.permissions
.check
) {
351 permhtml
+= "<pre>Check: " +
352 Ext
.htmlEncode(Ext
.JSON
.encode(info
.permissions
.check
)) + "</pre>";
354 permhtml
+= "Unknown systax!";
357 if (!info
.allowtoken
) {
358 permhtml
+= "<br />This API endpoint is not available for API tokens."
362 title
: 'Required permissions',
379 var ct
= Ext
.getCmp('docview');
380 ct
.setTitle("Path: " + data
.path
);
386 Ext
.define('Ext.form.SearchField', {
387 extend
: 'Ext.form.field.Text',
388 alias
: 'widget.searchfield',
390 emptyText
: 'Search...',
396 'change': function(){
398 var value
= this.getValue();
399 if (!Ext
.isEmpty(value
)) {
412 var tree
= Ext
.create('Ext.tree.Panel', {
413 title
: 'Resource Tree',
416 xtype
: 'searchfield',
422 tooltip
: 'Expand all',
423 tooltipType
: 'title',
424 callback
: (tree
) => tree
.expandAll(),
428 tooltip
: 'Collapse all',
429 tooltipType
: 'title',
430 callback
: (tree
) => tree
.collapseAll(),
440 selectionchange: function(v
, selections
) {
443 var rec
= selections
[0];
444 render_docu(rec
.data
);
445 location
.hash
= '#' + rec
.data
.path
;
450 Ext
.create('Ext.container.Viewport', {
452 renderTo
: Ext
.getBody(),
457 title
: 'Documentation',
467 var deepLink = function() {
468 var path
= window
.location
.hash
.substring(1).replace(/\/\s*$/, '')
469 var endpoint
= store
.findNode('path', path
);
472 tree
.getSelectionModel().select(endpoint
);
473 tree
.expandPath(endpoint
.getPath());
474 render_docu(endpoint
.data
);
477 window
.onhashchange
= deepLink
;