]>
Commit | Line | Data |
---|---|---|
6f3146c0 DC |
1 | Ext.define('PBS.TaskSummary', { |
2 | extend: 'Ext.panel.Panel', | |
3 | alias: 'widget.pbsTaskSummary', | |
4 | ||
ad9d1625 | 5 | title: gettext('Task Summary'), |
6f3146c0 DC |
6 | |
7 | controller: { | |
8 | xclass: 'Ext.app.ViewController', | |
9 | ||
dee74aa4 DC |
10 | states: [ |
11 | "", | |
12 | "error", | |
13 | "warning", | |
14 | "ok", | |
15 | ], | |
16 | ||
9608ac34 DC |
17 | types: [ |
18 | "backup", | |
19 | "prune", | |
20 | "garbage_collection", | |
21 | "sync", | |
4acd7229 | 22 | "verify", |
9608ac34 DC |
23 | ], |
24 | ||
25 | titles: { | |
26 | "backup": gettext('Backups'), | |
27 | "prune": gettext('Prunes'), | |
28 | "garbage_collection": gettext('Garbage collections'), | |
29 | "sync": gettext('Syncs'), | |
dee74aa4 DC |
30 | "verify": gettext('Verify'), |
31 | }, | |
32 | ||
33 | openTaskList: function(grid, td, cellindex, record, tr, rowindex) { | |
34 | let me = this; | |
35 | let view = me.getView(); | |
36 | ||
37 | if (cellindex > 0) { | |
38 | let tasklist = view.tasklist; | |
39 | let state = me.states[cellindex]; | |
40 | let type = me.types[rowindex]; | |
41 | let filterParam = { | |
42 | 'statusfilter': state, | |
43 | 'typefilter': type, | |
44 | }; | |
45 | ||
46 | if (me.since) { | |
47 | filterParam.since = me.since; | |
48 | } | |
49 | ||
50 | if (record.data[state] === 0) { | |
51 | return; | |
52 | } | |
53 | ||
54 | if (tasklist === undefined) { | |
55 | tasklist = Ext.create('Ext.grid.Panel', { | |
56 | tools: [{ | |
57 | handler: () => tasklist.setVisible(false), | |
58 | }], | |
59 | floating: true, | |
60 | scrollable: true, | |
61 | ||
62 | height: 400, | |
63 | width: 600, | |
64 | ||
65 | columns: [ | |
66 | { | |
67 | text: gettext('Task'), | |
68 | dataIndex: 'upid', | |
69 | renderer: Proxmox.Utils.render_upid, | |
70 | flex: 1, | |
71 | }, | |
72 | { | |
73 | header: gettext("Start Time"), | |
74 | dataIndex: 'starttime', | |
75 | width: 130, | |
76 | renderer: function(value) { | |
77 | return Ext.Date.format(value, "M d H:i:s"); | |
78 | }, | |
79 | }, | |
80 | { | |
81 | xtype: 'actioncolumn', | |
82 | width: 40, | |
83 | items: [ | |
84 | { | |
85 | iconCls: 'fa fa-chevron-right', | |
86 | tooltip: gettext('Open Task'), | |
87 | handler: function(g, rowIndex) { | |
88 | let rec = tasklist.getStore().getAt(rowIndex); | |
89 | tasklist.setVisible(false); | |
90 | Ext.create('Proxmox.window.TaskViewer', { | |
91 | upid: rec.data.upid, | |
92 | endtime: rec.data.endtime, | |
93 | listeners: { | |
94 | close: () => tasklist.setVisible(true), | |
95 | }, | |
96 | }).show(); | |
97 | }, | |
98 | }, | |
99 | ], | |
100 | }, | |
101 | ], | |
102 | ||
103 | store: { | |
104 | sorters: [ | |
105 | { | |
106 | property: 'starttime', | |
107 | direction: 'DESC', | |
108 | }, | |
109 | ], | |
110 | type: 'store', | |
111 | model: 'proxmox-tasks', | |
112 | proxy: { | |
113 | type: 'proxmox', | |
114 | url: "/api2/json/status/tasks", | |
115 | }, | |
116 | }, | |
117 | }); | |
118 | ||
119 | view.on('destroy', function() { | |
120 | tasklist.setVisible(false); | |
121 | tasklist.destroy(); | |
122 | tasklist = undefined; | |
123 | }); | |
124 | ||
125 | view.tasklist = tasklist; | |
126 | } else { | |
127 | let cidx = tasklist.cidx; | |
128 | let ridx = tasklist.ridx; | |
129 | ||
130 | if (cidx === cellindex && ridx === rowindex && tasklist.isVisible()) { | |
131 | tasklist.setVisible(false); | |
132 | return; | |
133 | } | |
134 | } | |
135 | ||
136 | tasklist.cidx = cellindex; | |
137 | tasklist.ridx = rowindex; | |
138 | ||
139 | let task = me.titles[type]; | |
140 | let status = ""; | |
141 | switch (state) { | |
142 | case 'ok': status = gettext("OK"); break; | |
143 | case 'warnings': status = gettext("Warning"); break; | |
144 | case 'error': status = Proxmox.Utils.errorText; break; | |
145 | } | |
146 | let icon = me.render_icon(state, 1); | |
147 | tasklist.setTitle(`${task} - ${status} ${icon}`); | |
148 | tasklist.getStore().getProxy().setExtraParams(filterParam); | |
149 | tasklist.getStore().removeAll(); | |
150 | ||
151 | tasklist.showBy(td, 'bl-tl'); | |
152 | setTimeout(() => tasklist.getStore().reload(), 10); | |
153 | } | |
9608ac34 DC |
154 | }, |
155 | ||
90d7425a | 156 | render_icon: function(state, count) { |
6f3146c0 | 157 | let cls = 'question'; |
be30e7d2 | 158 | let color = 'faded'; |
90d7425a DC |
159 | switch (state) { |
160 | case "error": | |
be30e7d2 DC |
161 | cls = "times-circle"; |
162 | color = "critical"; | |
163 | break; | |
90d7425a | 164 | case "warning": |
be30e7d2 DC |
165 | cls = "exclamation-circle"; |
166 | color = "warning"; | |
167 | break; | |
90d7425a | 168 | case "ok": |
be30e7d2 DC |
169 | cls = "check-circle"; |
170 | color = "good"; | |
171 | break; | |
6f3146c0 DC |
172 | default: break; |
173 | } | |
be30e7d2 | 174 | |
90d7425a | 175 | if (count < 1) { |
be30e7d2 DC |
176 | color = "faded"; |
177 | } | |
178 | cls += " " + color; | |
90d7425a DC |
179 | return `<i class="fa fa-${cls}"></i>`; |
180 | }, | |
181 | ||
182 | render_count: function(value, md, record, rowindex, colindex) { | |
183 | let me = this; | |
184 | let icon = me.render_icon(me.states[colindex], value); | |
185 | return `${icon} ${value}`; | |
6f3146c0 DC |
186 | }, |
187 | }, | |
188 | ||
dee74aa4 | 189 | updateTasks: function(source, since) { |
6f3146c0 | 190 | let me = this; |
9608ac34 DC |
191 | let controller = me.getController(); |
192 | let data = []; | |
193 | controller.types.forEach((type) => { | |
194 | source[type].type = controller.titles[type]; | |
195 | data.push(source[type]); | |
196 | }); | |
197 | me.lookup('grid').getStore().setData(data); | |
dee74aa4 | 198 | controller.since = since; |
6f3146c0 DC |
199 | }, |
200 | ||
201 | layout: 'fit', | |
202 | bodyPadding: 15, | |
203 | minHeight: 166, | |
204 | ||
205 | // we have to wrap the grid in a panel to get the padding right | |
206 | items: [ | |
207 | { | |
208 | xtype: 'grid', | |
209 | reference: 'grid', | |
210 | hideHeaders: true, | |
211 | border: false, | |
212 | bodyBorder: false, | |
213 | rowLines: false, | |
214 | viewConfig: { | |
215 | stripeRows: false, | |
216 | trackOver: false, | |
217 | }, | |
218 | scrollable: false, | |
219 | disableSelection: true, | |
220 | ||
221 | store: { | |
6ab77df3 | 222 | data: [], |
6f3146c0 DC |
223 | }, |
224 | ||
dee74aa4 DC |
225 | listeners: { |
226 | cellclick: 'openTaskList', | |
227 | }, | |
228 | ||
6f3146c0 DC |
229 | columns: [ |
230 | { | |
231 | dataIndex: 'type', | |
232 | flex: 1, | |
233 | }, | |
234 | { | |
235 | dataIndex: 'error', | |
236 | renderer: 'render_count', | |
237 | }, | |
238 | { | |
239 | dataIndex: 'warning', | |
240 | renderer: 'render_count', | |
241 | }, | |
242 | { | |
243 | dataIndex: 'ok', | |
244 | renderer: 'render_count', | |
245 | }, | |
246 | ], | |
6ab77df3 | 247 | }, |
6f3146c0 DC |
248 | ], |
249 | ||
250 | }); |