public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pbs-devel] [PATCH proxmox-backup 0/2] support multi-line comments in
@ 2023-09-15  9:46 Gabriel Goller
  2023-09-15  9:46 ` [pbs-devel] [PATCH proxmox-backup 1/2] close #4589: allow multi-line comments in datastore notes Gabriel Goller
  2023-09-15  9:46 ` [pbs-devel] [PATCH widget-toolkit 2/2] window: edit: added `convertNewlines` config Gabriel Goller
  0 siblings, 2 replies; 3+ messages in thread
From: Gabriel Goller @ 2023-09-15  9:46 UTC (permalink / raw)
  To: pbs-devel

Support multi-line comments in pbs datastore notes. As we
don't support multi-line configs in the `datastore.cfg` config
file, we convert the '\n' to '<br>' tags.


widget-toolkit

Gabriel Goller (1):
  window: edit: added `convertNewlines` config

 src/window/Edit.js | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)


proxmox-backup:

Gabriel Goller (1):
  close #4589: allow multi-line comments in datastore notes

 pbs-api-types/src/datastore.rs | 6 +++---
 www/datastore/Notes.js         | 5 +++--
 2 files changed, 6 insertions(+), 5 deletions(-)


-- 
2.39.2





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

* [pbs-devel] [PATCH proxmox-backup 1/2] close #4589: allow multi-line comments in datastore notes
  2023-09-15  9:46 [pbs-devel] [PATCH proxmox-backup 0/2] support multi-line comments in Gabriel Goller
@ 2023-09-15  9:46 ` Gabriel Goller
  2023-09-15  9:46 ` [pbs-devel] [PATCH widget-toolkit 2/2] window: edit: added `convertNewlines` config Gabriel Goller
  1 sibling, 0 replies; 3+ messages in thread
From: Gabriel Goller @ 2023-09-15  9:46 UTC (permalink / raw)
  To: pbs-devel

