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 252C4790F8 for ; Fri, 1 Jul 2022 11:58:19 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 122418262 for ; Fri, 1 Jul 2022 11:57:49 +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 for ; Fri, 1 Jul 2022 11:57:48 +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 E40A24006B; Fri, 1 Jul 2022 11:57:47 +0200 (CEST) Message-ID: <3ac30ae3-8d45-3795-8afd-f24657f7ccd0@proxmox.com> Date: Fri, 1 Jul 2022 11:57:45 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:103.0) Gecko/20100101 Thunderbird/103.0 Content-Language: en-US To: Thomas Lamprecht , pmg-devel@lists.proxmox.com References: <20220701080324.1750557-1-d.csapak@proxmox.com> <7dbfea9d-6be7-ed4d-a505-6843c6f6f31e@proxmox.com> From: Dominik Csapak In-Reply-To: <7dbfea9d-6be7-ed4d-a505-6843c6f6f31e@proxmox.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.100 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment NICE_REPLY_A -0.001 Looks like a legit reply (A) SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: Re: [pmg-devel] [PATCH pmg-gui v2] StatTimeSelector: don't show invalid month/day combinations X-BeenThere: pmg-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Mail Gateway development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 01 Jul 2022 09:58:19 -0000 On 7/1/22 11:32, Thomas Lamprecht wrote: > On 01/07/2022 10:03, Dominik Csapak wrote: >> by limiting the store of the day selector by the selected month >> >> reported by a user in the forum: >> https://forum.proxmox.com/threads/wrong-calendar.111631/ >> > > looks functional, some code nits inline that would make this quite a bit > shorter (and thus easier/quicker to read and grasp), ideally with those > addressed (but also otherwise if you really don't find them sensible): > > Reviewed-by: Thomas Lamprecht > >> Signed-off-by: Dominik Csapak >> --- >> changes from v1: >> * use js 'Date' to correctly calculate the last day of the month >> including leapyears, etc. >> >> js/StatTimeSelector.js | 18 ++++++++++++++++++ >> 1 file changed, 18 insertions(+) >> >> diff --git a/js/StatTimeSelector.js b/js/StatTimeSelector.js >> index f01b058..eae2d91 100644 >> --- a/js/StatTimeSelector.js >> +++ b/js/StatTimeSelector.js >> @@ -73,7 +73,25 @@ Ext.define('PMG.StatTimeSelector', { >> Ext.GlobalEvents.fireEvent('pmgStatTimeSelectorUpdate', data); >> }, >> >> + updateDays: function() { > > really not hard feelings for this one, but would be something like `updateMaxDays` > or `updateDayLimit` slightly more telling? > >> + let yearsel = this.lookupReference('yearsel'); >> + let monthsel = this.lookupReference('monthsel'); > > nit: useless intermediate variables > >> + let daysel = this.lookupReference('daysel'); >> + let year = yearsel.getValue(); >> + let month = monthsel.getValue(); > > let year = this.lookupReference('yearsel').getValue(); > let month = this.lookupReference('monthsel').getValue(); > >> + // create a date for the next month, but day 0 which wraps to >> + // the last day of the current month. Our month is already >> + // 1 greater than what Date expects, so we don't have to add 1 > > I'd use 100 cc for comments to reduce vertical space and reword as: > > // get last day of current month through wrapping back day 0 from next (zero indexed) month > > a bit terse, but anybody that worked with JS's current date API just a bit would expect > anything sane here... > >> + let maxDays = new Date(year, month, 0).getDate(); >> + daysel.getStore().setFilters([{ > > In the spirit of above I'd drop the single use `daysel` too and instead do: > > this.lookupReference('daysel').setFilters([{ > >> + property: 'day', >> + operator: '<=', >> + value: maxDays, >> + }]); >> + }, >> + >> onSelect: function() { >> + this.updateDays(); >> this.updateVisibility(); >> }, >> > sure the changes make sense, sending as v3 although the comment does not fit in 100 columns here (takes up 103) would that be still ok, or should i try to find an even shorter sentence? (also after looking at it again, i'd use 'lookup' instead of 'lookupReference' since that's only an alias and much shorter)