notification: matcher: move match-calendar fields to panel

Also introduce a local viewModel that is linked to a parent viewModel,
allowing us to move the formulas to the panel.
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:
Lukas Wagner 2024-07-08 11:38:08 +02:00 committed by Thomas Lamprecht
parent e91269d513
commit fa315d842b

View File

@ -389,15 +389,6 @@ Ext.define('Proxmox.panel.NotificationRulesEditPanel', {
return record?.get('type') === 'match-severity';
},
},
typeIsMatchCalendar: {
bind: {
bindTo: '{selectedRecord}',
deep: true,
},
get: function(record) {
return record?.get('type') === 'match-calendar';
},
},
matchSeverityValue: {
bind: {
bindTo: '{selectedRecord}',
@ -417,26 +408,6 @@ Ext.define('Proxmox.panel.NotificationRulesEditPanel', {
return record?.get('data')?.value;
},
},
matchCalendarValue: {
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;
},
},
rootMode: {
bind: {
bindTo: '{selectedRecord}',
@ -995,6 +966,58 @@ Ext.define('Proxmox.panel.NotificationMatchRuleSettings', {
['unknown', gettext('Unknown')],
],
},
{
xtype: 'pmxNotificationMatchCalendarSettings',
},
],
});
Ext.define('Proxmox.panel.MatchCalendarSettings', {
extend: 'Ext.panel.Panel',
xtype: 'pmxNotificationMatchCalendarSettings',
border: false,
layout: 'anchor',
// Hide initially to avoid glitches when opening the window
hidden: true,
bind: {
hidden: '{!typeIsMatchCalendar}',
},
viewModel: {
// parent is set in `initComponents`
formulas: {
typeIsMatchCalendar: {
bind: {
bindTo: '{selectedRecord}',
deep: true,
},
get: function(record) {
return record?.get('type') === 'match-calendar';
},
},
matchCalendarValue: {
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;
},
},
},
},
items: [
{
xtype: 'proxmoxKVComboBox',
fieldLabel: gettext('Timespan to match'),
@ -1003,11 +1026,8 @@ Ext.define('Proxmox.panel.NotificationMatchRuleSettings', {
editable: true,
displayField: 'key',
field: 'value',
// Hide initially to avoid glitches when opening the window
hidden: true,
bind: {
value: '{matchCalendarValue}',
hidden: '{!typeIsMatchCalendar}',
disabled: '{!typeIsMatchCalender}',
},
@ -1017,6 +1037,14 @@ Ext.define('Proxmox.panel.NotificationMatchRuleSettings', {
],
},
],
initComponent: function() {
let me = this;
Ext.apply(me.viewModel, {
parent: me.up('pmxNotificationMatchRulesEditPanel').getViewModel(),
});
me.callParent();
},
});
Ext.define('Proxmox.panel.MatchFieldSettings', {