public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Stefan Sterz <s.sterz@proxmox.com>
To: pbs-devel@lists.proxmox.com, pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH widget-toolkit v5 3/5] toolkit: refactor markdown based NotesView and NotesEdit
Date: Tue, 12 Apr 2022 12:34:21 +0200	[thread overview]
Message-ID: <20220412103423.3845322-4-s.sterz@proxmox.com> (raw)
In-Reply-To: <20220412103423.3845322-1-s.sterz@proxmox.com>

refactor them to make them more flexible and, thus, usable in pbs.
adds parameters for enabling the TBar, setting the help section in the
editing dialog and cleans up the code in some places

Signed-off-by: Stefan Sterz <s.sterz@proxmox.com>
---
 src/panel/NotesView.js  | 135 +++++++++++++++++++++++-----------------
 src/window/NotesEdit.js |   4 +-
 2 files changed, 81 insertions(+), 58 deletions(-)

diff --git a/src/panel/NotesView.js b/src/panel/NotesView.js
index 7c8299d..21dbdeb 100644
--- a/src/panel/NotesView.js
+++ b/src/panel/NotesView.js
@@ -1,12 +1,15 @@
-Ext.define('PVE.panel.NotesView', {
+Ext.define('Proxmox.panel.NotesView', {
     extend: 'Ext.panel.Panel',
-    xtype: 'pveNotesView',
+    xtype: 'pmxNotesView',
+    mixins: ['Proxmox.Mixin.CBind'],
 
     title: gettext("Notes"),
     bodyPadding: 10,
     scrollable: true,
     animCollapse: false,
     maxLength: 64 * 1024,
+    enableTBar: false,
+    onlineHelp: 'markdown_basics',
 
     tbar: {
 	itemId: 'tbar',
@@ -22,11 +25,55 @@ Ext.define('PVE.panel.NotesView', {
 	],
     },
 
+    cbindData: function(initalConfig) {
+	let me = this;
+	let type = '';
+
+	if (me.node) {
+	    me.url = `/api2/extjs/nodes/${me.node}/config`;
+	} else if (me.pveSelNode?.data?.id === 'root') {
+	    me.url = '/api2/extjs/cluster/options';
+	    type = me.pveSelNode?.data?.type;
+	} else {
+	    const nodename = me.pveSelNode?.data?.node;
+	    type = me.pveSelNode?.data?.type;
+
+	    if (!nodename) {
+		throw "no node name specified";
+	    }
+
+	    if (!Ext.Array.contains(['node', 'qemu', 'lxc'], type)) {
+		throw 'invalid type specified';
+	    }
+
+	    const vmid = me.pveSelNode?.data?.vmid;
+
+	    if (!vmid && type !== 'node') {
+		throw "no VM ID specified";
+	    }
+
+	    me.url = `/api2/extjs/nodes/${nodename}/`;
+
+	    // add the type specific path if qemu/lxc and set the backend's maxLen
+	    if (type === 'qemu' || type === 'lxc') {
+		me.url += `${type}/${vmid}/`;
+		me.maxLength = 8 * 1024;
+	    }
+
+	    me.url += 'config';
+	}
+
+	me.pveType = type;
+
+	me.load();
+	return {};
+    },
+
     run_editor: function() {
 	let me = this;
-	Ext.create('PVE.window.NotesEdit', {
-	    pveSelNode: me.pveSelNode,
+	Ext.create('Proxmox.window.NotesEdit', {
 	    url: me.url,
+	    onlineHelp: me.onlineHelp,
 	    listeners: {
 		destroy: () => me.load(),
 	    },
@@ -34,32 +81,34 @@ Ext.define('PVE.panel.NotesView', {
 	}).setMaxLength(me.maxLength);
     },
 
+    setNotes: function(value = '') {
+	let me = this;
+
+	let mdHtml = Proxmox.Markdown.parse(value);
+	me.update(mdHtml);
+
+	if (me.collapsible && me.collapseMode === 'auto') {
+	    me.setCollapsed(!value);
+	}
+    },
+
     load: function() {
-	var me = this;
+	let me = this;
 
 	Proxmox.Utils.API2Request({
 	    url: me.url,
 	    waitMsgTarget: me,
-	    failure: function(response, opts) {
+	    failure: (response, opts) => {
 		me.update(gettext('Error') + " " + response.htmlStatus);
 		me.setCollapsed(false);
 	    },
-	    success: function(response, opts) {
-		var data = response.result.data.description || '';
-
-		let mdHTML = Proxmox.Markdown.parse(data);
-		me.update(mdHTML);
-
-		if (me.collapsible && me.collapseMode === 'auto') {
-		    me.setCollapsed(data === '');
-		}
-	    },
+	    success: ({ result }) => me.setNotes(result.data.description),
 	});
     },
 
     listeners: {
 	render: function(c) {
-	    var me = this;
+	    let me = this;
 	    me.getEl().on('dblclick', me.run_editor, me);
 	},
 	afterlayout: function() {
@@ -71,49 +120,24 @@ Ext.define('PVE.panel.NotesView', {
 	},
     },
 
-    tools: [{
-	type: 'gear',
-	handler: function() {
-	    let view = this.up('panel');
-	    view.run_editor();
+    tools: [
+	{
+	    type: 'gear',
+	    handler: function() {
+		let view = this.up('panel');
+		view.run_editor();
+	    },
 	},
-    }],
+    ],
 
     initComponent: function() {
-	const me = this;
-	const type = me.pveSelNode.data.type;
-
-	if (me.pveSelNode.data.id === 'root') {
-	    me.url = '/api2/extjs/cluster/options';
-	} else {
-	    const nodename = me.pveSelNode.data.node;
-	    if (!nodename) {
-		throw "no node name specified";
-	    }
-
-	    if (!Ext.Array.contains(['node', 'qemu', 'lxc'], type)) {
-		throw 'invalid type specified';
-	    }
-
-	    const vmid = me.pveSelNode.data.vmid;
-	    if (!vmid && type !== 'node') {
-		throw "no VM ID specified";
-	    }
-
-	    me.url = `/api2/extjs/nodes/${nodename}/`;
-
-	    // add the type specific path if qemu/lxc and set the backend's maxLen
-	    if (type === 'qemu' || type === 'lxc') {
-		me.url += `${type}/${vmid}/`;
-		me.maxLength = 8 * 1024;
-	    }
-	    me.url += 'config';
-	}
-
+	let me = this;
 	me.callParent();
-	if (type === 'node' || type === '') { // '' is for datacenter
+
+	// '' is for datacenter
+	if (me.enableTBar === true || me.pveType === 'node' || me.pveType === '') {
 	    me.down('#tbar').setVisible(true);
-	} else if (me.pveSelNode.data.template !== 1) {
+	} else if (me.pveSelNode?.data?.template !== 1) {
 	    me.setCollapsible(true);
 	    me.collapseDirection = 'right';
 
@@ -124,6 +148,5 @@ Ext.define('PVE.panel.NotesView', {
 		me.setCollapsed(true);
 	    }
 	}
-	me.load();
     },
 });
diff --git a/src/window/NotesEdit.js b/src/window/NotesEdit.js
index 4649843..2de88f9 100644
--- a/src/window/NotesEdit.js
+++ b/src/window/NotesEdit.js
@@ -1,11 +1,11 @@
-Ext.define('PVE.window.NotesEdit', {
+Ext.define('Proxmox.window.NotesEdit', {
     extend: 'Proxmox.window.Edit',
 
     title: gettext('Notes'),
     onlineHelp: 'markdown_basics',
 
     width: 800,
-    height: '600px',
+    height: 600,
 
     resizable: true,
     layout: 'fit',
-- 
2.30.2





  parent reply	other threads:[~2022-04-12 10:34 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-12 10:34 [pve-devel] [PATCH proxmox-backup v5 0/5] fix 3067: add notes functionality in webui Stefan Sterz
2022-04-12 10:34 ` [pve-devel] [PATCH proxmox-backup v5 1/5] fix #3067: docs: add markdown primer from pve to pbs Stefan Sterz
2022-04-25  9:44   ` [pve-devel] applied: [pbs-devel] " Thomas Lamprecht
2022-04-12 10:34 ` [pve-devel] [PATCH widget-toolkit v5 2/5] toolkit: add NotesView panel and NotesEdit window Stefan Sterz
2022-04-13  9:43   ` [pve-devel] applied: [pbs-devel] " Thomas Lamprecht
2022-04-12 10:34 ` Stefan Sterz [this message]
2022-04-13  9:43   ` [pve-devel] applied: [pbs-devel] [PATCH widget-toolkit v5 3/5] toolkit: refactor markdown based NotesView and NotesEdit Thomas Lamprecht
2022-04-12 10:34 ` [pve-devel] [PATCH manager v5 4/5] ui: move NotesView panel and NotesEdit window to widget kit Stefan Sterz
2022-04-26 14:09   ` [pve-devel] applied: " Thomas Lamprecht
2022-04-12 10:34 ` [pve-devel] [PATCH proxmox-backup v5 5/5] fix #3067: ui: add a separate notes view for longer markdown notes Stefan Sterz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220412103423.3845322-4-s.sterz@proxmox.com \
    --to=s.sterz@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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