Converting '\n' to '<br>' tags then store it in the config
(`datastore.cfg`) file.

Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---
 pbs-api-types/src/datastore.rs | 6 +++---
 www/datastore/Notes.js         | 5 +++--
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/pbs-api-types/src/datastore.rs b/pbs-api-types/src/datastore.rs
index 73c4890e..4e555d0c 100644
--- a/pbs-api-types/src/datastore.rs
+++ b/pbs-api-types/src/datastore.rs
@@ -11,8 +11,8 @@ use proxmox_schema::{
 
 use crate::{
     Authid, CryptMode, Fingerprint, MaintenanceMode, Userid, DATASTORE_NOTIFY_STRING_SCHEMA,
-    GC_SCHEDULE_SCHEMA, PROXMOX_SAFE_ID_FORMAT, PRUNE_SCHEDULE_SCHEMA, SHA256_HEX_REGEX,
-    SINGLE_LINE_COMMENT_SCHEMA, UPID,
+    GC_SCHEDULE_SCHEMA, MULTI_LINE_COMMENT_SCHEMA, PROXMOX_SAFE_ID_FORMAT, PRUNE_SCHEDULE_SCHEMA,
+    SHA256_HEX_REGEX, SINGLE_LINE_COMMENT_SCHEMA, UPID,
 };
 
 const_regex! {
@@ -241,7 +241,7 @@ pub const DATASTORE_TUNING_STRING_SCHEMA: Schema = StringSchema::new("Datastore
         },
         comment: {
             optional: true,
-            schema: SINGLE_LINE_COMMENT_SCHEMA,
+            schema: MULTI_LINE_COMMENT_SCHEMA,
         },
         "gc-schedule": {
             optional: true,
diff --git a/www/datastore/Notes.js b/www/datastore/Notes.js
index 2928b7ec..300603fc 100644
--- a/www/datastore/Notes.js
+++ b/www/datastore/Notes.js
@@ -21,10 +21,11 @@ Ext.define('PBS.DataStoreNotes', {
 	    title: gettext('Comment'),
 	    width: 600,
 	    resizable: true,
+	    convertNewlines: true,
 	    layout: 'fit',
 	    defaultButton: undefined,
 	    items: {
-		xtype: 'textfield',
+		xtype: 'textareafield',
 		name: 'comment',
 		value: '',
 		hideLabel: true,
@@ -42,7 +43,7 @@ Ext.define('PBS.DataStoreNotes', {
     setNotes: function(value) {
 	let me = this;
 	var data = value || '';
-	me.update(Ext.htmlEncode(data));
+	me.update(data);
 
 	if (me.collapsible && me.collapseMode === 'auto') {
 	    me.setCollapsed(data === '');
-- 
2.39.2





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

* [pbs-devel] [PATCH widget-toolkit 2/2] window: edit: added `convertNewlines` config
  2023-09-15  9:46 [pbs-devel] [PATCH proxmox-backup 0/2] support multi-line comments in Gabriel Goller
  2023-09-15  9:46 ` [pbs-devel] [PATCH proxmox-backup 1/2] close #4589: allow multi-line comments in datastore notes Gabriel Goller
@ 2023-09-15  9:46 ` Gabriel Goller
  1 sibling, 0 replies; 3+ messages in thread
From: Gabriel Goller @ 2023-09-15  9:46 UTC (permalink / raw)
  To: pbs-devel

When setting `convertNewlines` to true, all the '\n' will
be converted to '<br>' tags and vice-versa. This means we
can press enter in a `textfieldarea`, save the config and
we get a '<br>' in the config file. When editing the value,
the '<br>' will be converted back to a '\n'.

Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---

Note: Implemented to close #4589 (support multi-line comments)

 src/window/Edit.js | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/window/Edit.js b/src/window/Edit.js
index 7f94e30..97cd4d2 100644
--- a/src/window/Edit.js
+++ b/src/window/Edit.js
@@ -66,6 +66,9 @@ Ext.define('Proxmox.window.Edit', {
     // onlineHelp of our first item, if set.
     onlineHelp: undefined,
 
+    // converts newlines '\n' to html '<br>' tags and vice-versa
+    convertNewlines: false,
+
     isValid: function() {
 	let me = this;
 
@@ -83,7 +86,15 @@ Ext.define('Proxmox.window.Edit', {
 
 	form.getFields().each(function(field) {
 	    if (!field.up('inputpanel') && (!dirtyOnly || field.isDirty())) {
-		Proxmox.Utils.assemble_field_data(values, field.getSubmitData());
+		let fieldData = field.getSubmitData();
+		if (me.convertNewlines) {
+		    for (let key in fieldData) {
+			if (typeof fieldData[key] === 'string' || fieldData[key] instanceof String) {
+			    fieldData[key] = fieldData[key].replaceAll('\n', '<br>');
+			}
+		    }
+		}
+		Proxmox.Utils.assemble_field_data(values, fieldData);
 	    }
 	});
 
@@ -105,7 +116,13 @@ Ext.define('Proxmox.window.Edit', {
 	        (f.id === id || f.name === id || f.dataIndex === id) && !f.up('inputpanel'),
 	    );
 	    fields.each((field) => {
+		if (me.convertNewlines) {
+		    if (typeof val === 'string' || val instanceof String) {
+			val = val.replaceAll('<br>', '\n');
+		    }
+		}
 		field.setValue(val);
+
 		if (form.trackResetOnLoad) {
 		    field.resetOriginalValue();
 		}
-- 
2.39.2





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

end of thread, other threads:[~2023-09-15  9:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-15  9:46 [pbs-devel] [PATCH proxmox-backup 0/2] support multi-line comments in Gabriel Goller
2023-09-15  9:46 ` [pbs-devel] [PATCH proxmox-backup 1/2] close #4589: allow multi-line comments in datastore notes Gabriel Goller
2023-09-15  9:46 ` [pbs-devel] [PATCH widget-toolkit 2/2] window: edit: added `convertNewlines` config Gabriel Goller

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