]> git.proxmox.com Git - pmg-gui.git/blob - js/SenderStatistics.js
use MiB instead of MBytes
[pmg-gui.git] / js / SenderStatistics.js
1 /*global Proxmox*/
2 /*jslint confusion: true*/
3 /* filter is a function and object */
4 Ext.define('PMG.SenderDetails', {
5 extend: 'Ext.grid.GridPanel',
6 xtype: 'pmgSenderDetails',
7
8 dockedItems: [
9 {
10 dock: 'top',
11 xtype: 'panel',
12 itemId: 'info',
13 bodyPadding: 10,
14 html: gettext('Please select a sender.')
15 }
16 ],
17
18 disableSelection: true,
19
20 plugins: 'gridfilters',
21
22 setUrl: function(url, title) {
23 var me = this;
24
25 me.store.setUrl(url);
26 me.store.setRemoteFilter(url !== undefined);
27 Proxmox.Utils.setErrorMask(me, false);
28 me.store.reload();
29
30 var infopanel = me.getComponent('info');
31 if (title) {
32 infopanel.update(title);
33 } else {
34 infopanel.update(gettext('Please select a sender.'));
35 }
36 },
37
38 store: {
39 type: 'pmgStatStore',
40 autoReload: false,
41 remoteSort: true,
42 remoteFilter: false, // enabled dynamically
43 fields: [
44 'receiver', 'virusinfo',
45 { type: 'integer', name: 'bytes' },
46 { type: 'boolean', name: 'blocked' },
47 { type: 'integer', name: 'spamlevel' },
48 { type: 'date', dateFormat: 'timestamp', name: 'time' }
49 ],
50 proxy: {
51 type: 'pmgfilterproxy',
52 filterId: 'x-gridfilter-receiver',
53 sortParam: 'orderby'
54 },
55 sorters: [
56 {
57 property: 'time',
58 direction: 'ASC'
59 }
60 ]
61 },
62
63 columns: [
64 {
65 text: gettext('Receiver'),
66 renderer: Ext.htmlEncode,
67 flex: 1,
68 filter: { type: 'string' },
69 dataIndex: 'receiver'
70 },
71 {
72 header: gettext('Size') + ' (KB)',
73 renderer: function(v) { return Ext.Number.toFixed(v/1024, 0); },
74 dataIndex: 'bytes'
75 },
76 {
77 xtype: 'datecolumn',
78 header: gettext('Date'),
79 format: 'Y-m-d',
80 dataIndex: 'time'
81 },
82 {
83 xtype: 'datecolumn',
84 header: gettext('Time'),
85 format: 'H:i:s',
86 dataIndex: 'time'
87 }
88 ],
89
90 initComponent: function() {
91 var me = this;
92 me.callParent();
93
94 Proxmox.Utils.monStoreErrors(me, me.store, true);
95 }
96 });
97
98 Ext.define('PMG.SenderList', {
99 extend: 'Ext.grid.GridPanel',
100 alias: 'widget.pmgSenderList',
101
102 title: gettext('Statistics') + ': ' + gettext('Sender') +
103 ' (' + gettext('Outgoing') +')',
104
105 multiColumnSort: true,
106 plugins: 'gridfilters',
107
108 emptyText: gettext('No data in database.'),
109 viewConfig: {
110 deferEmptyText: false
111 },
112
113 tbar: [ { xtype: 'pmgStatTimeSelector' } ],
114
115 store: {
116 type: 'pmgStatStore',
117 staturl: '/api2/json/statistics/sender',
118 remoteSort: true,
119 remoteFilter: true,
120 fields: [
121 'sender',
122 { type: 'integer', name: 'count' },
123 { type: 'integer', name: 'bytes' },
124 { type: 'integer', name: 'viruscount' }
125 ],
126 proxy: {
127 type: 'pmgfilterproxy',
128 sortParam: 'orderby',
129 filterId: 'x-gridfilter-sender'
130 },
131 sorters: [
132 {
133 property: 'count',
134 direction: 'DESC'
135 },
136 {
137 property: 'bytes',
138 direction: 'DESC'
139 },
140 {
141 property: 'sender',
142 direction: 'ASC'
143 }
144 ]
145 },
146
147 columns: [
148 {
149 text: gettext('Sender'),
150 flex: 1,
151 renderer: Ext.htmlEncode,
152 dataIndex: 'sender',
153 filter: {
154 type: 'string',
155 itemDefaults: {
156 // any Ext.form.field.Text configs accepted
157 }
158 }
159 },
160 {
161 text: gettext('Count'),
162 columns: [
163 {
164 text: gettext('Mail'),
165 dataIndex: 'count'
166 },
167 {
168 header: gettext('Virus'),
169 dataIndex: 'viruscount'
170 }
171 ]
172 },
173 {
174 text: gettext('Size') + ' (KB)',
175 dataIndex: 'bytes',
176 renderer: function(v) {
177 return Ext.Number.toFixed(v/1024, 0);
178 }
179 }
180 ],
181
182 initComponent: function() {
183 var me = this;
184 me.callParent();
185
186 Proxmox.Utils.monStoreErrors(me, me.store, true);
187 }
188 });
189
190 Ext.define('PMG.SenderStatistics', {
191 extend: 'Ext.panel.Panel',
192 xtype: 'pmgSenderStatistics',
193
194 layout: 'border',
195 border: false,
196 defaults: {
197 border: false
198 },
199
200 controller: {
201 xclass: 'Ext.app.ViewController',
202
203 selectionChange: function(grid, selected, eOpts) {
204 var details = this.lookupReference('details');
205 if (selected.length > 0) {
206 var sender = selected[0].data.sender;
207 var url = "/api2/json/statistics/sender/" +
208 encodeURIComponent(sender);
209 details.setUrl(url, '<b>' + gettext('Sender') + ':</b> ' + Ext.htmlEncode(sender));
210 } else {
211 details.setUrl();
212 }
213 }
214 },
215
216 items: [
217 {
218 xtype: 'pmgSenderList',
219 multiColumnSort: true,
220 region: 'center',
221 layout: 'fit',
222 flex: 1,
223
224 listeners: { selectionchange: 'selectionChange' }
225 },
226 {
227 xtype: 'pmgSenderDetails',
228 region: 'east',
229 reference: 'details',
230 split: true,
231 flex: 1
232 }
233 ]
234 });