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 5F1465B4FA for ; Tue, 7 Jul 2020 11:56:23 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 51F64263B8 for ; Tue, 7 Jul 2020 11:56:23 +0200 (CEST) Received-SPF: pass (proxmox.com: 212.186.127.180 is authorized to use 'a.lauterer@proxmox.com' in 'mfrom' identity (mechanism 'mx' matched)) receiver=firstgate.proxmox.com; identity=mailfrom; envelope-from="a.lauterer@proxmox.com"; helo=proxmox-new.maurer-it.com; client-ip=212.186.127.180 Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id B2B8B26386 for ; Tue, 7 Jul 2020 11:56:19 +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 2402144498 for ; Tue, 7 Jul 2020 11:49:03 +0200 (CEST) From: Aaron Lauterer To: pve-devel@pve.proxmox.com Date: Tue, 7 Jul 2020 11:48:59 +0200 Message-Id: <20200707094902.24712-3-a.lauterer@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200707094902.24712-1-a.lauterer@proxmox.com> References: <20200707094902.24712-1-a.lauterer@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record X-Mailman-Approved-At: Tue, 07 Jul 2020 12:27:43 +0200 Subject: [pve-devel] [PATCH v4 manager 2/5] gui: dc/backup: move renderers to Utils.js X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: PVE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Jul 2020 09:56:23 -0000 Moving the following renderers to Utils.js to be able to use them in more than one place: * render_backup_days_of_week * render_backup_selection Signed-off-by: Aaron Lauterer --- v1 -> v2 -> v3 -> v4: rebased www/manager6/Utils.js | 60 +++++++++++++++++++++++++++++++++++++++ www/manager6/dc/Backup.js | 59 ++------------------------------------ 2 files changed, 62 insertions(+), 57 deletions(-) diff --git a/www/manager6/Utils.js b/www/manager6/Utils.js index 56a0407d..158b370b 100644 --- a/www/manager6/Utils.js +++ b/www/manager6/Utils.js @@ -219,6 +219,66 @@ Ext.define('PVE.Utils', { utilities: { }, + render_backup_days_of_week: function(val) { + var dows = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat']; + var selected = []; + var cur = -1; + val.split(',').forEach(function(day){ + cur++; + var dow = (dows.indexOf(day)+6)%7; + if (cur === dow) { + if (selected.length === 0 || selected[selected.length-1] === 0) { + selected.push(1); + } else { + selected[selected.length-1]++; + } + } else { + while (cur < dow) { + cur++; + selected.push(0); + } + selected.push(1); + } + }); + + cur = -1; + var days = []; + selected.forEach(function(item) { + cur++; + if (item > 2) { + days.push(Ext.Date.dayNames[(cur+1)] + '-' + Ext.Date.dayNames[(cur+item)%7]); + cur += item-1; + } else if (item == 2) { + days.push(Ext.Date.dayNames[cur+1]); + days.push(Ext.Date.dayNames[(cur+2)%7]); + cur++; + } else if (item == 1) { + days.push(Ext.Date.dayNames[(cur+1)%7]); + } + }); + return days.join(', '); + }, + + render_backup_selection: function(value, metaData, record) { + let allExceptText = gettext('All except {0}'); + let allText = '-- ' + gettext('All') + ' --'; + if (record.data.all) { + if (record.data.exclude) { + return Ext.String.format(allExceptText, record.data.exclude); + } + return allText; + } + if (record.data.vmid) { + return record.data.vmid; + } + + if (record.data.pool) { + return "Pool '"+ record.data.pool + "'"; + } + + return "-"; + }, + get_kvm_osinfo: function(value) { var info = { base: 'Other' }; // default if (value) { diff --git a/www/manager6/dc/Backup.js b/www/manager6/dc/Backup.js index 13cd0528..1ef092c5 100644 --- a/www/manager6/dc/Backup.js +++ b/www/manager6/dc/Backup.js @@ -383,7 +383,6 @@ Ext.define('PVE.dc.BackupView', { onlineHelp: 'chapter_vzdump', allText: '-- ' + gettext('All') + ' --', - allExceptText: gettext('All except {0}'), initComponent : function() { var me = this; @@ -568,45 +567,7 @@ Ext.define('PVE.dc.BackupView', { width: 200, sortable: false, dataIndex: 'dow', - renderer: function(val) { - var dows = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat']; - var selected = []; - var cur = -1; - val.split(',').forEach(function(day){ - cur++; - var dow = (dows.indexOf(day)+6)%7; - if (cur === dow) { - if (selected.length === 0 || selected[selected.length-1] === 0) { - selected.push(1); - } else { - selected[selected.length-1]++; - } - } else { - while (cur < dow) { - cur++; - selected.push(0); - } - selected.push(1); - } - }); - - cur = -1; - var days = []; - selected.forEach(function(item) { - cur++; - if (item > 2) { - days.push(Ext.Date.dayNames[(cur+1)] + '-' + Ext.Date.dayNames[(cur+item)%7]); - cur += item-1; - } else if (item == 2) { - days.push(Ext.Date.dayNames[cur+1]); - days.push(Ext.Date.dayNames[(cur+2)%7]); - cur++; - } else if (item == 1) { - days.push(Ext.Date.dayNames[(cur+1)%7]); - } - }); - return days.join(', '); - } + renderer: PVE.Utils.render_backup_days_of_week }, { header: gettext('Start Time'), @@ -625,23 +586,7 @@ Ext.define('PVE.dc.BackupView', { flex: 1, sortable: false, dataIndex: 'vmid', - renderer: function(value, metaData, record) { - if (record.data.all) { - if (record.data.exclude) { - return Ext.String.format(me.allExceptText, record.data.exclude); - } - return me.allText; - } - if (record.data.vmid) { - return record.data.vmid; - } - - if (record.data.pool) { - return "Pool '"+ record.data.pool + "'"; - } - - return "-"; - } + renderer: PVE.Utils.render_backup_selection } ], listeners: { -- 2.20.1