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