public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH widget-toolkit 1/2] api-viewer: fix #4271: display nested formats instead of [object Object]
@ 2022-10-12 13:23 Matthias Heiserer
  2022-10-12 13:23 ` [pve-devel] [PATCH widget-toolkit 2/2] show min/max for values without any other format Matthias Heiserer
  2022-11-17  7:30 ` [pve-devel] applied: [PATCH widget-toolkit 1/2] api-viewer: fix #4271: display nested formats instead of [object Object] Thomas Lamprecht
  0 siblings, 2 replies; 3+ messages in thread
From: Matthias Heiserer @ 2022-10-12 13:23 UTC (permalink / raw)
  To: pve-devel

I tried to keep the format as close to the HTML docs as possible, but there are a few discrepancies between HTML docs and how this patch displays parameters:
Instead of <enum>,the enum variants are displayed. [1]
Instead of <0|1>, <boolean> is displayed.

[1] The HTML docs explain parameters after the initial format string, which the GUI doesn't (and there's no space for that).
Showing the variants inline is the easiest way to not loose information here.

Signed-off-by: Matthias Heiserer <m.heiserer@proxmox.com>
---
 src/api-viewer/APIViewer.js | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/src/api-viewer/APIViewer.js b/src/api-viewer/APIViewer.js
index c6580bb..2b04b8c 100644
--- a/src/api-viewer/APIViewer.js
+++ b/src/api-viewer/APIViewer.js
@@ -79,6 +79,27 @@ Ext.onReady(function() {
 	return pdef.enum ? 'enum' : pdef.type || 'string';
     };
 
+    const renderFormatString = function(obj) {
+	if (!Ext.isObject(obj)) {
+	    return obj;
+	}
+	const mandatory = [];
+	const optional = [];
+	Object.entries(obj).forEach(function([name, param]) {
+	    let list = param.optional ? optional : mandatory;
+	    let str = param.default_key ? `[${name}=]` : `${name}=`;
+	    if (param.alias) {
+		return;
+	    } else if (param.enum) {
+		str += `(${param.enum?.join(' | ')})`;
+	    } else {
+		str += `<${param.format_description || param.pattern || param.type}>`;
+	    }
+	    list.push(str);
+	});
+	return mandatory.join(", ") + ' ' + optional.map(each => `[,${each}]`).join(' ');
+    };
+
     let render_simple_format = function(pdef, type_fallback) {
 	if (pdef.typetext) {
 	    return pdef.typetext;
@@ -87,7 +108,7 @@ Ext.onReady(function() {
 	    return pdef.enum.join(' | ');
 	}
 	if (pdef.format) {
-	    return pdef.format;
+	    return renderFormatString(pdef.format);
 	}
 	if (pdef.pattern) {
 	    return pdef.pattern;
-- 
2.30.2





^ permalink raw reply	[flat|nested] 3+ messages in thread

* [pve-devel] [PATCH widget-toolkit 2/2] show min/max for values without any other format
  2022-10-12 13:23 [pve-devel] [PATCH widget-toolkit 1/2] api-viewer: fix #4271: display nested formats instead of [object Object] Matthias Heiserer
@ 2022-10-12 13:23 ` Matthias Heiserer
  2022-11-17  7:30 ` [pve-devel] applied: [PATCH widget-toolkit 1/2] api-viewer: fix #4271: display nested formats instead of [object Object] Thomas Lamprecht
  1 sibling, 0 replies; 3+ messages in thread
From: Matthias Heiserer @ 2022-10-12 13:23 UTC (permalink / raw)
  To: pve-devel

Signed-off-by: Matthias Heiserer <m.heiserer@proxmox.com>
---

Optional followup

 src/api-viewer/APIViewer.js | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/api-viewer/APIViewer.js b/src/api-viewer/APIViewer.js
index 2b04b8c..879c9a3 100644
--- a/src/api-viewer/APIViewer.js
+++ b/src/api-viewer/APIViewer.js
@@ -119,6 +119,9 @@ Ext.onReady(function() {
 	if (type_fallback && pdef.type) {
 	    return `<${pdef.type}>`;
 	}
+	if (pdef.minimum || pdef.maximum) {
+	    return `${pdef.minimum || 'N'} - ${pdef.maximum || 'N'}`;
+	}
 	return '';
     };
 
-- 
2.30.2





^ permalink raw reply	[flat|nested] 3+ messages in thread

* [pve-devel] applied: [PATCH widget-toolkit 1/2] api-viewer: fix #4271: display nested formats instead of [object Object]
  2022-10-12 13:23 [pve-devel] [PATCH widget-toolkit 1/2] api-viewer: fix #4271: display nested formats instead of [object Object] Matthias Heiserer
  2022-10-12 13:23 ` [pve-devel] [PATCH widget-toolkit 2/2] show min/max for values without any other format Matthias Heiserer
@ 2022-11-17  7:30 ` Thomas Lamprecht
  1 sibling, 0 replies; 3+ messages in thread
From: Thomas Lamprecht @ 2022-11-17  7:30 UTC (permalink / raw)
  To: Proxmox VE development discussion, Matthias Heiserer

Am 12/10/2022 um 15:23 schrieb Matthias Heiserer:
> I tried to keep the format as close to the HTML docs as possible, but there are a few discrepancies between HTML docs and how this patch displays parameters:
> Instead of <enum>,the enum variants are displayed. [1]
> Instead of <0|1>, <boolean> is displayed.
> 
> [1] The HTML docs explain parameters after the initial format string, which the GUI doesn't (and there's no space for that).
> Showing the variants inline is the easiest way to not loose information here.

please use a text-width limit of <<70 for commit message text:

https://pve.proxmox.com/wiki/Developer_Documentation#Commits_and_Commit_Messages

I re-wrapped that on apply.


> 
> Signed-off-by: Matthias Heiserer <m.heiserer@proxmox.com>
> ---
>  src/api-viewer/APIViewer.js | 23 ++++++++++++++++++++++-
>  1 file changed, 22 insertions(+), 1 deletion(-)
> 
>

applied, thanks!




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-11-17  7:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-12 13:23 [pve-devel] [PATCH widget-toolkit 1/2] api-viewer: fix #4271: display nested formats instead of [object Object] Matthias Heiserer
2022-10-12 13:23 ` [pve-devel] [PATCH widget-toolkit 2/2] show min/max for values without any other format Matthias Heiserer
2022-11-17  7:30 ` [pve-devel] applied: [PATCH widget-toolkit 1/2] api-viewer: fix #4271: display nested formats instead of [object Object] Thomas Lamprecht

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal