mirror of
https://git.proxmox.com/git/proxmox-widget-toolkit
synced 2025-06-27 13:45:28 +00:00
notification: matcher: move match-field formulas to local viewModel
This should make the code more cohesive and easier to follow. No functional changes. Signed-off-by: Lukas Wagner <l.wagner@proxmox.com> Tested-by: Maximiliano Sandoval <m.sandoval@proxmox.com> Reviewed-by: Max Carrara <m.carrara@proxmox.com>
This commit is contained in:
parent
043ce82954
commit
e91269d513
@ -380,15 +380,6 @@ Ext.define('Proxmox.panel.NotificationRulesEditPanel', {
|
|||||||
}
|
}
|
||||||
return !record.isRoot();
|
return !record.isRoot();
|
||||||
},
|
},
|
||||||
typeIsMatchField: {
|
|
||||||
bind: {
|
|
||||||
bindTo: '{selectedRecord}',
|
|
||||||
deep: true,
|
|
||||||
},
|
|
||||||
get: function(record) {
|
|
||||||
return record?.get('type') === 'match-field';
|
|
||||||
},
|
|
||||||
},
|
|
||||||
typeIsMatchSeverity: {
|
typeIsMatchSeverity: {
|
||||||
bind: {
|
bind: {
|
||||||
bindTo: '{selectedRecord}',
|
bindTo: '{selectedRecord}',
|
||||||
@ -407,89 +398,13 @@ Ext.define('Proxmox.panel.NotificationRulesEditPanel', {
|
|||||||
return record?.get('type') === 'match-calendar';
|
return record?.get('type') === 'match-calendar';
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
matchFieldType: {
|
|
||||||
bind: {
|
|
||||||
bindTo: '{selectedRecord}',
|
|
||||||
deep: true,
|
|
||||||
},
|
|
||||||
set: function(value) {
|
|
||||||
let me = this;
|
|
||||||
let record = me.get('selectedRecord');
|
|
||||||
let currentData = record.get('data');
|
|
||||||
|
|
||||||
let newValue = [];
|
|
||||||
|
|
||||||
// Build equivalent regular expression if switching
|
|
||||||
// to 'regex' mode
|
|
||||||
if (value === 'regex') {
|
|
||||||
let regexVal = "^(";
|
|
||||||
regexVal += currentData.value.join('|') + ")$";
|
|
||||||
newValue.push(regexVal);
|
|
||||||
}
|
|
||||||
|
|
||||||
record.set({
|
|
||||||
data: {
|
|
||||||
...currentData,
|
|
||||||
type: value,
|
|
||||||
value: newValue,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
},
|
|
||||||
get: function(record) {
|
|
||||||
return record?.get('data')?.type;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
matchFieldField: {
|
|
||||||
bind: {
|
|
||||||
bindTo: '{selectedRecord}',
|
|
||||||
deep: true,
|
|
||||||
},
|
|
||||||
set: function(value) {
|
|
||||||
let me = this;
|
|
||||||
let record = me.get('selectedRecord');
|
|
||||||
let currentData = record.get('data');
|
|
||||||
|
|
||||||
record.set({
|
|
||||||
data: {
|
|
||||||
...currentData,
|
|
||||||
field: value,
|
|
||||||
// Reset value if field changes
|
|
||||||
value: [],
|
|
||||||
},
|
|
||||||
});
|
|
||||||
},
|
|
||||||
get: function(record) {
|
|
||||||
return record?.get('data')?.field;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
matchFieldValue: {
|
|
||||||
bind: {
|
|
||||||
bindTo: '{selectedRecord}',
|
|
||||||
deep: true,
|
|
||||||
},
|
|
||||||
set: function(value) {
|
|
||||||
let me = this;
|
|
||||||
let record = me.get('selectedRecord');
|
|
||||||
let currentData = record.get('data');
|
|
||||||
record.set({
|
|
||||||
data: {
|
|
||||||
...currentData,
|
|
||||||
value: value,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
},
|
|
||||||
get: function(record) {
|
|
||||||
return record?.get('data')?.value;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
matchSeverityValue: {
|
matchSeverityValue: {
|
||||||
bind: {
|
bind: {
|
||||||
bindTo: '{selectedRecord}',
|
bindTo: '{selectedRecord}',
|
||||||
deep: true,
|
deep: true,
|
||||||
},
|
},
|
||||||
set: function(value) {
|
set: function(value) {
|
||||||
let me = this;
|
let record = this.get('selectedRecord');
|
||||||
let record = me.get('selectedRecord');
|
|
||||||
let currentData = record.get('data');
|
let currentData = record.get('data');
|
||||||
record.set({
|
record.set({
|
||||||
data: {
|
data: {
|
||||||
@ -1137,7 +1052,98 @@ Ext.define('Proxmox.panel.MatchFieldSettings', {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
viewModel: {
|
||||||
|
// parent is set in `initComponents`
|
||||||
|
formulas: {
|
||||||
|
typeIsMatchField: {
|
||||||
|
bind: {
|
||||||
|
bindTo: '{selectedRecord}',
|
||||||
|
deep: true,
|
||||||
|
},
|
||||||
|
get: function(record) {
|
||||||
|
return record?.get('type') === 'match-field';
|
||||||
|
},
|
||||||
|
},
|
||||||
|
isRegex: function(get) {
|
||||||
|
return get('matchFieldType') === 'regex';
|
||||||
|
},
|
||||||
|
matchFieldType: {
|
||||||
|
bind: {
|
||||||
|
bindTo: '{selectedRecord}',
|
||||||
|
deep: true,
|
||||||
|
},
|
||||||
|
set: function(value) {
|
||||||
|
let record = this.get('selectedRecord');
|
||||||
|
let currentData = record.get('data');
|
||||||
|
|
||||||
|
let newValue = [];
|
||||||
|
|
||||||
|
// Build equivalent regular expression if switching
|
||||||
|
// to 'regex' mode
|
||||||
|
if (value === 'regex') {
|
||||||
|
let regexVal = "^";
|
||||||
|
if (currentData.value && currentData.value.length) {
|
||||||
|
regexVal += `(${currentData.value.join('|')})`;
|
||||||
|
}
|
||||||
|
regexVal += "$";
|
||||||
|
newValue.push(regexVal);
|
||||||
|
}
|
||||||
|
|
||||||
|
record.set({
|
||||||
|
data: {
|
||||||
|
...currentData,
|
||||||
|
type: value,
|
||||||
|
value: newValue,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
get: function(record) {
|
||||||
|
return record?.get('data')?.type;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
matchFieldField: {
|
||||||
|
bind: {
|
||||||
|
bindTo: '{selectedRecord}',
|
||||||
|
deep: true,
|
||||||
|
},
|
||||||
|
set: function(value) {
|
||||||
|
let record = this.get('selectedRecord');
|
||||||
|
let currentData = record.get('data');
|
||||||
|
|
||||||
|
record.set({
|
||||||
|
data: {
|
||||||
|
...currentData,
|
||||||
|
field: value,
|
||||||
|
// Reset value if field changes
|
||||||
|
value: [],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
get: function(record) {
|
||||||
|
return record?.get('data')?.field;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
matchFieldValue: {
|
||||||
|
bind: {
|
||||||
|
bindTo: '{selectedRecord}',
|
||||||
|
deep: true,
|
||||||
|
},
|
||||||
|
set: function(value) {
|
||||||
|
let record = this.get('selectedRecord');
|
||||||
|
let currentData = record.get('data');
|
||||||
|
record.set({
|
||||||
|
data: {
|
||||||
|
...currentData,
|
||||||
|
value: value,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
get: function(record) {
|
||||||
|
return record?.get('data')?.value;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
initComponent: function() {
|
initComponent: function() {
|
||||||
let me = this;
|
let me = this;
|
||||||
@ -1195,15 +1201,10 @@ Ext.define('Proxmox.panel.MatchFieldSettings', {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
Ext.apply(me, {
|
Ext.apply(me.viewModel, {
|
||||||
viewModel: Ext.create('Ext.app.ViewModel', {
|
|
||||||
parent: me.up('pmxNotificationMatchRulesEditPanel').getViewModel(),
|
parent: me.up('pmxNotificationMatchRulesEditPanel').getViewModel(),
|
||||||
formulas: {
|
});
|
||||||
isRegex: function(get) {
|
Ext.apply(me, {
|
||||||
return get('matchFieldType') === 'regex';
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
fieldLabel: gettext('Match Type'),
|
fieldLabel: gettext('Match Type'),
|
||||||
|
Loading…
Reference in New Issue
Block a user