From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id C13E4CA1E; Tue, 12 Apr 2022 12:34:39 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B9078D409; Tue, 12 Apr 2022 12:34:39 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id CFFDED2DF; Tue, 12 Apr 2022 12:34:34 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id A8ADD4164F; Tue, 12 Apr 2022 12:34:34 +0200 (CEST) From: Stefan Sterz To: pbs-devel@lists.proxmox.com, pve-devel@lists.proxmox.com Date: Tue, 12 Apr 2022 12:34:21 +0200 Message-Id: <20220412103423.3845322-4-s.sterz@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220412103423.3845322-1-s.sterz@proxmox.com> References: <20220412103423.3845322-1-s.sterz@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.025 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [data.id] Subject: [pve-devel] [PATCH widget-toolkit v5 3/5] toolkit: refactor markdown based NotesView and NotesEdit X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Apr 2022 10:34:39 -0000 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 --- 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