ui: utils: add function for parsing maintenance mode
...since the same code is used is more than one place Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
This commit is contained in:
parent
fbd6f54f39
commit
1b7479c968
17
www/Utils.js
17
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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 ?? '',
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue