From abde5f2bad192de9015c71cba6ac132d01a54c86 Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Mon, 5 Jul 2021 16:34:02 +0200 Subject: [PATCH] node/Tasks: add 'clear filter' button that does two things, show the user that some filters are active (even if filters are collapsed), and let the user to reset the filters all at once Signed-off-by: Dominik Csapak --- src/node/Tasks.js | 55 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/node/Tasks.js b/src/node/Tasks.js index dfe93dc..aa074b4 100644 --- a/src/node/Tasks.js +++ b/src/node/Tasks.js @@ -89,6 +89,13 @@ Ext.define('Proxmox.node.Tasks', { let vm = me.getViewModel(); vm.set('showFilter', pressed); }, + + clearFilter: function() { + let me = this; + me.lookup('filtertoolbar').query('field').forEach((field) => { + field.setValue(undefined); + }); + }, }, listeners: { @@ -140,6 +147,44 @@ Ext.define('Proxmox.node.Tasks', { return params; }, + filterCount: function(get) { + let count = 0; + if (get('typefilter')) { + count++; + } + let status = get('statusfilter'); + if ((Ext.isArray(status) && status.length > 0) || + (!Ext.isArray(status) && status)) { + count++; + } + if (get('since')) { + count++; + } + if (get('until')) { + count++; + } + + if (get('extraFilter')) { + let extraFilter = get('extraFilter'); + for (const value of Object.values(extraFilter)) { + if (value !== undefined && value !== null && value !== "") { + count++; + } + } + } + + return count; + }, + clearFilterText: function(get) { + let count = get('filterCount'); + let fieldMsg = ''; + if (count > 1) { + fieldMsg = ` (${count} ${gettext('Fields')})`; + } else if (count > 0) { + fieldMsg = ` (1 ${gettext('Field')})`; + } + return gettext('Clear Filter') + fieldMsg; + }, }, stores: { @@ -186,6 +231,16 @@ Ext.define('Proxmox.node.Tasks', { handler: 'reload', }, '->', + { + xtype: 'button', + bind: { + text: '{clearFilterText}', + disabled: '{!filterCount}', + }, + text: gettext('Clear Filter'), + enabled: false, + handler: 'clearFilter', + }, { xtype: 'button', enableToggle: true,