]>
Commit | Line | Data |
---|---|---|
b87d4733 DC |
1 | Ext.define('Proxmox.panel.StatusView', { |
2 | extend: 'Ext.panel.Panel', | |
3 | alias: 'widget.pmxStatusView', | |
4 | ||
5 | layout: { | |
6 | type: 'column', | |
7 | }, | |
8 | ||
9 | title: gettext('Status'), | |
10 | ||
11 | getRecordValue: function(key, store) { | |
0d58bef7 TL |
12 | let me = this; |
13 | ||
b87d4733 DC |
14 | if (!key) { |
15 | throw "no key given"; | |
16 | } | |
b87d4733 DC |
17 | |
18 | if (store === undefined) { | |
19 | store = me.getStore(); | |
20 | } | |
21 | ||
0d58bef7 | 22 | let rec = store.getById(key); |
b87d4733 DC |
23 | if (rec) { |
24 | return rec.data.value; | |
25 | } | |
b87d4733 DC |
26 | return ''; |
27 | }, | |
28 | ||
29 | fieldRenderer: function(val, max) { | |
30 | if (max === undefined) { | |
31 | return val; | |
32 | } | |
33 | ||
34 | if (!Ext.isNumeric(max) || max === 1) { | |
35 | return Proxmox.Utils.render_usage(val); | |
36 | } | |
37 | return Proxmox.Utils.render_size_usage(val, max); | |
38 | }, | |
39 | ||
40 | fieldCalculator: function(used, max) { | |
41 | if (!Ext.isNumeric(max) && Ext.isNumeric(used)) { | |
42 | return used; | |
43 | } else if (!Ext.isNumeric(used)) { | |
44 | /* we come here if the field is from a node | |
45 | * where the records are not mem and maxmem | |
46 | * but mem.used and mem.total | |
47 | */ | |
48 | if (used.used !== undefined && | |
49 | used.total !== undefined) { | |
50 | return used.used/used.total; | |
51 | } | |
52 | } | |
53 | ||
54 | return used/max; | |
55 | }, | |
56 | ||
57 | updateField: function(field) { | |
0d58bef7 TL |
58 | let me = this; |
59 | let renderer = me.fieldRenderer; | |
b87d4733 DC |
60 | if (Ext.isFunction(field.renderer)) { |
61 | renderer = field.renderer; | |
62 | } | |
63 | if (field.multiField === true) { | |
64 | field.updateValue(renderer.call(field, me.getStore().getRecord())); | |
65 | } else if (field.textField !== undefined) { | |
66 | field.updateValue(renderer.call(field, me.getRecordValue(field.textField))); | |
67 | } else if (field.valueField !== undefined) { | |
0d58bef7 TL |
68 | let used = me.getRecordValue(field.valueField); |
69 | let max = field.maxField !== undefined ? me.getRecordValue(field.maxField) : 1; | |
b87d4733 | 70 | |
0d58bef7 | 71 | let calculate = me.fieldCalculator; |
b87d4733 DC |
72 | if (Ext.isFunction(field.calculate)) { |
73 | calculate = field.calculate; | |
74 | } | |
75 | field.updateValue(renderer.call(field, used, max), calculate(used, max)); | |
76 | } | |
77 | }, | |
78 | ||
79 | getStore: function() { | |
0d58bef7 TL |
80 | let me = this; |
81 | ||
b87d4733 DC |
82 | if (!me.rstore) { |
83 | throw "there is no rstore"; | |
84 | } | |
85 | ||
86 | return me.rstore; | |
87 | }, | |
88 | ||
89 | updateTitle: function() { | |
0d58bef7 | 90 | let me = this; |
b87d4733 DC |
91 | me.setTitle(me.getRecordValue('name')); |
92 | }, | |
93 | ||
94 | updateValues: function(store, records, success) { | |
0d58bef7 TL |
95 | let me = this; |
96 | ||
b87d4733 DC |
97 | if (!success) { |
98 | return; // do not update if store load was not successful | |
99 | } | |
0d58bef7 | 100 | me.query('pmxInfoWidget').forEach(me.updateField, me); |
689fa8a5 | 101 | me.query('pveInfoWidget').forEach(me.updateField, me); |
b87d4733 DC |
102 | |
103 | me.updateTitle(store); | |
104 | }, | |
105 | ||
106 | initComponent: function() { | |
0d58bef7 | 107 | let me = this; |
b87d4733 DC |
108 | |
109 | if (!me.rstore) { | |
110 | throw "no rstore given"; | |
111 | } | |
b87d4733 DC |
112 | if (!me.title) { |
113 | throw "no title given"; | |
114 | } | |
115 | ||
116 | Proxmox.Utils.monStoreErrors(me, me.rstore); | |
117 | ||
118 | me.callParent(); | |
119 | ||
120 | me.mon(me.rstore, 'load', me.updateValues, me); | |
121 | }, | |
122 | ||
123 | }); |