[pve-devel] [PATCH manager 2/6] ui: factor out input panel for editing prune settings

Fabian Ebner f.ebner at proxmox.com
Mon Sep 6 13:32:27 CEST 2021


To be re-used for configuring job-specific retention options for
backups.

Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
 www/manager6/Makefile                     |  1 +
 www/manager6/panel/EditPruneInputPanel.js | 97 +++++++++++++++++++++++
 www/manager6/storage/Base.js              | 96 +---------------------
 3 files changed, 99 insertions(+), 95 deletions(-)
 create mode 100644 www/manager6/panel/EditPruneInputPanel.js

diff --git a/www/manager6/Makefile b/www/manager6/Makefile
index 75d355a5..3f81d9c4 100644
--- a/www/manager6/Makefile
+++ b/www/manager6/Makefile
@@ -79,6 +79,7 @@ JSSRC= 							\
 	grid/Replication.js				\
 	grid/ResourceGrid.js				\
 	panel/ConfigPanel.js				\
+	panel/EditPruneInputPanel.js			\
 	panel/HealthWidget.js				\
 	panel/IPSet.js					\
 	panel/NotesView.js				\
diff --git a/www/manager6/panel/EditPruneInputPanel.js b/www/manager6/panel/EditPruneInputPanel.js
new file mode 100644
index 00000000..d58db208
--- /dev/null
+++ b/www/manager6/panel/EditPruneInputPanel.js
@@ -0,0 +1,97 @@
+/*
+ * Input panel for prune settings with a keep-all option intended to be used as
+ * part of an edit/create window.
+ */
+Ext.define('PVE.panel.EditPruneInputPanel', {
+    extend: 'Proxmox.panel.PruneInputPanel',
+    xtype: 'pveEditPruneInputPanel',
+    mixins: ['Proxmox.Mixin.CBind'],
+
+    onlineHelp: 'vzdump_retention',
+
+    onGetValues: function(formValues) {
+	if (this.needMask) { // isMasked() may not yet be true if not rendered once
+	    return {};
+	} else if (this.isCreate && !this.rendered) {
+	    return { 'prune-backups': 'keep-all=1' };
+	}
+	delete formValues.delete;
+	let retention = PVE.Parser.printPropertyString(formValues);
+	if (retention === '') {
+	    if (this.isCreate) {
+		return {};
+	    }
+	    // always delete old 'maxfiles' on edit, we map it to keep-last on window load
+	    return {
+		'delete': ['prune-backups', 'maxfiles'],
+	    };
+	}
+	let options = { 'prune-backups': retention };
+	if (!this.isCreate) {
+	    options.delete = 'maxfiles';
+	}
+	return options;
+    },
+
+    updateComponents: function() {
+	let me = this;
+
+	let keepAll = me.down('proxmoxcheckbox[name=keep-all]').getValue();
+	let anyValue = false;
+	me.query('pmxPruneKeepField').forEach(field => {
+	    anyValue = anyValue || field.getValue() !== null;
+	    field.setDisabled(keepAll);
+	});
+	me.down('component[name=no-keeps-hint]').setHidden(anyValue || keepAll);
+    },
+
+    listeners: {
+	afterrender: function(panel) {
+	    if (panel.needMask) {
+		panel.down('component[name=no-keeps-hint]').setHtml('');
+		panel.mask(
+		    gettext('Backup content type not available for this storage.'),
+		);
+	    } else if (panel.isCreate) {
+		panel.down('proxmoxcheckbox[name=keep-all]').setValue(true);
+	    }
+	    panel.down('component[name=pbs-hint]').setHidden(!panel.isPBS);
+
+	    panel.query('pmxPruneKeepField').forEach(field => {
+		field.on('change', panel.updateComponents, panel);
+	    });
+	    panel.updateComponents();
+	},
+    },
+
+    columnT: {
+	xtype: 'proxmoxcheckbox',
+	name: 'keep-all',
+	boxLabel: gettext('Keep all backups'),
+	listeners: {
+	    change: function(field, newValue) {
+		let panel = field.up('pveEditPruneInputPanel');
+		panel.updateComponents();
+	    },
+	},
+    },
+
+    columnB: [
+	{
+	    xtype: 'component',
+	    userCls: 'pmx-hint',
+	    name: 'no-keeps-hint',
+	    hidden: true,
+	    padding: '5 1',
+	    html: gettext('Without any keep option, the node\'s vzdump.conf or `keep-all` is used as fallback for backup jobs'),
+	},
+	{
+	    xtype: 'component',
+	    userCls: 'pmx-hint',
+	    name: 'pbs-hint',
+	    hidden: true,
+	    padding: '5 1',
+	    html: gettext("It's preferred to configure backup retention directly on the Proxmox Backup Server."),
+	},
+    ],
+});
diff --git a/www/manager6/storage/Base.js b/www/manager6/storage/Base.js
index ee8b54e8..862c981b 100644
--- a/www/manager6/storage/Base.js
+++ b/www/manager6/storage/Base.js
@@ -55,100 +55,6 @@ Ext.define('PVE.panel.StorageBase', {
     },
 });
 
