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 5C3EF7A961 for ; Tue, 5 Jul 2022 15:16:38 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 4E4832FAC0 for ; Tue, 5 Jul 2022 15:16:38 +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 ; Tue, 5 Jul 2022 15:16:33 +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 EC06C43DBB for ; Tue, 5 Jul 2022 15:08:49 +0200 (CEST) From: Hannes Laimer To: pbs-devel@lists.proxmox.com Date: Tue, 5 Jul 2022 13:08:21 +0000 Message-Id: <20220705130834.14285-16-h.laimer@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220705130834.14285-1-h.laimer@proxmox.com> References: <20220705130834.14285-1-h.laimer@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.041 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 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 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [activetasks.read] Subject: [pbs-devel] [PATCH proxmox-backup 13/26] ui: utils: remove parseMaintenanceMode function X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Jul 2022 13:16:38 -0000 ... and use parsePropertyString instead + remove quotes from quoted values in parsePropertyString. Signed-off-by: Hannes Laimer --- www/NavigationTree.js | 8 ++++---- www/Utils.js | 24 +++++++----------------- www/datastore/Summary.js | 6 +++--- www/window/MaintenanceOptions.js | 6 +++--- 4 files changed, 17 insertions(+), 27 deletions(-) diff --git a/www/NavigationTree.js b/www/NavigationTree.js index 5f44aace..aae35012 100644 --- a/www/NavigationTree.js +++ b/www/NavigationTree.js @@ -255,10 +255,10 @@ Ext.define('PBS.view.main.NavigationTree', { } let [qtip, iconCls] = ['', 'fa fa-database']; - const maintenance = records[i].data.maintenance; - if (maintenance) { - const [type, message] = PBS.Utils.parseMaintenanceMode(maintenance); - qtip = `${type}${message ? ': ' + message : ''}`; + const maintenanceString = records[i].data.maintenance; + if (maintenanceString) { + const maintenance = PBS.Utils.parsePropertyString(maintenanceString, 'type'); + qtip = `${maintenance.type}${maintenance.message ? ': ' + maintenance.message : ''}`; iconCls = 'fa fa-database pmx-tree-icon-custom maintenance'; } diff --git a/www/Utils.js b/www/Utils.js index ad451c9f..a1f17bdc 100644 --- a/www/Utils.js +++ b/www/Utils.js @@ -73,13 +73,13 @@ Ext.define('PBS.Utils', { Ext.Array.each(value.split(','), function(p) { var kv = p.split('=', 2); if (Ext.isDefined(kv[1])) { - res[kv[0]] = kv[1]; + res[kv[0]] = kv[1].replace(/^"(.*)"$/, '$1'); } else if (Ext.isDefined(defaultKey)) { if (Ext.isDefined(res[defaultKey])) { error = 'defaultKey may be only defined once in propertyString'; return false; // break } - res[defaultKey] = kv[0]; + res[defaultKey] = kv[0].replace(/^"(.*)"$/, '$1'); } else { error = 'invalid propertyString, not a key=value pair and no defaultKey defined'; return false; // break @@ -656,27 +656,17 @@ Ext.define('PBS.Utils', { return `${icon} ${value}`; }, - // FIXME: this "parser" is brittle and relies on the order the arguments will appear in - parseMaintenanceMode: function(mode) { - let [type, message] = mode.split(/,(.+)/); - type = type.split("=").pop(); - message = message ? message.split("=")[1] - .replace(/^"(.*)"$/, '$1') - .replaceAll('\\"', '"') : null; - return [type, message]; - }, - renderMaintenance: function(mode, activeTasks) { if (!mode) { return gettext('None'); } - let [type, message] = PBS.Utils.parseMaintenanceMode(mode); + const maintenance = PBS.Utils.parsePropertyString(mode, 'type'); let extra = ''; if (activeTasks !== undefined) { - const conflictingTasks = activeTasks.write + (type === 'offline' ? activeTasks.read : 0); + const conflictingTasks = activeTasks.write + (maintenance.type === 'offline' ? activeTasks.read : 0); if (conflictingTasks > 0) { extra += '| '; @@ -686,12 +676,12 @@ Ext.define('PBS.Utils', { } } - if (message) { - extra += ` ("${message}")`; + if (maintenance.message) { + extra += ` ("${maintenance.message}")`; } let modeText = Proxmox.Utils.unknownText; - switch (type) { + switch (maintenance.type) { case 'read-only': modeText = gettext("Read-only"); break; case 'offline': modeText = gettext("Offline"); diff --git a/www/datastore/Summary.js b/www/datastore/Summary.js index 94be9559..6e73e9ad 100644 --- a/www/datastore/Summary.js +++ b/www/datastore/Summary.js @@ -49,10 +49,10 @@ Ext.define('PBS.DataStoreInfo', { success: function(response) { const config = response.result.data; if (config['maintenance-mode']) { - const [_type, msg] = PBS.Utils.parseMaintenanceMode(config['maintenance-mode']); + const maintenance = PBS.Utils.parsePropertyString(config['maintenance-mode'], 'type'); me.view.el.mask( - `${gettext('Datastore is in maintenance mode')}${msg ? ': ' + msg : ''}`, - 'fa pbs-maintenance-mask', + `${gettext('Datastore is in maintenance mode')}${maintenance.message ? ': ' + maintenance.message : ''}`, + 'fa pbs-maintenance-mask', ); } else { me.view.el.mask(gettext('Datastore is not available')); diff --git a/www/window/MaintenanceOptions.js b/www/window/MaintenanceOptions.js index 1ee92542..3cd3e2ce 100644 --- a/www/window/MaintenanceOptions.js +++ b/www/window/MaintenanceOptions.js @@ -73,10 +73,10 @@ Ext.define('PBS.window.MaintenanceOptions', { 'maintenance-msg': '', }; if (values['maintenance-mode']) { - const [type, message] = PBS.Utils.parseMaintenanceMode(values['maintenance-mode']); + const maintenance = PBS.Utils.parsePropertyString(values['maintenance-mode'], 'type'); options = { - 'maintenance-type': type, - 'maintenance-msg': message ?? '', + 'maintenance-type': maintenance.type, + 'maintenance-msg': maintenance.message ?? '', }; } -- 2.30.2