]> git.proxmox.com Git - pmg-gui.git/blob - js/SpamInfoGrid.js
quarantines: fix the default behavior of the theme toggle button
[pmg-gui.git] / js / SpamInfoGrid.js
1 Ext.define('PMG.grid.SpamInfoGrid', {
2 extend: 'Ext.grid.GridPanel',
3 xtype: 'pmgSpamInfoGrid',
4
5 store: {
6 autoDestroy: true,
7 fields: ['desc', 'name', { type: 'number', name: 'score' }],
8 proxy: {
9 type: 'proxmox',
10 root: 'data.spaminfo',
11 },
12 sorters: 'score',
13 },
14
15 setID: function(rec) {
16 let me = this;
17 let id = rec?.data?.id;
18 if (!id) {
19 me.getStore().removeAll();
20 return;
21 }
22 me.store.proxy.setUrl(`/api2/json/quarantine/content?id=${id}`);
23 me.store.load();
24 },
25
26 emptyText: gettext('No Spam Info'),
27 hidden: true,
28
29 features: [{
30 ftype: 'summary',
31 }],
32
33 columns: [
34 {
35 text: gettext('Test Name'),
36 dataIndex: 'name',
37 flex: 1,
38 summaryType: 'count',
39 summaryRenderer: _v => gettext('Spamscore'),
40 tdCls: 'txt-monospace',
41 },
42 {
43 text: gettext('Score'),
44 dataIndex: 'score',
45 align: 'right',
46 tdCls: 'txt-monospace',
47 renderer: function(score, meta) {
48 if (score === 0) {
49 return score;
50 }
51
52 let absScore = Math.abs(score), fontWeight = '400';
53 let background = score < 0 ? "--pmg-spam-mid-neg" : "--pmg-spam-mid-pos";
54
55 if (absScore >= 3) {
56 fontWeight = '900';
57 background = score < 0 ? "--pmg-spam-high-neg" : "--pmg-spam-high-pos";
58 } else if (absScore >= 1.5) {
59 fontWeight = '600';
60 } else if (absScore <= 0.1) {
61 fontWeight = '200';
62 background = score < 0 ? "--pmg-spam-low-neg" : "--pmg-spam-low-pos";
63 }
64
65 meta.tdStyle = `font-weight: ${fontWeight};background-color: var(${background});`;
66 return score;
67 },
68 summaryType: 'sum',
69 summaryRenderer: value => Ext.util.Format.round(value, 5),
70 },
71 {
72 text: gettext('Description'),
73 dataIndex: 'desc',
74 flex: 2,
75 },
76 ],
77 });