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 8C46CCA3D; Tue, 12 Apr 2022 12:35:10 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 4D247D40D; Tue, 12 Apr 2022 12:34:40 +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 D7CF4D2E0; 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 AB02E415F2; 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:20 +0200 Message-Id: <20220412103423.3845322-3-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.024 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 2/5] toolkit: add NotesView panel and NotesEdit window 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:35:10 -0000 move them here from pve so we can maintain them across several products Signed-off-by: Stefan Sterz --- src/Makefile | 2 + src/panel/NotesView.js | 129 ++++++++++++++++++++++++++++++++++++++++ src/window/NotesEdit.js | 38 ++++++++++++ 3 files changed, 169 insertions(+) create mode 100644 src/panel/NotesView.js create mode 100644 src/window/NotesEdit.js diff --git a/src/Makefile b/src/Makefile index abafc2c..dd7729e 100644 --- a/src/Makefile +++ b/src/Makefile @@ -66,6 +66,7 @@ JSSRC= \ panel/ACMEDomains.js \ panel/StatusView.js \ panel/TfaView.js \ + panel/NotesView.js \ window/Edit.js \ window/PasswordEdit.js \ window/SafeDestroy.js \ @@ -87,6 +88,7 @@ JSSRC= \ window/AddWebauthn.js \ window/AddYubico.js \ window/TfaEdit.js \ + window/NotesEdit.js \ node/APT.js \ node/APTRepositories.js \ node/NetworkEdit.js \ diff --git a/src/panel/NotesView.js b/src/panel/NotesView.js new file mode 100644 index 0000000..7c8299d --- /dev/null +++ b/src/panel/NotesView.js @@ -0,0 +1,129 @@ +Ext.define('PVE.panel.NotesView', { + extend: 'Ext.panel.Panel', + xtype: 'pveNotesView', + + title: gettext("Notes"), + bodyPadding: 10, + scrollable: true, + animCollapse: false, + maxLength: 64 * 1024, + + tbar: { + itemId: 'tbar', + hidden: true, + items: [ + { + text: gettext('Edit'), + handler: function() { + let view = this.up('panel'); + view.run_editor(); + }, + }, + ], + }, + + run_editor: function() { + let me = this; + Ext.create('PVE.window.NotesEdit', { + pveSelNode: me.pveSelNode, + url: me.url, + listeners: { + destroy: () => me.load(), + }, + autoShow: true, + }).setMaxLength(me.maxLength); + }, + + load: function() { + var me = this; + + Proxmox.Utils.API2Request({ + url: me.url, + waitMsgTarget: me, + failure: function(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 === ''); + } + }, + }); + }, + + listeners: { + render: function(c) { + var me = this; + me.getEl().on('dblclick', me.run_editor, me); + }, + afterlayout: function() { + let me = this; + if (me.collapsible && !me.getCollapsed() && me.collapseMode === 'always') { + me.setCollapsed(true); + me.collapseMode = ''; // only once, on initial load! + } + }, + }, + + 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'; + } + + me.callParent(); + if (type === 'node' || type === '') { // '' is for datacenter + me.down('#tbar').setVisible(true); + } else if (me.pveSelNode.data.template !== 1) { + me.setCollapsible(true); + me.collapseDirection = 'right'; + + let sp = Ext.state.Manager.getProvider(); + me.collapseMode = sp.get('guest-notes-collapse', 'never'); + + if (me.collapseMode === 'auto') { + me.setCollapsed(true); + } + } + me.load(); + }, +}); diff --git a/src/window/NotesEdit.js b/src/window/NotesEdit.js new file mode 100644 index 0000000..4649843 --- /dev/null +++ b/src/window/NotesEdit.js @@ -0,0 +1,38 @@ +Ext.define('PVE.window.NotesEdit', { + extend: 'Proxmox.window.Edit', + + title: gettext('Notes'), + onlineHelp: 'markdown_basics', + + width: 800, + height: '600px', + + resizable: true, + layout: 'fit', + + autoLoad: true, + defaultButton: undefined, + + setMaxLength: function(maxLength) { + let me = this; + + let area = me.down('textarea[name="description"]'); + area.maxLength = maxLength; + area.validate(); + + return me; + }, + + items: { + xtype: 'textarea', + name: 'description', + height: '100%', + value: '', + hideLabel: true, + emptyText: gettext('You can use Markdown for rich text formatting.'), + fieldStyle: { + 'white-space': 'pre-wrap', + 'font-family': 'monospace', + }, + }, +}); -- 2.30.2