[pve-devel] [PATCH manager] fix #4873: use last used backup storage for the storage selector

Dominik Csapak d.csapak at proxmox.com
Mon Nov 20 15:18:52 CET 2023


for this, we invent the 'storageStateId' parameter that is undeifned by
default, but if set, the storage selector saves it's value on every
change there and on initial load (when no value is set from outside)
loads it from there and uses that as its value.

for now only use it for the selection of backup storages namely in:
* backup grid
* "backup now" edit window
* backup job edit window

in the future we could use that to have a 'last used disk image' or
'last used iso' storage too if this approach fits

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---

the backup job edit is a bit weird and probably warrants a bit of
discussion, since the interaction when editing an existing job is imho
unexpected:

 1. select backup storage X in backup grid
 2. edit a backup job where storage Y is selected (that happens
    correctly) but don't touch the storage field
 3. now storage Y is the last used and selected on the grids

 www/manager6/dc/Backup.js            |  1 +
 www/manager6/form/StorageSelector.js | 14 ++++++++++++++
 www/manager6/grid/BackupView.js      |  1 +
 www/manager6/window/Backup.js        |  1 +
 4 files changed, 17 insertions(+)

diff --git a/www/manager6/dc/Backup.js b/www/manager6/dc/Backup.js
index 9aae4090..28b41b2b 100644
--- a/www/manager6/dc/Backup.js
+++ b/www/manager6/dc/Backup.js
@@ -250,6 +250,7 @@ Ext.define('PVE.dc.BackupEdit', {
 				{
 				    xtype: 'pveStorageSelector',
 				    reference: 'storageSelector',
+				    storageStateId: 'pve-last-backup-storage',
 				    fieldLabel: gettext('Storage'),
 				    clusterView: true,
 				    storageContent: 'backup',
diff --git a/www/manager6/form/StorageSelector.js b/www/manager6/form/StorageSelector.js
index 872bc1ab..0a43712f 100644
--- a/www/manager6/form/StorageSelector.js
+++ b/www/manager6/form/StorageSelector.js
@@ -147,6 +147,15 @@ Ext.define('PVE.form.StorageSelector', {
 	me.reloadStorageList();
     },
 
+    listeners: {
+	change: function(selector, storage) {
+	    if (selector.storageStateId){
+		let sp = Ext.state.Manager.getProvider();
+		sp.set(selector.storageStateId, storage);
+	    }
+	},
+    },
+
     initComponent: function() {
 	var me = this;
 
@@ -168,6 +177,11 @@ Ext.define('PVE.form.StorageSelector', {
 	me.callParent();
 
 	me.setNodename(nodename);
+
+	if ((!me.value || !me.value.length) && me.storageStateId) {
+	    let sp = Ext.state.Manager.getProvider();
+	    me.setValue(sp.get(me.storageStateId));
+	}
     },
 }, function() {
     Ext.define('pve-storage-status', {
diff --git a/www/manager6/grid/BackupView.js b/www/manager6/grid/BackupView.js
index 65340dcb..8af51b34 100644
--- a/www/manager6/grid/BackupView.js
+++ b/www/manager6/grid/BackupView.js
@@ -104,6 +104,7 @@ Ext.define('PVE.grid.BackupView', {
 
 	var storagesel = Ext.create('PVE.form.StorageSelector', {
 	    nodename: nodename,
+	    storageStateId: 'pve-last-backup-storage',
 	    fieldLabel: gettext('Storage'),
 	    labelAlign: 'right',
 	    storageContent: 'backup',
diff --git a/www/manager6/window/Backup.js b/www/manager6/window/Backup.js
index 8d8c9ff0..2b263a9a 100644
--- a/www/manager6/window/Backup.js
+++ b/www/manager6/window/Backup.js
@@ -73,6 +73,7 @@ Ext.define('PVE.window.Backup', {
 
 	var storagesel = Ext.create('PVE.form.StorageSelector', {
 	    nodename: me.nodename,
+	    storageStateId: 'pve-last-backup-storage',
 	    name: 'storage',
 	    fieldLabel: gettext('Storage'),
 	    storageContent: 'backup',
-- 
2.30.2






More information about the pve-devel mailing list