[pbs-devel] [PATCH proxmox-backup v2 4/4] ui: datastore content: add 'more actions' menu to actions

Dominik Csapak d.csapak at proxmox.com
Tue Dec 5 11:53:45 CET 2023


and move change owner and change protection there, since these are not
that often used. Also add the 'Show Information' action there for
snapshots, as this was not available via actions.

Refactor the menu creation for this.

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 www/datastore/Content.js | 110 ++++++++++++++++++++++-----------------
 1 file changed, 61 insertions(+), 49 deletions(-)

diff --git a/www/datastore/Content.js b/www/datastore/Content.js
index f715f814..8f063287 100644
--- a/www/datastore/Content.js
+++ b/www/datastore/Content.js
@@ -806,6 +806,48 @@ Ext.define('PBS.DataStoreContent', {
 	    }).show();
 	},
 
+	onMoreActions: function(panel, rI, cI, item, event, record) {
+	    this.showContextMenu(panel, record, event, false);
+	},
+
+	showContextMenu: function(panel, record, event, rightClick) {
+	    let me = this;
+	    event.stopEvent();
+	    let menu;
+	    let view = me.getView();
+	    let createControllerCallback = function(name) {
+		return function() {
+		    me[name](view, undefined, undefined, undefined, undefined, record);
+		};
+	    };
+	    if (record.data.ty === 'group') {
+		let params = {
+		    title: gettext('Group'),
+		    onChangeOwner: createControllerCallback('onChangeOwner'),
+		};
+		if (rightClick) {
+		    params.onVerify = createControllerCallback('onVerify');
+		    params.onPrune = createControllerCallback('onPrune');
+		    params.onForget = createControllerCallback('onForget');
+		}
+		menu = Ext.create('PBS.datastore.GroupCmdMenu', params);
+	    } else if (record.data.ty === 'dir') {
+		let params = {
+		    title: gettext('Snapshot'),
+		    onProtectionChange: createControllerCallback('onProtectionChange'),
+		    onShowInformation: createControllerCallback('onShowInformation'),
+		};
+		if (rightClick) {
+		    params.onVerify = createControllerCallback('onVerify');
+		    params.onForget = createControllerCallback('onForget');
+		}
+		menu = Ext.create('PBS.datastore.SnapshotCmdMenu', params);
+	    }
+	    if (menu) {
+		menu.showAt(event.getXY());
+	    }
+	},
+
 	filter: function(item, value) {
 	    if (item.data.text.indexOf(value) !== -1) {
 		return true;
@@ -882,35 +924,7 @@ Ext.define('PBS.DataStoreContent', {
 	    }
 	},
 	itemcontextmenu: function(panel, record, item, index, event) {
-	    event.stopEvent();
-	    let menu;
-	    let view = panel.up('pbsDataStoreContent');
-	    let controller = view.getController();
-	    let createControllerCallback = function(name) {
-		return function() {
-		    controller[name](view, undefined, undefined, undefined, undefined, record);
-		};
-	    };
-	    if (record.data.ty === 'group') {
-		menu = Ext.create('PBS.datastore.GroupCmdMenu', {
-		    title: gettext('Group'),
-		    onVerify: createControllerCallback('onVerify'),
-		    onChangeOwner: createControllerCallback('onChangeOwner'),
-		    onPrune: createControllerCallback('onPrune'),
-		    onForget: createControllerCallback('onForget'),
-		});
-	    } else if (record.data.ty === 'dir') {
-		menu = Ext.create('PBS.datastore.SnapshotCmdMenu', {
-		    title: gettext('Snapshot'),
-		    onVerify: createControllerCallback('onVerify'),
-		    onProtectionChange: createControllerCallback('onProtectionChange'),
-		    onShowInformation: createControllerCallback('onShowInformation'),
-		    onForget: createControllerCallback('onForget'),
-		});
-	    }
-	    if (menu) {
-		menu.showAt(event.getXY());
-	    }
+	    this.getController().showContextMenu(panel, record, event, true);
 	},
     },
 
@@ -1000,30 +1014,12 @@ Ext.define('PBS.DataStoreContent', {
 		        ? 'pve-icon-verify-lettering' : 'pmx-hidden',
 		    isActionDisabled: (v, r, c, i, rec) => !!rec.data.leaf,
                 },
-                {
-		    handler: 'onChangeOwner',
-		    getClass: (v, m, { data }) => data.ty === 'group' ? 'fa fa-user' : 'pmx-hidden',
-		    getTip: (v, m, rec) => Ext.String.format(gettext("Change owner of '{0}'"), v),
-		    isActionDisabled: (v, r, c, i, { data }) => data.ty !== 'group',
-                },
 		{
 		    handler: 'onPrune',
 		    getTip: (v, m, rec) => Ext.String.format(gettext("Prune '{0}'"), v),
 		    getClass: (v, m, { data }) => data.ty === 'group' ? 'fa fa-scissors' : 'pmx-hidden',
 		    isActionDisabled: (v, r, c, i, { data }) => data.ty !== 'group',
 		},
-		{
-		    handler: 'onProtectionChange',
-		    getTip: (v, m, rec) => Ext.String.format(gettext("Change protection of '{0}'"), v),
-		    getClass: (v, m, rec) => {
-			if (rec.data.ty === 'dir') {
-			    let extraCls = rec.data.protected ? 'good' : 'faded';
-			    return `fa fa-shield ${extraCls}`;
-			}
-			return 'pmx-hidden';
-		    },
-		    isActionDisabled: (v, r, c, i, rec) => rec.data.ty !== 'dir',
-		},
 		{
 		    handler: 'onForget',
 		    getTip: (v, m, { data }) => {
@@ -1044,6 +1040,12 @@ Ext.define('PBS.DataStoreContent', {
 		        : 'pmx-hidden',
 		    isActionDisabled: (v, r, c, i, { data }) => false,
 		},
+		{
+		    handler: 'onMoreActions',
+		    getTip: (v, m, { data }) => gettext('Show more actions'),
+		    getClass: (v, m, { data }) => data.ty === 'group' || data.ty === 'dir' ? 'fa fa-bars' : 'pmx-hidden',
+		    isActionDisabled: (v, r, c, i, { data }) => data.ty !== 'group' && data.ty !== 'dir',
+		},
 		{
 		    handler: 'downloadFile',
 		    getTip: (v, m, rec) => Ext.String.format(gettext("Download '{0}'"), v),
@@ -1325,7 +1327,12 @@ Ext.define('PBS.datastore.GroupCmdMenu', {
 		hidden: '{!onPrune}',
 	    },
 	},
-	{ xtype: 'menuseparator' },
+	{
+	    xtype: 'menuseparator',
+	    cbind: {
+		hidden: '{!onForget}',
+	    },
+	},
 	{
 	    text: gettext('Remove'),
 	    iconCls: 'fa critical fa-trash-o',
@@ -1374,7 +1381,12 @@ Ext.define('PBS.datastore.SnapshotCmdMenu', {
 		disabled: '{!onShowInformation}',
 	    },
 	},
-	{ xtype: 'menuseparator' },
+	{
+	    xtype: 'menuseparator',
+	    cbind: {
+		hidden: '{!onForget}',
+	    },
+	},
 	{
 	    text: gettext('Remove'),
 	    iconCls: 'fa critical fa-trash-o',
-- 
2.30.2





More information about the pbs-devel mailing list