[pbs-devel] [PATCH proxmox-backup 1/1] ui: dashboard: show node's repository/subscription status

Fabian Ebner f.ebner at proxmox.com
Fri Jul 9 14:44:16 CEST 2021


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 at proxmox.com>
---

Dependency bump for widget-toolkit is needed.

Built on top of Dominik's patches to refactor/extend the node info in
the Dashboard [0] (still applied for me).

[0]: https://lists.proxmox.com/pipermail/pbs-devel/2021-April/002788.html

 www/Dashboard.js      | 22 ++++++++++++++
 www/panel/NodeInfo.js | 68 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 90 insertions(+)

diff --git a/www/Dashboard.js b/www/Dashboard.js
index 18f174fe..70c2305b 100644
--- a/www/Dashboard.js
+++ b/www/Dashboard.js
@@ -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,
 	},
 	{
diff --git a/www/panel/NodeInfo.js b/www/panel/NodeInfo.js
index 17bf3812..fbd5aad5 100644
--- a/www/panel/NodeInfo.js
+++ b/www/panel/NodeInfo.js
@@ -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;
 
-- 
2.30.2






More information about the pbs-devel mailing list