From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <d.csapak@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 7668971E6B
 for <pve-devel@lists.proxmox.com>; Wed, 30 Jun 2021 17:15:35 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id E43F61B7BA
 for <pve-devel@lists.proxmox.com>; Wed, 30 Jun 2021 17:15:04 +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 941A91B6C8
 for <pve-devel@lists.proxmox.com>; Wed, 30 Jun 2021 17:15:02 +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 6C66646767
 for <pve-devel@lists.proxmox.com>; Wed, 30 Jun 2021 17:15:02 +0200 (CEST)
From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Wed, 30 Jun 2021 17:14:58 +0200
Message-Id: <20210630151459.231895-5-d.csapak@proxmox.com>
X-Mailer: git-send-email 2.30.2
In-Reply-To: <20210630151459.231895-1-d.csapak@proxmox.com>
References: <20210630151459.231895-1-d.csapak@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.708 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
 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [values.name, warning.property]
Subject: [pve-devel] [PATCH widget-toolkit 4/5] APTRepositories: make the
 Suites warnings inline errors
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: Wed, 30 Jun 2021 15:15:35 -0000

by iterating only once over the info array and adding them directly
to the records this way we can avoid iterating over the records
again

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 src/node/APTRepositories.js | 100 +++++++++++++++++-------------------
 1 file changed, 46 insertions(+), 54 deletions(-)

diff --git a/src/node/APTRepositories.js b/src/node/APTRepositories.js
index 23cd984..de0197b 100644
--- a/src/node/APTRepositories.js
+++ b/src/node/APTRepositories.js
@@ -157,8 +157,20 @@ Ext.define('Proxmox.node.APTRepositoriesGrid', {
 	{
 	    header: gettext('Suites'),
 	    dataIndex: 'Suites',
-	    renderer: function(suites, cell, record) {
-		return suites.join(' ');
+	    renderer: function(suites, metaData, record) {
+		let err = '';
+		if (record.data.warnings && record.data.warnings.length > 0) {
+		    let txt = [gettext('Warning')];
+		    record.data.warnings.forEach((warning) => {
+			if (warning.property === 'Suites') {
+			    txt.push(warning.message);
+			}
+		    });
+		    metaData.tdAttr = `data-qtip="${Ext.htmlEncode(txt.join('<br>'))}"`;
+		    metaData.tdCls = 'proxmox-invalid-row';
+		    err = '<i class="fa fa-fw critical fa-exclamation-circle"></i> ';
+		}
+		return suites.join(' ') + err;
 	    },
 	    width: 130,
 	},
@@ -209,53 +221,6 @@ Ext.define('Proxmox.node.APTRepositoriesGrid', {
 	},
     ],
 
-    addAdditionalInfos: function(gridData, infos) {
-	let me = this;
-
-	let warnings = {};
-	let origins = {};
-
-	let addLine = function(obj, key, line) {
-	    if (obj[key]) {
-		obj[key] += "\n";
-		obj[key] += line;
-	    } else {
-		obj[key] = line;
-	    }
-	};
-
-	for (const info of infos) {
-	    const key = `${info.path}:${info.index}`;
-	    if (info.kind === 'warning' ||
-		(info.kind === 'ignore-pre-upgrade-warning' && !me.majorUpgradeAllowed)
-	    ) {
-		addLine(warnings, key, gettext('Warning') + ": " + info.message);
-	    } else if (info.kind === 'origin') {
-		origins[key] = info.message;
-	    }
-	}
-
-	gridData.forEach(function(record) {
-	    const key = `${record.Path}:${record.Index}`;
-	    record.Origin = origins[key];
-	});
-
-	me.rowBodyFeature.getAdditionalData = function(innerData, rowIndex, record, orig) {
-	    let headerCt = this.view.headerCt;
-	    let colspan = headerCt.getColumnCount();
-
-	    const key = `${innerData.Path}:${innerData.Index}`;
-	    const warning_text = warnings[key];
-
-	    return {
-		rowBody: '<div style="color: red; white-space: pre-line">' +
-		    Ext.String.htmlEncode(warning_text) + '</div>',
-		rowBodyCls: warning_text ? '' : Ext.baseCSSPrefix + 'grid-row-body-hidden',
-		rowBodyColspan: colspan,
-	    };
-	};
-    },
-
     initComponent: function() {
 	let me = this;
 
@@ -274,8 +239,6 @@ Ext.define('Proxmox.node.APTRepositoriesGrid', {
 	    ],
 	});
 
-	let rowBodyFeature = Ext.create('Ext.grid.feature.RowBody', {});
-
 	let groupingFeature = Ext.create('Ext.grid.feature.Grouping', {
 	    groupHeaderTpl: '{[ "File: " + values.name ]} ({rows.length} ' +
 		'repositor{[values.rows.length > 1 ? "ies" : "y"]})',
@@ -287,8 +250,7 @@ Ext.define('Proxmox.node.APTRepositoriesGrid', {
 	Ext.apply(me, {
 	    store: store,
 	    selModel: sm,
-	    rowBodyFeature: rowBodyFeature,
-	    features: [groupingFeature, rowBodyFeature],
+	    features: [groupingFeature],
 	});
 
 	me.callParent();
@@ -494,16 +456,46 @@ Ext.define('Proxmox.node.APTRepositories', {
 		errors = data.errors;
 		digest = data.digest;
 
+		let infos = {};
+		for (const info of data.infos) {
+		    let path = info.path;
+		    let idx = info.index;
+
+		    if (!infos[path]) {
+			infos[path] = {};
+		    }
+		    if (!infos[path][idx]) {
+			infos[path][idx] = {
+			    origin: '',
+			    warnings: [],
+			};
+		    }
+
+		    if (info.kind === 'origin') {
+			infos[path][idx].origin = info.message;
+		    } else if (info.kind === 'warning' ||
+			(info.kind === 'ignore-pre-upgrade-warning' && !repoGrid.majorUpgradeAllowed)
+		    ) {
+			infos[path][idx].warnings.push(info);
+		    } else {
+			throw 'unknown info';
+		    }
+		}
+
+
 		files.forEach(function(file) {
 		    for (let n = 0; n < file.repositories.length; n++) {
 			let repo = file.repositories[n];
 			repo.Path = file.path;
 			repo.Index = n;
+			if (infos[file.path] && infos[file.path][n]) {
+			    repo.Origin = infos[file.path][n].origin || Proxmox.Utils.UnknownText;
+			    repo.warnings = infos[file.path][n].warnings || [];
+			}
 			gridData.push(repo);
 		    }
 		});
 
-		repoGrid.addAdditionalInfos(gridData, data.infos);
 		repoGrid.store.loadData(gridData);
 
 		me.updateStandardRepos(data['standard-repos']);
-- 
2.30.2