]> git.proxmox.com Git - proxmox-widget-toolkit.git/blob - src/panel/InfoWidget.js
info widget: set default warning threshold to 75%
[proxmox-widget-toolkit.git] / src / panel / InfoWidget.js
1 Ext.define('Proxmox.widget.Info', {
2 extend: 'Ext.container.Container',
3 alias: 'widget.pmxInfoWidget',
4
5 layout: {
6 type: 'vbox',
7 align: 'stretch',
8 },
9
10 value: 0,
11 maximum: 1,
12 printBar: true,
13 items: [
14 {
15 xtype: 'component',
16 itemId: 'label',
17 data: {
18 title: '',
19 usage: '',
20 iconCls: undefined,
21 },
22 tpl: [
23 '<div class="left-aligned">',
24 '<tpl if="iconCls">',
25 '<i class="{iconCls}"></i> ',
26 '</tpl>',
27 '{title}</div>&nbsp;<div class="right-aligned">{usage}</div>',
28 ],
29 },
30 {
31 height: 2,
32 border: 0,
33 },
34 {
35 xtype: 'progressbar',
36 itemId: 'progress',
37 height: 5,
38 value: 0,
39 animate: true,
40 },
41 ],
42
43 warningThreshold: 0.75,
44 criticalThreshold: 0.9,
45
46 setPrintBar: function(enable) {
47 var me = this;
48 me.printBar = enable;
49 me.getComponent('progress').setVisible(enable);
50 },
51
52 setIconCls: function(iconCls) {
53 var me = this;
54 me.getComponent('label').data.iconCls = iconCls;
55 },
56
57 setData: function(data) {
58 this.updateValue(data.text, data.usage);
59 },
60
61 updateValue: function(text, usage) {
62 var me = this;
63 var label = me.getComponent('label');
64 label.update(Ext.apply(label.data, { title: me.title, usage: text }));
65
66 if (usage !== undefined && me.printBar && Ext.isNumeric(usage) && usage >= 0) {
67 let progressBar = me.getComponent('progress');
68 progressBar.updateProgress(usage, '');
69 if (usage > me.criticalThreshold) {
70 progressBar.removeCls('warning');
71 progressBar.addCls('critical');
72 } else if (usage > me.warningThreshold) {
73 progressBar.removeCls('critical');
74 progressBar.addCls('warning');
75 } else {
76 progressBar.removeCls('warning');
77 progressBar.removeCls('critical');
78 }
79 }
80 },
81
82 initComponent: function() {
83 var me = this;
84
85 if (!me.title) {
86 throw "no title defined";
87 }
88
89 me.callParent();
90
91 me.getComponent('progress').setVisible(me.printBar);
92
93 me.updateValue(me.text, me.value);
94 me.setIconCls(me.iconCls);
95 },
96
97 });