]> git.proxmox.com Git - proxmox-widget-toolkit.git/commitdiff
notification: add ui for managing notification filters
authorLukas Wagner <l.wagner@proxmox.com>
Thu, 3 Aug 2023 12:17:18 +0000 (14:17 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 16 Aug 2023 08:37:44 +0000 (10:37 +0200)
This commit adds a new dialog window, containing all fields necessary
to configure notification filters.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
Reviewed-by: Dominik Csapak <d.csapak@proxmox.com>
src/Makefile
src/data/model/NotificationConfig.js
src/panel/NotificationConfigView.js
src/window/NotificationFilterEdit.js [new file with mode: 0644]

index f661bb60856f52f38a39f9153f86805bce35299c..21fbe764eedbd7a7975cd31939a48557516f2494 100644 (file)
@@ -89,7 +89,8 @@ JSSRC=                                        \
        window/ACMEAccount.js           \
        window/ACMEPluginEdit.js        \
        window/ACMEDomains.js           \
-       window/EndpointEditBase.js              \
+       window/EndpointEditBase.js      \
+       window/NotificationFilterEdit.js \
        window/FileBrowser.js           \
        window/AuthEditBase.js          \
        window/AuthEditOpenId.js        \
index c2ce843d8d66325035075ca73cd90f59928f20b5..bb4ef85c120d8c6d4c794a435b3c0a1fe84d6ca0 100644 (file)
@@ -6,3 +6,12 @@ Ext.define('proxmox-notification-endpoints', {
     },
     idProperty: 'name',
 });
+
+Ext.define('proxmox-notification-filters', {
+    extend: 'Ext.data.Model',
+    fields: ['name', 'comment'],
+    proxy: {
+        type: 'proxmox',
+    },
+    idProperty: 'name',
+});
index 80e38f1098e9becd64551d0aa7fb79e8e2137204..6586524f478faa4f51616f384c0abbd10ef1d9b6 100644 (file)
@@ -15,6 +15,17 @@ Ext.define('Proxmox.panel.NotificationConfigView', {
                baseUrl: '{baseUrl}',
            },
        },
+       {
+           region: 'south',
+           height: '50%',
+           border: false,
+           collapsible: true,
+           animCollapse: false,
+           xtype: 'pmxNotificationFilterView',
+           cbind: {
+               baseUrl: '{baseUrl}',
+           },
+       },
     ],
 });
 
@@ -198,3 +209,111 @@ Ext.define('Proxmox.panel.NotificationEndpointView', {
        me.store.rstore.proxy.setUrl(`/api2/json/${me.baseUrl}/targets`);
     },
 });
