]> git.proxmox.com Git - proxmox-backup.git/blame - www/Dashboard.js
ui: do *not* close panel when triggering datastore GC
[proxmox-backup.git] / www / Dashboard.js
CommitLineData
84b9eced
TL
1Ext.define('PBS.Dashboard', {
2 extend: 'Ext.panel.Panel',
3 xtype: 'pbsDashboard',
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 if (setState) {
55 var sp = Ext.state.Manager.getProvider();
56 sp.set('dashboard-hours', hours);
57 }
58 },
59
60
61 updateSubscription: function(store, records, success) {
62 if (!success) {
63 return;
64 }
65 var me = this;
66 var viewmodel = me.getViewModel();
67
68 var subStatus = 2; // 2 = all good, 1 = different leves, 0 = none
69 var subLevel = "";
70 },
71
72 updateUsageStats: function(store, records, success) {
73 if (!success) {
74 return;
75 }
76 if (records === undefined || records.length < 1) {
77 return;
78 }
79 let me = this;
80 let viewmodel = me.getViewModel();
81
82 let res = records[0].data;
83
84 let cpu = res.cpu,
85 mem = res.memory,
86 hd = 0;
87
88 var cpuPanel = me.lookup('cpu');
89 cpuPanel.updateValue(cpu);
90
91 var memPanel = me.lookup('mem');
92 memPanel.updateValue(mem.used / mem.total);
93
94 //var hdPanel = me.lookup('hd');
95 //hdPanel.updateValue(hd);
96 },
97
98 init: function(view) {
99 var me = this;
100 var sp = Ext.state.Manager.getProvider();
101 var hours = sp.get('dashboard-hours') || 12;
102 me.setHours(hours, false);
103 }
104 },
105
106 viewModel: {
107 data: {
108 timespan: 300, // in seconds
109 hours: 12, // in hours
110 error_shown: false,
111 'bytes_in': 0,
112 'bytes_out': 0,
113 'avg_ptime': 0.0
114 },
115
116 stores: {
117 usage: {
118 storeid: 'dash-usage',
119 type: 'update',
120 interval: 3000,
121 autoStart: true,
122 autoLoad: true,
123 autoDestroy: true,
124 proxy: {
125 type: 'proxmox',
126 url: '/api2/json/nodes/localhost/status/usage'
127 },
128 listeners: {
129 load: 'updateUsageStats'
130 }
131 },
132 subscription: {
133 storeid: 'dash-subscription',
134 type: 'update',
135 interval: 10000,
136 autoStart: true,
137 autoLoad: true,
138 autoDestroy: true,
139 proxy: {
140 type: 'proxmox',
141 url: '/api2/json/subscription'
142 },
143 listeners: {
144 load: 'updateSubscription'
145 }
146 },
147 }
148 },
149
150 title: gettext('Dashboard') + ' - WIP',
151
152 layout: {
153 type: 'column'
154 },
155
156 bodyPadding: '20 0 0 20',
157
158 defaults: {
159 columnWidth: 0.49,
160 xtype: 'panel',
161 margin: '0 20 20 0'
162 },
163
164 scrollable: true,
165
166 items: [
167 {
168 height: 250,
169 iconCls: 'fa fa-tasks',
170 title: gettext('Server Resources'),
171 bodyPadding: '0 20 0 20',
172 layout: {
173 type: 'hbox',
174 align: 'center'
175 },
176 defaults: {
177 xtype: 'proxmoxGauge',
178 spriteFontSize: '20px',
179 flex: 1
180 },
181 items: [
182 {
183 title: gettext('CPU'),
184 reference: 'cpu'
185 },
186 {
187 title: gettext('Memory'),
188 reference: 'mem'
189 },
190 {
191 title: gettext('Storage'),
192 reference: 'hd'
193 }
194 ]
195 },
196 {
197 xtype: 'container',
198 height: 250,
199 layout: {
200 type: 'vbox',
201 align: 'stretch'
202 },
203 items: [
204 {
205 iconCls: 'fa fa-ticket',
206 title: 'Subscription',
207 reference: 'subscription',
208 xtype: 'pmgSubscriptionInfo',
209 height: 110
210 }
211 ]
212 },
213 ]
214});
215
216Ext.define('PMG.dashboard.SubscriptionInfo', {
217 extend: 'Ext.panel.Panel',
218 xtype: 'pmgSubscriptionInfo',
219
220 data: {
221 icon: 'question-circle',
222 message: gettext('Unknown')
223 },
224
225 style: {
226 cursor: 'pointer'
227 },
228
229 setSubStatus: function(status) {
230 var me = this;
231 var data = {};
232
233 switch (status) {
234 case 2:
235 data.icon = 'check green';
236 data.message = gettext('Your subscription status is valid.');
237 break;
2e75b6d8 238 case 1:
84b9eced
TL
239 data.icon = 'exclamation-triangle yellow';
240 data.message = gettext('Warning: Your subscription levels are not the same.');
241 break;
2e75b6d8 242 case 0:
84b9eced
TL
243 data.icon = 'times-circle red';
244 data.message = gettext('You have at least one node without subscription.');
245 break;
246 default:
247 throw 'invalid subscription status';
248 }
249 me.update(data);
250 },
251 tpl: [
252 '<table style="height: 100%;" class="dash">',
253 '<tr><td class="center">',
254 '<i class="fa fa-3x fa-{icon}"></i>',
255 '</td><td class="center">{message}</td></tr>',
256 '</table>'
257 ],
258
259 listeners: {
260 click: {
261 element: 'body',
262 fn: function() {
263 var mainview = this.component.up('mainview');
264 mainview.getController().redirectTo('pmgSubscription');
265 }
266 }
267 }
268});