From: Hannes Laimer <h.laimer@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup v2 5/6] ui: utils: add function for parsing maintenance mode
Date: Tue, 26 Apr 2022 06:23:34 +0000 [thread overview]
Message-ID: <20220426062335.6215-6-h.laimer@proxmox.com> (raw)
In-Reply-To: <20220426062335.6215-1-h.laimer@proxmox.com>
...since the same code is used is more than one place
Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
---
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
next prev parent reply other threads:[~2022-04-26 6:24 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-26 6:23 [pbs-devel] [PATCH proxmox-backup v2 0/6] improve UI for " Hannes Laimer
2022-04-26 6:23 ` [pbs-devel] [PATCH proxmox-backup v2 1/6] ui: add summary mask when in " Hannes Laimer
2022-04-26 6:23 ` [pbs-devel] [PATCH proxmox-backup v2 2/6] api2: DataStoreListItem add maintenance info Hannes Laimer
2022-04-26 6:23 ` [pbs-devel] [PATCH proxmox-backup v2 3/6] ui: update icon in datastore list when in maintenance mode Hannes Laimer
2022-04-26 6:23 ` [pbs-devel] [PATCH proxmox-backup v2 4/6][optional] ui: update datastore list more often Hannes Laimer
2022-04-26 6:23 ` Hannes Laimer [this message]
2022-04-26 6:23 ` [pbs-devel] [PATCH proxmox-backup v2 6/6] ui: add tooltip to datastore in maintenance mode Hannes Laimer
2022-04-27 17:40 ` [pbs-devel] applied-series: [PATCH proxmox-backup v2 0/6] improve UI for " Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220426062335.6215-6-h.laimer@proxmox.com \
--to=h.laimer@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox