From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 3B5AAB556; Wed, 9 Aug 2023 12:55:51 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 1FF0A13DB3; Wed, 9 Aug 2023 12:55:51 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS; Wed, 9 Aug 2023 12:55:50 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 42B924381B; Wed, 9 Aug 2023 12:55:50 +0200 (CEST) From: Christian Ebner To: pve-devel@lists.proxmox.com, pmg-devel@lists.proxmox.com Date: Wed, 9 Aug 2023 12:55:27 +0200 Message-Id: <20230809105529.58459-3-c.ebner@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230809105529.58459-1-c.ebner@proxmox.com> References: <20230809105529.58459-1-c.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.149 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH v2 proxmox-widget-toolkit 2/2] fix #4442: Extend LogView for firewall datetime filtering X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Aug 2023 10:55:51 -0000 Extends the current panels date filtering capability to date-time based filtering, and adds a config option to switch between livemode and filter mode, analogous to the JournalView panel. The `submitFormat` config is introduced to adapt the formatting of params values for their corresponding api calls. Signed-off-by: Christian Ebner --- changes since v1: - Also bind labels of input fields to `livemode` state src/panel/LogView.js | 89 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 80 insertions(+), 9 deletions(-) diff --git a/src/panel/LogView.js b/src/panel/LogView.js index 44aa8e3..cacc861 100644 --- a/src/panel/LogView.js +++ b/src/panel/LogView.js @@ -22,19 +22,28 @@ Ext.define('Proxmox.panel.LogView', { updateParams: function() { let me = this; let viewModel = me.getViewModel(); - let since = viewModel.get('since'); - let until = viewModel.get('until'); - if (viewModel.get('hide_timespan')) { + + if (viewModel.get('hide_timespan') || viewModel.get('livemode')) { return; } + let since = viewModel.get('since'); + let until = viewModel.get('until'); + if (since > until) { Ext.Msg.alert('Error', 'Since date must be less equal than Until date.'); return; } - viewModel.set('params.since', Ext.Date.format(since, 'Y-m-d')); - viewModel.set('params.until', Ext.Date.format(until, 'Y-m-d') + ' 23:59:59'); + let submitFormat = viewModel.get('submitFormat'); + + viewModel.set('params.since', Ext.Date.format(since, submitFormat)); + if (submitFormat === 'Y-m-d') { + viewModel.set('params.until', Ext.Date.format(until, submitFormat) + ' 23:59:59'); + } else { + viewModel.set('params.until', Ext.Date.format(until, submitFormat)); + } + me.getView().loadTask.delay(200); }, @@ -175,6 +184,27 @@ Ext.define('Proxmox.panel.LogView', { } }, + onLiveMode: function() { + let me = this; + let viewModel = me.getViewModel(); + viewModel.set('livemode', true); + viewModel.set('params', { start: 0, limit: 510 }); + + let view = me.getView(); + delete view.content; + view.scrollToEnd = true; + me.updateView([], true, false); + }, + + onTimespan: function() { + let me = this; + me.getViewModel().set('livemode', false); + me.updateView([], false); + // Directly apply currently selected values without update + // button click. + me.updateParams(); + }, + init: function(view) { let me = this; @@ -189,6 +219,7 @@ Ext.define('Proxmox.panel.LogView', { viewModel.set('since', since); viewModel.set('params.limit', view.pageSize); viewModel.set('hide_timespan', !view.log_select_timespan); + viewModel.set('submitFormat', view.submitFormat); me.lookup('content').setStyle('line-height', `${view.lineHeight}px`); view.loadTask = new Ext.util.DelayedTask(me.doLoad, me); @@ -224,6 +255,8 @@ Ext.define('Proxmox.panel.LogView', { data: { until: null, since: null, + submitFormat: 'Y-m-d', + livemode: true, hide_timespan: false, data: { start: 0, @@ -263,32 +296,70 @@ Ext.define('Proxmox.panel.LogView', { }, items: [ '->', - 'Since: ', { - xtype: 'datefield', + xtype: 'segmentedbutton', + items: [ + { + text: gettext('Live Mode'), + bind: { + pressed: '{livemode}', + }, + handler: 'onLiveMode', + }, + { + text: gettext('Select Timespan'), + bind: { + pressed: '{!livemode}', + }, + handler: 'onTimespan', + }, + ], + }, + { + xtype: 'box', + autoEl: { cn: gettext('Since') + ':' }, + bind: { + disabled: '{livemode}', + }, + }, + { + xtype: 'proxmoxDateTimeField', name: 'since_date', reference: 'since', format: 'Y-m-d', bind: { + disabled: '{livemode}', value: '{since}', maxValue: '{until}', + submitFormat: '{submitFormat}', }, }, - 'Until: ', { - xtype: 'datefield', + xtype: 'box', + autoEl: { cn: gettext('Until') + ':' }, + bind: { + disabled: '{livemode}', + }, + }, + { + xtype: 'proxmoxDateTimeField', name: 'until_date', reference: 'until', format: 'Y-m-d', bind: { + disabled: '{livemode}', value: '{until}', minValue: '{since}', + submitFormat: '{submitFormat}', }, }, { xtype: 'button', text: 'Update', handler: 'updateParams', + bind: { + disabled: '{livemode}', + }, }, ], }, -- 2.39.2