From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <m.heiserer@proxmox.com>
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 1818963371
 for <pve-devel@lists.proxmox.com>; Mon, 14 Feb 2022 15:02:35 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 0F99223342
 for <pve-devel@lists.proxmox.com>; Mon, 14 Feb 2022 15:02:05 +0100 (CET)
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 783672330B
 for <pve-devel@lists.proxmox.com>; Mon, 14 Feb 2022 15:02:03 +0100 (CET)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 4CCF6461D4
 for <pve-devel@lists.proxmox.com>; Mon, 14 Feb 2022 15:02:03 +0100 (CET)
From: Matthias Heiserer <m.heiserer@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Mon, 14 Feb 2022 15:01:40 +0100
Message-Id: <20220214140144.961041-4-m.heiserer@proxmox.com>
X-Mailer: git-send-email 2.30.2
In-Reply-To: <20220214140144.961041-1-m.heiserer@proxmox.com>
References: <20220214140144.961041-1-m.heiserer@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.004 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 -
Subject: [pve-devel] [RFC manager 2/5] GUI: Utils: add comment renderer and
 field provider
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Mon, 14 Feb 2022 14:02:35 -0000

These render functions are used when displaying comments in a
separate column.
The `commentField` utility simplifies creation of comments.

Signed-off-by: Matthias Heiserer <m.heiserer@proxmox.com>
---
 www/manager6/Utils.js | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/www/manager6/Utils.js b/www/manager6/Utils.js
index aafe359a..2d03f611 100644
--- a/www/manager6/Utils.js
+++ b/www/manager6/Utils.js
@@ -1803,6 +1803,45 @@ Ext.define('PVE.Utils', {
 
 	return undefined;
     },
+
+    renderComment: function(key, metaData, rec, rowIndex, colIndex, store, pending) {
+	if (rec && rec.data && rec.data.value) {
+	    let properties = PVE.Parser.parsePropertyString(rec.data.value, rec.data.key);
+	    if (properties && properties.comment) {
+		return properties.comment;
+	    }
+	}
+	// Try to extract a comment from the separate fields
+	// This is needed for single value fields like bios and memory
+	if (rec && rec.id) {
+	    let hw_name = rec.id;
+	    let comment = this.getObjectValue(`${hw_name}_comment`, undefined);
+	    if (comment) {
+		return comment;
+	    }
+	}
+	return PVE.Utils.noneText;
+    },
+
+    renderValueWithoutComment: function(context) {
+	return function(value, ...args) {
+	    if (value && typeof value === "string") {
+		value = value.replace(/comment=[^,]*(,|$)/, "");
+	    }
+	    return this.renderValue(value, ...args);
+	}.bind(context);
+    },
+
+    commentField: function(name = 'comment') {
+	return {
+	    xtype: 'textfield',
+	    name: name,
+	    fieldLabel: gettext('comment'),
+	    allowBlank: true,
+	    emptyText: '',
+	    defaultValue: '',
+	};
+    },
 },
 
     singleton: true,
-- 
2.30.2