ui: dashboard: show node's repository/subscription status

Mostly copied from PVE, slightly adapted to be consistent with other
things in the dashboard, e.g. use a store for the repository info.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
This commit is contained in:
Fabian Ebner 2021-07-09 14:44:16 +02:00 committed by Thomas Lamprecht
parent 01284de0b2
commit 4672273fe6
2 changed files with 90 additions and 0 deletions

View File

@ -59,6 +59,11 @@ Ext.define('PBS.Dashboard', {
}
},
updateRepositoryStatus: function(store, records, success) {
if (!success) { return; }
let me = this;
me.lookup('nodeInfo').setRepositoryInfo(records[0].data['standard-repos']);
},
updateSubscription: function(store, records, success) {
if (!success) { return; }
@ -67,6 +72,7 @@ Ext.define('PBS.Dashboard', {
// 2 = all good, 1 = different leves, 0 = none
let subStatus = status.toLowerCase() === 'active' ? 2 : 0;
me.lookup('subscription').setSubStatus(subStatus);
me.lookup('nodeInfo').setSubscriptionStatus(subStatus);
},
updateTasks: function(store, records, success) {
@ -131,6 +137,21 @@ Ext.define('PBS.Dashboard', {
},
stores: {
repositories: {
storeid: 'dash-repositories',
type: 'update',
interval: 15000,
autoStart: true,
autoLoad: true,
autoDestroy: true,
proxy: {
type: 'proxmox',
url: '/api2/json/nodes/localhost/apt/repositories',
},
listeners: {
load: 'updateRepositoryStatus',
},
},
subscription: {
storeid: 'dash-subscription',
type: 'update',
@ -204,6 +225,7 @@ Ext.define('PBS.Dashboard', {
items: [
{
xtype: 'pbsNodeInfoPanel',
reference: 'nodeInfo',
height: 280,
},
{

View File

@ -20,6 +20,37 @@ Ext.define('PBS.NodeInfoPanel', {
padding: '0 15 5 15',
},
viewModel: {
data: {
subscriptionActive: '',
noSubscriptionRepo: '',
enterpriseRepo: '',
testRepo: '',
},
formulas: {
repoStatus: function(get) {
if (get('subscriptionActive') === '' || get('enterpriseRepo') === '') {
return '';
}
if (get('noSubscriptionRepo') || get('testRepo')) {
return 'non-production';
} else if (get('subscriptionActive') && get('enterpriseRepo')) {
return 'ok';
} else if (!get('subscriptionActive') && get('enterpriseRepo')) {
return 'no-sub';
} else if (!get('enterpriseRepo') || !get('noSubscriptionRepo') || !get('testRepo')) {
return 'no-repo';
}
return 'unknown';
},
repoStatusMessage: function(get) {
const status = get('repoStatus');
return Proxmox.Utils.formatNodeRepoStatus(status, 'Proxmox Backup Server');
},
},
},
controller: {
xclass: 'Ext.app.ViewController',
@ -147,6 +178,18 @@ Ext.define('PBS.NodeInfoPanel', {
textField: 'kversion',
value: '',
},
{
itemId: 'repositoryStatus',
colspan: 2,
printBar: false,
title: gettext('Repository Status'),
setValue: function(value) { // for binding below
this.updateValue(value);
},
bind: {
value: '{repoStatusMessage}',
},
},
],
updateTitle: function() {
@ -155,6 +198,31 @@ Ext.define('PBS.NodeInfoPanel', {
me.setTitle(Proxmox.NodeName + ' (' + gettext('Uptime') + ': ' + uptime + ')');
},
setRepositoryInfo: function(standardRepos) {
let me = this;
let vm = me.getViewModel();
for (const standardRepo of standardRepos) {
const handle = standardRepo.handle;
const status = standardRepo.status;
if (handle === "enterprise") {
vm.set('enterpriseRepo', status);
} else if (handle === "no-subscription") {
vm.set('noSubscriptionRepo', status);
} else if (handle === "test") {
vm.set('testRepo', status);
}
}
},
setSubscriptionStatus: function(status) {
let me = this;
let vm = me.getViewModel();
vm.set('subscriptionActive', status);
},
initComponent: function() {
let me = this;