]> git.proxmox.com Git - pmg-gui.git/blobdiff - js/SpamInfoGrid.js
dashboard: increase height of node-info and top-receiver panel to 300
[pmg-gui.git] / js / SpamInfoGrid.js
index a1b3324fde50a8f2f6a24346b22eb991a38dfc3c..00d6f97341e08969daec68d063a007fedd7ce98c 100644 (file)
@@ -1,26 +1,25 @@
-Ext.define('PMG.grid.SpamInfoGrid',{
+Ext.define('PMG.grid.SpamInfoGrid', {
     extend: 'Ext.grid.GridPanel',
     xtype: 'pmgSpamInfoGrid',
 
-    hideHeaders: true,
-
     store: {
        autoDestroy: true,
-       fields: [ 'desc', 'name', { type: 'number', name: 'score' } ],
+       fields: ['desc', 'name', { type: 'number', name: 'score' }],
        proxy: {
            type: 'proxmox',
-           root: 'data.spaminfo'
-       }
+           root: 'data.spaminfo',
+       },
+       sorters: 'score',
     },
 
     setID: function(rec) {
-       var me = this;
-       if (!rec || !rec.data || !rec.data.id) {
+       let me = this;
+       let id = rec?.data?.id;
+       if (!id) {
            me.getStore().removeAll();
            return;
        }
-       var url = '/api2/json/quarantine/content?id=' + rec.data.id;
-       me.store.proxy.setUrl(url);
+       me.store.proxy.setUrl(`/api2/json/quarantine/content?id=${id}`);
        me.store.load();
     },
 
@@ -28,32 +27,51 @@ Ext.define('PMG.grid.SpamInfoGrid',{
     hidden: true,
 
     features: [{
-       ftype: 'summary'
+       ftype: 'summary',
     }],
 
     columns: [
        {
            text: gettext('Test Name'),
            dataIndex: 'name',
-           flex: 2,
+           flex: 1,
            summaryType: 'count',
-           summaryRenderer: function(value, summaryData, dataIndex, metaData) {
-               return gettext('Spamscore');
-           }
+           summaryRenderer: _v => gettext('Spamscore'),
+           tdCls: 'txt-monospace',
        },
        {
            text: gettext('Score'),
            dataIndex: 'score',
            align: 'right',
+           tdCls: 'txt-monospace',
+           renderer: function(score, meta) {
+               if (score === 0) {
+                   return score;
+               }
+
+               let absScore = Math.abs(score), fontWeight = '400';
+               let background = score < 0 ? "--pmg-spam-mid-neg" : "--pmg-spam-mid-pos";
+
+               if (absScore >= 3) {
+                   fontWeight = '900';
+                   background = score < 0 ? "--pmg-spam-high-neg" : "--pmg-spam-high-pos";
+               } else if (absScore >= 1.5) {
+                   fontWeight = '600';
+               } else if (absScore <= 0.1) {
+                   fontWeight = '200';
+                   background = score < 0 ? "--pmg-spam-low-neg" : "--pmg-spam-low-pos";
+               }
+
+               meta.tdStyle = `font-weight: ${fontWeight};background-color: var(${background});`;
+               return score;
+           },
            summaryType: 'sum',
-           summaryRenderer: function(value, summaryData, dataIndex, metaData) {
-               return Ext.util.Format.round(value, 5);
-           }
+           summaryRenderer: value => Ext.util.Format.round(value, 5),
        },
        {
            text: gettext('Description'),
            dataIndex: 'desc',
-           flex: 3
-       }
+           flex: 2,
+       },
     ],
 });