[pbs-devel] [RFC v2 widget-toolkit 10/10] APT: show warnings for repositories

Fabian Ebner f.ebner at proxmox.com
Fri Feb 26 16:09:59 CET 2021


Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---

Changes from v1:
    * Use the row body feature to pin warnings to the repository they are for
      and make warnings more prominent.
    * Also check the subscription status.

Sent as an RFC, because there's probably a better way than using the
title bar for the global warning.

 src/node/APTRepositories.js | 116 +++++++++++++++++++++++++++++++++++-
 1 file changed, 115 insertions(+), 1 deletion(-)

diff --git a/src/node/APTRepositories.js b/src/node/APTRepositories.js
index f4a3a43..c8033df 100644
--- a/src/node/APTRepositories.js
+++ b/src/node/APTRepositories.js
@@ -21,6 +21,51 @@ Ext.define('Proxmox.node.APTRepositories', {
 
     sortableColumns: false,
 
+    viewModel: {
+	data: {
+	    subscriptionActive: '',
+	    noSubscriptionRepo: '',
+	    enterpriseRepo: '',
+	},
+	formulas: {
+	    globalWarning: function(get) {
+		if (get('subscriptionActive') === '' ||
+		    get('noSubscriptionRepo') === '' ||
+		    get('enterpriseRepo') === '') {
+		    return '';
+		}
+
+		if (!get('subscriptionActive') && get('enterpriseRepo')) {
+		    return "WARNING: The enterprise repository is configured " +
+			"but there is no active subscription!";
+		}
+
+		if (get('noSubscriptionRepo')) {
+		    return "WARNING: The no-subscription repository is not " +
+			"recommended for production use!";
+		}
+
+		if (!get('enterpriseRepo') && !get('noSubscriptionRepo')) {
+		    return "WARNING: Neither the enterprise nor the " +
+			"no-subscription repository is active!";
+		}
+
+		return '';
+	    },
+	},
+    },
+
+    tbar: [
+	{
+	    xtype: 'label',
+	    text: 'default',
+	    style: 'color: red;',
+	    bind: {
+		text: '{globalWarning}',
+	    },
+	},
+    ],
+
     columns: [
 	{
 	    header: gettext('Enabled'),
@@ -94,6 +139,71 @@ Ext.define('Proxmox.node.APTRepositories', {
 	},
     ],
 
+    check_repositories: function(rowBodyFeature) {
+	let me = this;
+	let vm = me.getViewModel();
+
+	Proxmox.Utils.API2Request({
+	    url: `/nodes/${me.nodename}/apt/checkrepositories`,
+	    method: 'GET',
+	    failure: function(response, opts) {
+		Ext.Msg.alert(gettext('Error'), response.htmlStatus);
+	    },
+	    success: function(response, opts) {
+		const data = response.result.data;
+
+		vm.set('enterpriseRepo', data.enterprise);
+		vm.set('noSubscriptionRepo', data.nosubscription);
+
+		let warnings = {};
+		for (const warning of data.warnings) {
+		    const key = `${warning.Path}:${warning.Number}`;
+		    if (warnings[key]) {
+			warnings[key] += "\n";
+			warnings[key] += "Warning: " + warning.Warning;
+		    } else {
+			warnings[key] = "Warning: " + warning.Warning;
+		    }
+		}
+
+		rowBodyFeature.getAdditionalData = function(innerData, rowIndex, record, orig) {
+		    let headerCt = this.view.headerCt;
+		    let colspan = headerCt.getColumnCount();
+
+		    const key = `${innerData.Path}:${innerData.Number}`;
+		    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,
+		    };
+		};
+	    },
+	});
+    },
+
+    check_subscription: function() {
+	let me = this;
+	let vm = me.getViewModel();
+
+	Proxmox.Utils.API2Request({
+	    url: `/nodes/${me.nodename}/subscription`,
+	    method: 'GET',
+	    failure: function(response, opts) {
+		Ext.Msg.alert(gettext('Error'), response.htmlStatus);
+	    },
+	    success: function(response, opts) {
+		const res = response.result;
+		const subscription = !(res === null || res === undefined ||
+		    !res || res.data.status.toLowerCase() !== 'active');
+		vm.set('subscriptionActive', subscription);
+	    },
+	});
+    },
+
     initComponent: function() {
 	let me = this;
 
@@ -116,6 +226,8 @@ Ext.define('Proxmox.node.APTRepositories', {
 	    ],
 	});
 
+	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"]})',
@@ -124,6 +236,8 @@ Ext.define('Proxmox.node.APTRepositories', {
 
 	let reload = function() {
 	    store.load();
+	    me.check_repositories(rowBodyFeature);
+	    me.check_subscription();
 	};
 
 	let sm = Ext.create('Ext.selection.RowModel', {});
@@ -131,7 +245,7 @@ Ext.define('Proxmox.node.APTRepositories', {
 	Ext.apply(me, {
 	    store: store,
 	    selModel: sm,
-	    features: [groupingFeature],
+	    features: [groupingFeature, rowBodyFeature],
 	    listeners: {
 		activate: reload,
 	    },
-- 
2.20.1






More information about the pbs-devel mailing list