node/APTRepositories: rework top status and error grid

instead of having a title bar and a seperate error grid,
add an always visible panel that displays the status (ok, warning, errors)
which also contains the error grid (if necessary, ala ceph summary)

this makes the panel more consistent to use and it is immediatly
visible if something is wrong

this also adds a test for the 'test' repositories, as well as a test
for not correctly configured suites

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2021-07-02 12:48:59 +02:00 committed by Thomas Lamprecht
parent fbbe68fd69
commit f59d1076d7

View File

@ -108,11 +108,9 @@ Ext.define('Proxmox.node.APTRepositoriesErrors', {
xtype: 'proxmoxNodeAPTRepositoriesErrors', xtype: 'proxmoxNodeAPTRepositoriesErrors',
title: gettext('Errors'),
store: {}, store: {},
border: false, scrollable: true,
viewConfig: { viewConfig: {
stripeRows: false, stripeRows: false,
@ -419,6 +417,50 @@ Ext.define('Proxmox.node.APTRepositories', {
let rec = selection[0]; let rec = selection[0];
let vm = me.getViewModel(); let vm = me.getViewModel();
vm.set('selectionenabled', rec.get('Enabled')); vm.set('selectionenabled', rec.get('Enabled'));
vm.notify();
},
updateState: function() {
let me = this;
let vm = me.getViewModel();
if (vm.get('errorCount') > 0) {
vm.set('state', {
iconCls: Proxmox.Utils.get_health_icon('critical', true),
text: gettext('Error parsing repositories'),
});
return;
}
let text = gettext('Repositories are configured in a recommended way');
let status = 'warning';
let activeSubscription = vm.get('subscriptionActive');
let enterprise = vm.get('enterpriseRepo');
let nosubscription = vm.get('noSubscriptionRepo');
let test = vm.get('testRepo');
let wrongSuites = vm.get('suitesWarning');
if (!activeSubscription && enterprise) {
text = gettext('The enterprise repository is enabled, but there is no active subscription!');
} else if (nosubscription) {
text = gettext('The no-subscription repository is not recommended for production use!');
} else if (test) {
text = gettext('The test repository is not recommended for production use!');
} else if (!enterprise && !nosubscription && !test) {
text = Ext.String.format(gettext('No {0} repository is enabled!'), vm.get('product'));
} else if (wrongSuites) {
text = gettext('Some Suites are misconfigured');
} else {
status = 'good';
}
let iconCls = Proxmox.Utils.get_health_icon(status, true);
vm.set('state', {
iconCls,
text,
});
}, },
}, },
@ -426,40 +468,18 @@ Ext.define('Proxmox.node.APTRepositories', {
data: { data: {
product: 'Proxmox VE', // default product: 'Proxmox VE', // default
errorCount: 0, errorCount: 0,
suitesWarning: false,
subscriptionActive: '', subscriptionActive: '',
noSubscriptionRepo: '', noSubscriptionRepo: '',
enterpriseRepo: '', enterpriseRepo: '',
testRepo: '',
selectionenabled: false, selectionenabled: false,
state: {},
}, },
formulas: { formulas: {
noErrors: (get) => get('errorCount') === 0, noErrors: (get) => get('errorCount') === 0,
enableButtonText: (get) => get('selectionenabled') enableButtonText: (get) => get('selectionenabled')
? gettext('Disable') : gettext('Enable'), ? gettext('Disable') : gettext('Enable'),
mainWarning: function(get) {
// Not yet initialized
if (get('subscriptionActive') === '' ||
get('enterpriseRepo') === '') {
return '';
}
let icon = `<i class='fa fa-fw fa-exclamation-triangle critical'></i>`;
let fmt = (msg) => `<div class="black">${icon}${gettext('Warning')}: ${msg}</div>`;
if (!get('subscriptionActive') && get('enterpriseRepo')) {
return fmt(gettext('The enterprise repository is enabled, but there is no active subscription!'));
}
if (get('noSubscriptionRepo')) {
return fmt(gettext('The no-subscription repository is not recommended for production use!'));
}
if (!get('enterpriseRepo') && !get('noSubscriptionRepo')) {
let msg = Ext.String.format(gettext('No {0} repository is enabled!'), get('product'));
return fmt(msg);
}
return '';
},
}, },
}, },
@ -471,32 +491,50 @@ Ext.define('Proxmox.node.APTRepositories', {
items: [ items: [
{ {
xtype: 'header', xtype: 'panel',
baseCls: 'x-panel-header', border: false,
bind: { layout: {
hidden: '{!mainWarning}', type: 'hbox',
title: '{mainWarning}', align: 'stretch',
},
},
{
xtype: 'box',
bind: {
hidden: '{!mainWarning}',
},
height: 5,
},
{
xtype: 'proxmoxNodeAPTRepositoriesErrors',
name: 'repositoriesErrors',
hidden: true,
padding: '0 0 5 0',
bind: {
hidden: '{noErrors}',
}, },
height: 150,
title: gettext('Status'),
items: [
{
xtype: 'box',
flex: 1,
margin: 10,
data: {
iconCls: Proxmox.Utils.get_health_icon(undefined, true),
text: '',
},
bind: {
data: '{state}',
},
tpl: [
'<center>',
'<i class="fa fa-4x {iconCls}"></i>',
'<br/><br/>',
'{text}',
'</center>',
],
},
{
xtype: 'proxmoxNodeAPTRepositoriesErrors',
name: 'repositoriesErrors',
flex: 2,
hidden: true,
margin: 10,
bind: {
hidden: '{noErrors}',
},
},
],
}, },
{ {
xtype: 'proxmoxNodeAPTRepositoriesGrid', xtype: 'proxmoxNodeAPTRepositoriesGrid',
name: 'repositoriesGrid', name: 'repositoriesGrid',
flex: 1,
cbind: { cbind: {
nodename: '{nodename}', nodename: '{nodename}',
}, },
@ -519,6 +557,7 @@ Ext.define('Proxmox.node.APTRepositories', {
const res = response.result; const res = response.result;
const subscription = !(!res || !res.data || res.data.status.toLowerCase() !== 'active'); const subscription = !(!res || !res.data || res.data.status.toLowerCase() !== 'active');
vm.set('subscriptionActive', subscription); vm.set('subscriptionActive', subscription);
me.getController().updateState();
}, },
}); });
}, },
@ -538,7 +577,10 @@ Ext.define('Proxmox.node.APTRepositories', {
vm.set('enterpriseRepo', status); vm.set('enterpriseRepo', status);
} else if (handle === "no-subscription") { } else if (handle === "no-subscription") {
vm.set('noSubscriptionRepo', status); vm.set('noSubscriptionRepo', status);
} else if (handle === 'test') {
vm.set('testRepo', status);
} }
me.getController().updateState();
addButton.repoInfo.push(standardRepo); addButton.repoInfo.push(standardRepo);
addButton.digest = me.digest; addButton.digest = me.digest;
@ -557,6 +599,7 @@ Ext.define('Proxmox.node.APTRepositories', {
let gridData = []; let gridData = [];
let errors = []; let errors = [];
let digest; let digest;
let suitesWarning = false;
if (success && records.length > 0) { if (success && records.length > 0) {
let data = records[0].data; let data = records[0].data;
@ -585,6 +628,9 @@ Ext.define('Proxmox.node.APTRepositories', {
(info.kind === 'ignore-pre-upgrade-warning' && !repoGrid.majorUpgradeAllowed) (info.kind === 'ignore-pre-upgrade-warning' && !repoGrid.majorUpgradeAllowed)
) { ) {
infos[path][idx].warnings.push(info); infos[path][idx].warnings.push(info);
if (!suitesWarning && info.property === 'Suites') {
suitesWarning = true;
}
} else { } else {
throw 'unknown info'; throw 'unknown info';
} }
@ -612,6 +658,9 @@ Ext.define('Proxmox.node.APTRepositories', {
me.digest = digest; me.digest = digest;
vm.set('errorCount', errors.length); vm.set('errorCount', errors.length);
vm.set('suitesWarning', suitesWarning);
me.getController().updateState();
errorGrid.store.loadData(errors); errorGrid.store.loadData(errors);
}); });