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 56A0A929A for ; Tue, 26 Apr 2022 08:24:24 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 52F7DE8CE for ; Tue, 26 Apr 2022 08:24:24 +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 id 355CBE588 for ; Tue, 26 Apr 2022 08:24:18 +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 0F3EB42B2B for ; Tue, 26 Apr 2022 08:24:18 +0200 (CEST) From: Hannes Laimer To: pbs-devel@lists.proxmox.com Date: Tue, 26 Apr 2022 06:23:34 +0000 Message-Id: <20220426062335.6215-6-h.laimer@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220426062335.6215-1-h.laimer@proxmox.com> References: <20220426062335.6215-1-h.laimer@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.044 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 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 v2 5/6] ui: utils: add function for parsing maintenance mode 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, 26 Apr 2022 06:24:24 -0000 ...since the same code is used is more than one place Signed-off-by: Hannes Laimer --- www/Utils.js | 17 +++++++++++++---- www/datastore/Summary.js | 7 ++----- www/window/MaintenanceOptions.js | 8 ++------ 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/www/Utils.js b/www/Utils.js index 32f56278..9a53cc72 100644 --- a/www/Utils.js +++ b/www/Utils.js @@ -640,13 +640,22 @@ 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'); } - // FIXME: this "parser" is brittle and relies on the order the arguments will appear in - let [type, message] = mode.split(","); - type = type.split("=").pop(); + + let [type, message] = PBS.Utils.parseMaintenanceMode(mode); const conflictingTasks = activeTasks.write + (type === 'offline' ? activeTasks.read : 0); @@ -659,7 +668,7 @@ Ext.define('PBS.Utils', { } if (message) { - extra += ` (${message.split("=").pop()})`; + extra += ` ("${message}")`; } let modeText = Proxmox.Utils.unknownText; diff --git a/www/datastore/Summary.js b/www/datastore/Summary.js index d7b53a3a..328aa561 100644 --- a/www/datastore/Summary.js +++ b/www/datastore/Summary.js @@ -49,12 +49,9 @@ Ext.define('PBS.DataStoreInfo', { success: function(response) { const config = response.result.data; if (config['maintenance-mode']) { - const [_type, msg] = config['maintenance-mode'].split(/,(.+)/); - const message = msg ? ': ' + msg.split("=")[1] - .replace(/^"(.*)"$/, '$1') - .replaceAll('\\"', '"') : ''; + const [_type, msg] = PBS.Utils.parseMaintenanceMode(config['maintenance-mode']); me.view.el.mask( - `${gettext('Datastore is in maintenance mode')}${message}`, + `${gettext('Datastore is in maintenance mode')}${msg ? ': ' + msg : ''}`, 'fa pbs-maintenance-mask', ); } else { diff --git a/www/window/MaintenanceOptions.js b/www/window/MaintenanceOptions.js index 47196b42..713da569 100644 --- a/www/window/MaintenanceOptions.js +++ b/www/window/MaintenanceOptions.js @@ -62,14 +62,10 @@ Ext.define('PBS.window.MaintenanceOptions', { 'maintenance-msg': '', }; if (values['maintenance-mode']) { - let [type, message] = values['maintenance-mode'].split(/,(.+)/); - type = type.split("=").pop(); - message = message ? message.split("=")[1] - .replace(/^"(.*)"$/, '$1') - .replaceAll('\\"', '"') : ''; + const [type, message] = PBS.Utils.parseMaintenanceMode(values['maintenance-mode']); options = { 'maintenance-type': type, - 'maintenance-msg': message, + 'maintenance-msg': message ?? '', }; } -- 2.30.2