[pbs-devel] [PATCH v6 proxmox-widget-toolkit 2/3] APT repositories: add warnings

Fabian Ebner f.ebner at proxmox.com
Fri Jun 11 13:44:02 CEST 2021


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

No changes from v5.

 src/node/APTRepositories.js | 170 +++++++++++++++++++++++++++++++++++-
 1 file changed, 168 insertions(+), 2 deletions(-)

diff --git a/src/node/APTRepositories.js b/src/node/APTRepositories.js
index 71b141c..5f8b2e5 100644
--- a/src/node/APTRepositories.js
+++ b/src/node/APTRepositories.js
@@ -3,6 +3,7 @@ Ext.define('apt-repolist', {
     fields: [
 	'Path',
 	'Number',
+	'OfficialHost',
 	'FileType',
 	'Enabled',
 	'Comment',
@@ -56,6 +57,22 @@ Ext.define('Proxmox.node.APTRepositoriesGrid', {
     sortableColumns: false,
 
     columns: [
+	{
+	    header: gettext('Official'),
+	    dataIndex: 'OfficialHost',
+	    renderer: function(value, cell, record) {
+		let icon = (cls) => `<i class="fa fa-fw ${cls}"></i>`;
+
+		if (value === undefined || value === null) {
+		    return icon('fa-question-circle-o');
+		}
+		if (!value) {
+		    return icon('fa-times critical');
+		}
+		return icon('fa-check good');
+	    },
+	    width: 70,
+	},
 	{
 	    header: gettext('Enabled'),
 	    dataIndex: 'Enabled',
@@ -128,9 +145,90 @@ Ext.define('Proxmox.node.APTRepositoriesGrid', {
 	},
     ],
 
+    check_repositories: function(gridData) {
+	let me = this;
+	let panel = me.up('proxmoxNodeAPTRepositories');
+	let vm = panel.getViewModel();
+
+	let params = {};
+	if (panel.digest !== undefined) {
+	    params.digest = panel.digest;
+	}
+
+	Proxmox.Utils.API2Request({
+	    url: `/nodes/${me.nodename}/apt/checkrepositories`,
+	    method: 'GET',
+	    params: params,
+	    failure: function(response, opts) {
+		me.rowBodyFeature.getAdditionalData = function() {
+		    return {
+			rowBody: undefined,
+			rowBodyCls: Ext.baseCSSPrefix + 'grid-row-body-hidden',
+		    };
+		};
+		me.store.loadData(gridData);
+		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 = {};
+		let officialHosts = {};
+
+		let addLine = function(obj, key, line) {
+		    if (obj[key]) {
+			obj[key] += "\n";
+			obj[key] += line;
+		    } else {
+			obj[key] = line;
+		    }
+		};
+
+		for (const info of data.infos) {
+		    const key = `${info.path}:${info.number}`;
+		    if (info.kind === 'warning' ||
+			(info.kind === 'ignore-pre-upgrade-warning' && !me.majorUpgradeAllowed)) {
+			addLine(warnings, key, gettext('Warning') + ": " + info.message);
+		    } else if (info.kind === 'badge' && info.message === 'official host name') {
+			officialHosts[key] = true;
+		    }
+		}
+
+		gridData.forEach(function(record) {
+		    const key = `${record.Path}:${record.Number}`;
+		    record.OfficialHost = !!officialHosts[key];
+		});
+
+		me.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,
+		    };
+		};
+
+		me.store.loadData(gridData);
+	    },
+	});
+    },
+
     initComponent: function() {
 	let me = this;
 
+	if (!me.nodename) {
+	    throw "no node name specified";
+	}
+
 	let store = Ext.create('Ext.data.Store', {
 	    model: 'apt-repolist',
 	    groupField: 'Path',
@@ -142,6 +240,8 @@ 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"]})',
@@ -153,7 +253,8 @@ Ext.define('Proxmox.node.APTRepositoriesGrid', {
 	Ext.apply(me, {
 	    store: store,
 	    selModel: sm,
-	    features: [groupingFeature],
+	    rowBodyFeature: rowBodyFeature,
+	    features: [groupingFeature, rowBodyFeature],
 	});
 
 	me.callParent();
@@ -164,19 +265,59 @@ Ext.define('Proxmox.node.APTRepositories', {
     extend: 'Ext.panel.Panel',
 
     xtype: 'proxmoxNodeAPTRepositories',
+    mixins: ['Proxmox.Mixin.CBind'],
 
     digest: undefined,
 
     viewModel: {
 	data: {
 	    errorCount: 0,
+	    subscriptionActive: '',
+	    noSubscriptionRepo: '',
+	    enterpriseRepo: '',
 	},
 	formulas: {
 	    noErrors: (get) => get('errorCount') === 0,
+	    mainWarning: function(get) {
+		if (get('subscriptionActive') === '' ||
+		    get('noSubscriptionRepo') === '' ||
+		    get('enterpriseRepo') === '') {
+		    return '';
+		}
+
+		let withStyle = (msg) => "<div style='color:red;'><i class='fa fa-fw " +
+		    "fa-exclamation-triangle'></i>" + gettext('Warning') + ': ' + msg + "</div>";
+
+		if (!get('subscriptionActive') && get('enterpriseRepo')) {
+		    return withStyle(gettext('The enterprise repository is ' +
+			'configured, but there is no active subscription!'));
+		}
+
+		if (get('noSubscriptionRepo')) {
+		    return withStyle(gettext('The no-subscription repository is ' +
+			'not recommended for production use!'));
+		}
+
+		if (!get('enterpriseRepo') && !get('noSubscriptionRepo')) {
+		    return withStyle(gettext('Neither the enterprise repository ' +
+			'nor the no-subscription repository is configured!'));
+		}
+
+		return '';
+	    },
 	},
     },
 
     items: [
+	{
+	    title: gettext('Warning'),
+	    name: 'repositoriesMainWarning',
+	    xtype: 'panel',
+	    bind: {
+		title: '{mainWarning}',
+		hidden: '{!mainWarning}',
+	    },
+	},
 	{
 	    xtype: 'proxmoxNodeAPTRepositoriesErrors',
 	    name: 'repositoriesErrors',
@@ -188,6 +329,10 @@ Ext.define('Proxmox.node.APTRepositories', {
 	{
 	    xtype: 'proxmoxNodeAPTRepositoriesGrid',
 	    name: 'repositoriesGrid',
+	    cbind: {
+		nodename: '{nodename}',
+		majorUpgradeAllowed: '{majorUpgradeAllowed}',
+	    },
 	},
     ],
 
@@ -202,6 +347,25 @@ Ext.define('Proxmox.node.APTRepositories', {
 	},
     ],
 
+    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);
+	    },
+	});
+    },
+
     reload: function() {
 	let me = this;
 	let vm = me.getViewModel();
@@ -231,11 +395,13 @@ Ext.define('Proxmox.node.APTRepositories', {
 
 	    me.digest = digest;
 
-	    repoGrid.store.loadData(gridData);
+	    repoGrid.check_repositories(gridData); // loads gridData after updating it
 
 	    vm.set('errorCount', errors.length);
 	    errorGrid.store.loadData(errors);
 	});
+
+	me.check_subscription();
     },
 
     listeners: {
-- 
2.20.1






More information about the pbs-devel mailing list