+
+Ext.define('Proxmox.panel.NotificationFilterView', {
+    extend: 'Ext.grid.Panel',
+    alias: 'widget.pmxNotificationFilterView',
+
+    title: gettext('Notification Filters'),
+
+    controller: {
+       xclass: 'Ext.app.ViewController',
+
+       openEditWindow: function(filter) {
+           let me = this;
+
+           Ext.create('Proxmox.window.NotificationFilterEdit', {
+               baseUrl: me.getView().baseUrl,
+               name: filter,
+               autoShow: true,
+               listeners: {
+                   destroy: () => me.reload(),
+               },
+           });
+       },
+
+       openEditForSelectedItem: function() {
+           let me = this;
+           let view = me.getView();
+
+           let selection = view.getSelection();
+           if (selection.length < 1) {
+               return;
+           }
+
+           me.openEditWindow(selection[0].data.name);
+       },
+
+       reload: function() {
+           this.getView().getStore().rstore.load();
+       },
+    },
+
+    listeners: {
+       itemdblclick: 'openEditForSelectedItem',
+       activate: 'reload',
+    },
+
+    emptyText: gettext('No notification filters configured'),
+
+    columns: [
+       {
+           dataIndex: 'name',
+           text: gettext('Filter Name'),
+           renderer: Ext.String.htmlEncode,
+           flex: 1,
+       },
+       {
+           dataIndex: 'comment',
+           text: gettext('Comment'),
+           renderer: Ext.String.htmlEncode,
+           flex: 2,
+       },
+    ],
+
+    store: {
+       type: 'diff',
+       autoDestroy: true,
+       autoDestroyRstore: true,
+       rstore: {
+           type: 'update',
+           storeid: 'proxmox-notification-filters',
+           model: 'proxmox-notification-filters',
+           autoStart: true,
+       },
+       sorters: 'name',
+    },
+
+    initComponent: function() {
+       let me = this;
+
+       if (!me.baseUrl) {
+           throw "baseUrl is not set!";
+       }
+
+       Ext.apply(me, {
+           tbar: [
+               {
+                   xtype: 'proxmoxButton',
+                   text: gettext('Add'),
+                   handler: () => me.getController().openEditWindow(),
+                   selModel: false,
+               },
+               {
+                   xtype: 'proxmoxButton',
+                   text: gettext('Modify'),
+                   handler: 'openEditForSelectedItem',
+                   disabled: true,
+               },
+               {
+                   xtype: 'proxmoxStdRemoveButton',
+                   callback: 'reload',
+                   baseurl: `${me.baseUrl}/filters`,
+               },
+           ],
+       });
+
+       me.callParent();
+       me.store.rstore.proxy.setUrl(`/api2/json/${me.baseUrl}/filters`);
+    },
+});
diff --git a/src/window/NotificationFilterEdit.js b/src/window/NotificationFilterEdit.js
new file mode 100644 (file)
index 0000000..703a9e2
--- /dev/null
@@ -0,0 +1,109 @@
+Ext.define('Proxmox.panel.NotificationFilterEditPanel', {
+    extend: 'Proxmox.panel.InputPanel',
+    xtype: 'pmxNotificationFilterEditPanel',
+    mixins: ['Proxmox.Mixin.CBind'],
+
+    items: [
+       {
+           xtype: 'pmxDisplayEditField',
+           name: 'name',
+           cbind: {
+               value: '{name}',
+               editable: '{isCreate}',
+           },
+           fieldLabel: gettext('Filter Name'),
+           allowBlank: false,
+       },
+       {
+           xtype: 'proxmoxKVComboBox',
+           name: 'min-severity',
+           fieldLabel: gettext('Minimum Severity'),
+           value: null,
+           cbind: {
+               deleteEmpty: '{!isCreate}',
+           },
+           comboItems: [
+               ['info', 'info'],
+               ['notice', 'notice'],
+               ['warning', 'warning'],
+               ['error', 'error'],
+           ],
+           triggers: {
+               clear: {
+                   cls: 'pmx-clear-trigger',
+                   weight: -1,
+                   hidden: false,
+                   handler: function() {
+                       this.setValue('');
+                   },
+               },
+           },
+       },
+       {
+           xtype: 'proxmoxcheckbox',
+           fieldLabel: gettext('Invert match'),
+           name: 'invert-match',
+           uncheckedValue: 0,
+           defaultValue: 0,
+           cbind: {
+               deleteDefaultValue: '{!isCreate}',
+           },
+       },
+       {
+           xtype: 'proxmoxtextfield',
+           name: 'comment',
+           fieldLabel: gettext('Comment'),
+           cbind: {
+               deleteEmpty: '{!isCreate}',
+           },
+       },
+    ],
+});
+
+Ext.define('Proxmox.window.NotificationFilterEdit', {
+    extend: 'Proxmox.window.Edit',
+
+    isAdd: true,
+
+    fieldDefaults: {
+       labelWidth: 120,
+    },
+
+    width: 500,
+
+    initComponent: function() {
+       let me = this;
+
+       me.isCreate = !me.name;
+
+       if (!me.baseUrl) {
+           throw "baseUrl not set";
+       }
+
+       me.url = `/api2/extjs${me.baseUrl}/filters`;
+
+       if (me.isCreate) {
+           me.method = 'POST';
+       } else {
+           me.url += `/${me.name}`;
+           me.method = 'PUT';
+       }
+
+       me.subject = gettext('Notification Filter');
+
+       Ext.apply(me, {
+           items: [{
+               name: me.name,
+               xtype: 'pmxNotificationFilterEditPanel',
+               isCreate: me.isCreate,
+               baseUrl: me.baseUrl,
+           }],
+       });
+
+       me.callParent();
+
+       if (!me.isCreate) {
+           me.load();
+       }
+    },
+});