]> git.proxmox.com Git - pmg-gui.git/blame_incremental - js/Dashboard.js
fix #5251: login: set autocomplete on password and user
[pmg-gui.git] / js / Dashboard.js
... / ...
CommitLineData
1Ext.define('PMG.Dashboard', {
2 extend: 'Ext.panel.Panel',
3 xtype: 'pmgDashboard',
4
5 controller: {
6 xclass: 'Ext.app.ViewController',
7
8 openDashboardOptions: function() {
9 var me = this;
10 var viewModel = me.getViewModel();
11 Ext.create('Ext.window.Window', {
12 modal: true,
13 width: 300,
14 title: gettext('Dashboard Options'),
15 layout: {
16 type: 'auto',
17 },
18 items: [{
19 xtype: 'form',
20 bodyPadding: '10 10 10 10',
21 defaultButton: 'savebutton',
22 items: [{
23 xtype: 'proxmoxintegerfield',
24 itemId: 'hours',
25 labelWidth: 100,
26 anchor: '100%',
27 allowBlank: false,
28 minValue: 1,
29 maxValue: 24,
30 value: viewModel.get('hours'),
31 fieldLabel: gettext('Hours to show'),
32 }],
33 buttons: [{
34 text: gettext('Save'),
35 reference: 'loginButton',
36 formBind: true,
37 handler: function() {
38 var win = this.up('window');
39 var hours = win.down('#hours').getValue();
40 me.setHours(hours, true);
41 win.close();
42 },
43 }],
44 }],
45 }).show();
46 },
47
48 setHours: function(hours, setState) {
49 var me = this;
50 var viewModel = me.getViewModel();
51 viewModel.set('hours', hours);
52 viewModel.notify();
53
54 Ext.Array.forEach(['recentmails', 'receivers'], function(item) {
55 viewModel.getStore(item).reload();
56 });
57
58 if (setState) {
59 var sp = Ext.state.Manager.getProvider();
60 sp.set('dashboard-hours', hours);
61 }
62 },
63
64 updateMailStats: function(store, records, success) {
65 if (!success) {
66 return;
67 }
68 var me = this;
69 var viewModel = me.getViewModel();
70
71 var count = 0;
72 var bytes_in = 0;
73 var bytes_out = 0;
74 var ptime = 0;
75 var avg_ptime = 'N/A';
76
77 records.forEach(function(item) {
78 bytes_in += item.data.bytes_in;
79 bytes_out += item.data.bytes_out;
80 // unnormalize
81 count += (item.data.count*item.data.timespan)/60;
82 ptime += item.data.ptimesum;
83 });
84
85 if (count) {
86 avg_ptime = (ptime/count).toFixed(2) + " s";
87 }
88
89 viewModel.set('bytes_in', Proxmox.Utils.format_size(bytes_in));
90 viewModel.set('bytes_out', Proxmox.Utils.format_size(bytes_out));
91 viewModel.set('avg_ptime', avg_ptime);
92 },
93
94 updateClusterStats: function(store, records, success) {
95 if (!success) {
96 return;
97 }
98 var me = this;
99 var viewmodel = me.getViewModel();
100
101 var subStatus = 2; // 2 = all good, 1 = different leves, 0 = none
102 var subLevel = "";
103
104 var cpu = 0;
105 var mem = 0;
106 var hd = 0;
107 var count = records.length;
108 var errors = [];
109
110 records.forEach(function(item) {
111 // subscription level check
112 if (subStatus && item.data.level) {
113 if (subLevel !== "" && subLevel !== item.data.level) {
114 subStatus = 1;
115 } else if (subLevel === "") {
116 subLevel = item.data.level;
117 }
118 } else {
119 subStatus = 0;
120 }
121
122 if (item.data.name === Proxmox.NodeName) {
123 let repoStatus = me.lookup('nodeInfo').down('#repositoryStatus');
124 repoStatus.setSubscriptionStatus(!!item.data.level);
125 }
126
127 // resources count
128 cpu += item.data.cpu || 0;
129
130 var memory = item.data.memory || { used: 0, total: 1 };
131 mem += memory.used/memory.total;
132
133 var rootfs = item.data.rootfs || { used: 0, total: 1 };
134 hd += rootfs.used/rootfs.total;
135
136 if (item.data.conn_error && count > 1) {
137 count--;
138 errors.push({
139 name: item.data.name,
140 msg: item.data.conn_error,
141 });
142 }
143 });
144
145 var subscriptionPanel = me.lookup('subscription');
146 subscriptionPanel.setSubStatus(subStatus);
147
148 // the node info already displays this information in case there is no cluster
149 me.lookup('clusterResources').setHidden(records.length === 1);
150
151 cpu = cpu/count;
152 mem = mem/count;
153 hd = hd/count;
154
155 var cpuPanel = me.lookup('cpu');
156 cpuPanel.updateValue(cpu);
157
158 var memPanel = me.lookup('mem');
159 memPanel.updateValue(mem);
160
161 var hdPanel = me.lookup('hd');
162 hdPanel.updateValue(hd);
163
164 if (errors.length && !viewmodel.get('error_shown')) {
165 var text = "";
166 errors.forEach(function(error) {
167 text += error.name + ':<br>' + error.msg + '<br>';
168 });
169 Ext.Msg.alert(gettext('Error'), text);
170 viewmodel.set('error_shown', true);
171 }
172 },
173
174 updateRepositoryStatus: function(store, records, success) {
175 if (!success) {
176 return;
177 }
178
179 let me = this;
180 let repoStatus = me.lookup('nodeInfo').down('#repositoryStatus');
181 repoStatus.setRepositoryInfo(records[0].data['standard-repos']);
182 },
183
184 init: function(view) {
185 var me = this;
186 var sp = Ext.state.Manager.getProvider();
187 var hours = sp.get('dashboard-hours') || 12;
188 me.setHours(hours, false);
189
190 view.mon(sp, 'statechange', function(provider, key, value) {
191 if (key !== 'summarycolumns') {
192 return;
193 }
194 Proxmox.Utils.updateColumnWidth(view);
195 });
196 },
197 },
198
199 listeners: {
200 resize: panel => Proxmox.Utils.updateColumnWidth(panel),
201 },
202
203 viewModel: {
204 data: {
205 timespan: 300, // in seconds
206 hours: 12, // in hours
207 error_shown: false,
208 'bytes_in': 0,
209 'bytes_out': 0,
210 'avg_ptime': 0.0,
211 },
212
213 stores: {
214 cluster: {
215 storeid: 'dash-cluster',
216 type: 'update',
217 interval: 5000,
218 autoStart: true,
219 autoDestroy: true,
220 proxy: {
221 extraParams: { list_single_node: 1 },
222 type: 'proxmox',
223 url: '/api2/json/config/cluster/status',
224 },
225 listeners: {
226 load: 'updateClusterStats',
227 },
228 },
229 recentmails: {
230 storeid: 'dash-recent',
231 interval: 5000,
232 type: 'update',
233 autoStart: true,
234 autoDestroy: true,
235 proxy: {
236 type: 'proxmox',
237 url: '/api2/json/statistics/recent',
238 extraParams: {
239 hours: '{hours}',
240 timespan: '{timespan}',
241 },
242 },
243 fields: [
244 {
245 type: 'number', name: 'count',
246 convert: PMG.Utils.convert_field_to_per_min,
247 },
248 {
249 type: 'number', name: 'count_in',
250 convert: PMG.Utils.convert_field_to_per_min,
251 },
252 {
253 type: 'number', name: 'count_out',
254 convert: PMG.Utils.convert_field_to_per_min,
255 },
256 {
257 type: 'number', name: 'spam',
258 convert: PMG.Utils.convert_field_to_per_min,
259 },
260 {
261 type: 'number', name: 'spam_in',
262 convert: PMG.Utils.convert_field_to_per_min,
263 },
264 {
265 type: 'number', name: 'spam_out',
266 convert: PMG.Utils.convert_field_to_per_min,
267 },
268 {
269 type: 'number', name: 'virus',
270 convert: PMG.Utils.convert_field_to_per_min,
271 },
272 {
273 type: 'number', name: 'virus_in',
274 convert: PMG.Utils.convert_field_to_per_min,
275 },
276 { type: 'integer', name: 'virus_out' },
277 { type: 'integer', name: 'bytes_in' },
278 { type: 'integer', name: 'bytes_out' },
279 { type: 'number', name: 'ptimesum' },
280 { type: 'date', dateFormat: 'timestamp', name: 'time' },
281 ],
282 listeners: {
283 load: 'updateMailStats',
284 },
285 },
286 receivers: {
287 storeid: 'dash-receivers',
288 interval: 10000,
289 type: 'update',
290 autoStart: true,
291 autoDestroy: true,
292 proxy: {
293 type: 'proxmox',
294 url: '/api2/json/statistics/recentreceivers',
295 extraParams: {
296 hours: '{hours}',
297 limit: 10, // make this also configurable?
298 },
299 },
300 fields: [
301 { type: 'integer', name: 'count' },
302 { type: 'string', name: 'receiver' },
303 ],
304 },
305 repositories: {
306 storeid: 'dash-repositories',
307 type: 'update',
308 interval: 15000,
309 autoStart: true,
310 autoLoad: true,
311 autoDestroy: true,
312 proxy: {
313 type: 'proxmox',
314 url: '/api2/json/nodes/localhost/apt/repositories',
315 },
316 listeners: {
317 load: 'updateRepositoryStatus',
318 },
319 },
320 },
321 },
322
323 bind: {
324 title: gettext('Dashboard') + ' (' +
325 Ext.String.format(gettext('{0} hours'), '{hours}') + ')',
326 },
327
328 layout: {
329 type: 'column',
330 },
331 border: false,
332
333 bodyPadding: '20 0 0 20',
334
335 defaults: {
336 columnWidth: 1,
337 xtype: 'panel',
338 margin: '0 20 20 0',
339 },
340
341 tools: [
342 {
343 type: 'gear',
344 handler: 'openDashboardOptions',
345 },
346 ],
347
348 scrollable: true,
349
350 items: [
351 {
352 height: 300,
353 flex: 1,
354 iconCls: 'fa fa-tachometer',
355 title: gettext('E-Mail Volume'),
356 layout: {
357 type: 'vbox',
358 align: 'stretch',
359 },
360 defaults: {
361 xtype: 'pmgMiniGraph',
362 bind: {
363 store: '{recentmails}',
364 },
365 },
366 items: [
367 {
368 fields: ['count'],
369 fieldTitles: [gettext('Mails / min')],
370 seriesConfig: {
371 colors: ['#00617F'],
372 style: {
373 opacity: 0.60,
374 lineWidth: 1,
375 },
376 highlightCfg: {
377 opacity: 1,
378 scaling: 1,
379 },
380 },
381 },
382 {
383 fields: ['spam'],
384 fieldTitles: [gettext('Spam / min')],
385 seriesConfig: {
386 colors: ['#E67300'],
387 style: {
388 opacity: 0.60,
389 lineWidth: 1,
390 },
391 highlightCfg: {
392 opacity: 1,
393 scaling: 1,
394 },
395 },
396 },
397 ],
398 },
399 {
400 xtype: 'container',
401 height: 300,
402 layout: {
403 type: 'vbox',
404 align: 'stretch',
405 },
406 items: [
407 {
408 xtype: 'pmgMailProcessing',
409 title: gettext('E-Mail Processing'),
410 iconCls: 'fa fa-hourglass-half',
411 height: 180,
412 bind: {
413 data: {
414 'bytes_in': '{bytes_in}',
415 'bytes_out': '{bytes_out}',
416 'avg_ptime': '{avg_ptime}',
417 },
418 },
419 },
420 {
421 iconCls: 'fa fa-ticket',
422 title: gettext('Subscription'),
423 reference: 'subscription',
424 xtype: 'pmgSubscriptionInfo',
425 margin: '10 0 0 0',
426 height: 110,
427 },
428 ],
429 },
430 {
431 xtype: 'pmgNodeInfoPanel',
432 reference: 'nodeInfo',
433 height: 300,
434 bodyPadding: '15 5 15 5',
435 iconCls: 'fa fa-tasks',
436 },
437 {
438 height: 300,
439 iconCls: 'fa fa-list',
440 title: gettext('Top Receivers'),
441
442 bodyPadding: '10 10 10 10',
443 layout: {
444 type: 'vbox',
445 pack: 'center',
446 align: 'stretch',
447 },
448 items: [{
449 xtype: 'grid',
450 bind: {
451 store: '{receivers}',
452 },
453 emptyText: gettext('No data in database'),
454 // remove all borders/lines/headers
455 border: false,
456 bodyBorder: false,
457 hideHeaders: true,
458 header: false,
459 columnLines: false,
460 rowLines: false,
461 viewConfig: {
462 stripeRows: false,
463 },
464 columns: [
465 {
466 dataIndex: 'receiver',
467 flex: 1,
468 text: gettext('Receiver'),
469 },
470 {
471 dataIndex: 'count',
472 align: 'right',
473 text: gettext('Count'),
474 },
475 ],
476 }],
477 },
478 {
479 height: 250,
480 iconCls: 'fa fa-tasks',
481 title: gettext('Cluster Resources (average)'),
482 reference: 'clusterResources',
483 hidden: true,
484 bodyPadding: '0 20 0 20',
485 layout: {
486 type: 'hbox',
487 align: 'center',
488 },
489 defaults: {
490 xtype: 'proxmoxGauge',
491 spriteFontSize: '20px',
492 flex: 1,
493 },
494 items: [
495 {
496 title: gettext('CPU'),
497 reference: 'cpu',
498 },
499 {
500 title: gettext('Memory'),
501 reference: 'mem',
502 },
503 {
504 title: gettext('Storage'),
505 reference: 'hd',
506 },
507 ],
508 },
509 ],
510});