-Ext.define('PVE.panel.StoragePruneInputPanel', {
-    extend: 'Proxmox.panel.PruneInputPanel',
-    xtype: 'pveStoragePruneInputPanel',
-    mixins: ['Proxmox.Mixin.CBind'],
-
-    onlineHelp: 'vzdump_retention',
-
-    onGetValues: function(formValues) {
-	if (this.needMask) { // isMasked() may not yet be true if not rendered once
-	    return {};
-	} else if (this.isCreate && !this.rendered) {
-	    return { 'prune-backups': 'keep-all=1' };
-	}
-	delete formValues.delete;
-	let retention = PVE.Parser.printPropertyString(formValues);
-	if (retention === '') {
-	    if (this.isCreate) {
-		return {};
-	    }
-	    // always delete old 'maxfiles' on edit, we map it to keep-last on window load
-	    return {
-		'delete': ['prune-backups', 'maxfiles'],
-	    };
-	}
-	let options = { 'prune-backups': retention };
-	if (!this.isCreate) {
-	    options.delete = 'maxfiles';
-	}
-	return options;
-    },
-
-    updateComponents: function() {
-	let me = this;
-
-	let keepAll = me.down('proxmoxcheckbox[name=keep-all]').getValue();
-	let anyValue = false;
-	me.query('pmxPruneKeepField').forEach(field => {
-	    anyValue = anyValue || field.getValue() !== null;
-	    field.setDisabled(keepAll);
-	});
-	me.down('component[name=no-keeps-hint]').setHidden(anyValue || keepAll);
-    },
-
-    listeners: {
-	afterrender: function(panel) {
-	    if (panel.needMask) {
-		panel.down('component[name=no-keeps-hint]').setHtml('');
-		panel.mask(
-		    gettext('Backup content type not available for this storage.'),
-		);
-	    } else if (panel.isCreate) {
-		panel.down('proxmoxcheckbox[name=keep-all]').setValue(true);
-	    }
-	    panel.down('component[name=pbs-hint]').setHidden(!panel.isPBS);
-
-	    panel.query('pmxPruneKeepField').forEach(field => {
-		field.on('change', panel.updateComponents, panel);
-	    });
-	    panel.updateComponents();
-	},
-    },
-
-    columnT: {
-	xtype: 'proxmoxcheckbox',
-	name: 'keep-all',
-	boxLabel: gettext('Keep all backups'),
-	listeners: {
-	    change: function(field, newValue) {
-		let panel = field.up('pveStoragePruneInputPanel');
-		panel.updateComponents();
-	    },
-	},
-    },
-
-    columnB: [
-	{
-	    xtype: 'component',
-	    userCls: 'pmx-hint',
-	    name: 'no-keeps-hint',
-	    hidden: true,
-	    padding: '5 1',
-	    html: gettext('Without any keep option, the node\'s vzdump.conf or `keep-all` is used as fallback for backup jobs'),
-	},
-	{
-	    xtype: 'component',
-	    userCls: 'pmx-hint',
-	    name: 'pbs-hint',
-	    hidden: true,
-	    padding: '5 1',
-	    html: gettext("It's preferred to configure backup retention directly on the Proxmox Backup Server."),
-	},
-    ],
-});
-
 Ext.define('PVE.storage.BaseEdit', {
     extend: 'Proxmox.window.Edit',
 
@@ -191,7 +97,7 @@ Ext.define('PVE.storage.BaseEdit', {
 		items: [
 		    me.ipanel,
 		    {
-			xtype: 'pveStoragePruneInputPanel',
+			xtype: 'pveEditPruneInputPanel',
 			title: gettext('Backup Retention'),
 			isCreate: me.isCreate,
 			isPBS: me.ipanel.isPBS,
-- 
2.30.2






More information about the pve-devel mailing list