]>
Commit | Line | Data |
---|---|---|
24313a9d FE |
1 | Ext.define('apt-repolist', { |
2 | extend: 'Ext.data.Model', | |
3 | fields: [ | |
4 | 'Path', | |
5 | 'Index', | |
d91987a5 | 6 | 'Origin', |
24313a9d FE |
7 | 'FileType', |
8 | 'Enabled', | |
9 | 'Comment', | |
10 | 'Types', | |
11 | 'URIs', | |
12 | 'Suites', | |
13 | 'Components', | |
14 | 'Options', | |
15 | ], | |
16 | }); | |
17 | ||
21860ea4 FE |
18 | Ext.define('Proxmox.window.APTRepositoryAdd', { |
19 | extend: 'Proxmox.window.Edit', | |
20 | alias: 'widget.pmxAPTRepositoryAdd', | |
21 | ||
22 | isCreate: true, | |
23 | isAdd: true, | |
24 | ||
25 | subject: gettext('Repository'), | |
5e9eb245 | 26 | width: 600, |
21860ea4 FE |
27 | |
28 | initComponent: function() { | |
29 | let me = this; | |
30 | ||
31 | if (!me.repoInfo || me.repoInfo.length === 0) { | |
32 | throw "repository information not initialized"; | |
33 | } | |
34 | ||
35 | let description = Ext.create('Ext.form.field.Display', { | |
36 | fieldLabel: gettext('Description'), | |
37 | name: 'description', | |
38 | }); | |
39 | ||
40 | let status = Ext.create('Ext.form.field.Display', { | |
41 | fieldLabel: gettext('Status'), | |
42 | name: 'status', | |
43 | renderer: function(value) { | |
44 | let statusText = gettext('Not yet configured'); | |
45 | if (value !== '') { | |
46 | statusText = Ext.String.format( | |
47 | '{0}: {1}', | |
48 | gettext('Configured'), | |
49 | value ? gettext('enabled') : gettext('disabled'), | |
50 | ); | |
51 | } | |
52 | ||
53 | return statusText; | |
54 | }, | |
55 | }); | |
56 | ||
57 | let repoSelector = Ext.create('Proxmox.form.KVComboBox', { | |
58 | fieldLabel: gettext('Repository'), | |
59 | xtype: 'proxmoxKVComboBox', | |
60 | name: 'handle', | |
61 | allowBlank: false, | |
62 | comboItems: me.repoInfo.map(info => [info.handle, info.name]), | |
824f9977 TL |
63 | validator: function(renderedValue) { |
64 | let handle = this.value; | |
65 | // we cannot use this.callParent in instantiations | |
66 | let valid = Proxmox.form.KVComboBox.prototype.validator.call(this, renderedValue); | |
21860ea4 | 67 | |
824f9977 | 68 | if (!valid || !handle) { |
21860ea4 FE |
69 | return false; |
70 | } | |
71 | ||
72 | const info = me.repoInfo.find(elem => elem.handle === handle); | |
21860ea4 FE |
73 | if (!info) { |
74 | return false; | |
75 | } | |
76 | ||
58b71860 | 77 | if (info.status) { |
824f9977 TL |
78 | return Ext.String.format(gettext('{0} is already configured'), renderedValue); |
79 | } | |
80 | return valid; | |
21860ea4 FE |
81 | }, |
82 | listeners: { | |
83 | change: function(f, value) { | |
84 | const info = me.repoInfo.find(elem => elem.handle === value); | |
85 | description.setValue(info.description); | |
86 | status.setValue(info.status); | |
87 | }, | |
88 | }, | |
89 | }); | |
90 | ||
91 | repoSelector.setValue(me.repoInfo[0].handle); | |
92 | ||
21860ea4 | 93 | Ext.apply(me, { |
5e9eb245 TL |
94 | items: [ |
95 | repoSelector, | |
96 | description, | |
97 | status, | |
98 | ], | |
21860ea4 FE |
99 | repoSelector: repoSelector, |
100 | }); | |
101 | ||
102 | me.callParent(); | |
103 | }, | |
104 | }); | |
105 | ||
24313a9d FE |
106 | Ext.define('Proxmox.node.APTRepositoriesErrors', { |
107 | extend: 'Ext.grid.GridPanel', | |
108 | ||
109 | xtype: 'proxmoxNodeAPTRepositoriesErrors', | |
110 | ||
24313a9d FE |
111 | store: {}, |
112 | ||
f59d1076 | 113 | scrollable: true, |
d8b5cd80 | 114 | |
24313a9d FE |
115 | viewConfig: { |
116 | stripeRows: false, | |
5e0cecb7 DC |
117 | getRowClass: (record) => { |
118 | switch (record.data.status) { | |
119 | case 'warning': return 'proxmox-warning-row'; | |
120 | case 'critical': return 'proxmox-invalid-row'; | |
121 | default: return ''; | |
122 | } | |
123 | }, | |
24313a9d FE |
124 | }, |
125 | ||
5e0cecb7 DC |
126 | hideHeaders: true, |
127 | ||
24313a9d FE |
128 | columns: [ |
129 | { | |
5e0cecb7 DC |
130 | dataIndex: 'status', |
131 | renderer: (value) => `<i class="fa fa-fw ${Proxmox.Utils.get_health_icon(value, true)}"></i>`, | |
132 | width: 50, | |
24313a9d FE |
133 | }, |
134 | { | |
5e0cecb7 | 135 | dataIndex: 'message', |
24313a9d FE |
136 | flex: 1, |
137 | }, | |
138 | ], | |
139 | }); | |
140 | ||
141 | Ext.define('Proxmox.node.APTRepositoriesGrid', { | |
142 | extend: 'Ext.grid.GridPanel', | |
24313a9d | 143 | xtype: 'proxmoxNodeAPTRepositoriesGrid', |
5e76f730 | 144 | mixins: ['Proxmox.Mixin.CBind'], |
24313a9d FE |
145 | |
146 | title: gettext('APT Repositories'), | |
147 | ||
994fe897 TL |
148 | cls: 'proxmox-apt-repos', // to allow applying styling to general components with local effect |
149 | ||
d8b5cd80 DC |
150 | border: false, |
151 | ||
24313a9d FE |
152 | tbar: [ |
153 | { | |
154 | text: gettext('Reload'), | |
155 | iconCls: 'fa fa-refresh', | |
156 | handler: function() { | |
157 | let me = this; | |
158 | me.up('proxmoxNodeAPTRepositories').reload(); | |
159 | }, | |
160 | }, | |
d76eedb4 FE |
161 | { |
162 | text: gettext('Add'), | |
faacb77f | 163 | name: 'addRepo', |
21860ea4 FE |
164 | disabled: true, |
165 | repoInfo: undefined, | |
5e76f730 FE |
166 | cbind: { |
167 | onlineHelp: '{onlineHelp}', | |
168 | }, | |
21860ea4 FE |
169 | handler: function(button, event, record) { |
170 | Proxmox.Utils.checked_command(() => { | |
171 | let me = this; | |
172 | let panel = me.up('proxmoxNodeAPTRepositories'); | |
173 | ||
174 | let extraParams = {}; | |
175 | if (panel.digest !== undefined) { | |
176 | extraParams.digest = panel.digest; | |
177 | } | |
178 | ||
179 | Ext.create('Proxmox.window.APTRepositoryAdd', { | |
180 | repoInfo: me.repoInfo, | |
d7aeb02f | 181 | url: `/api2/extjs/nodes/${panel.nodename}/apt/repositories`, |
21860ea4 FE |
182 | method: 'PUT', |
183 | extraRequestParams: extraParams, | |
5e76f730 | 184 | onlineHelp: me.onlineHelp, |
21860ea4 FE |
185 | listeners: { |
186 | destroy: function() { | |
187 | panel.reload(); | |
188 | }, | |
189 | }, | |
190 | }).show(); | |
191 | }); | |
d76eedb4 FE |
192 | }, |
193 | }, | |
af48de6b | 194 | '-', |
d76eedb4 | 195 | { |
8832b590 | 196 | xtype: 'proxmoxAltTextButton', |
bb64cd03 TL |
197 | defaultText: gettext('Enable'), |
198 | altText: gettext('Disable'), | |
faacb77f | 199 | name: 'repoEnable', |
d76eedb4 | 200 | disabled: true, |
003c4982 DC |
201 | bind: { |
202 | text: '{enableButtonText}', | |
203 | }, | |
d76eedb4 FE |
204 | handler: function(button, event, record) { |
205 | let me = this; | |
206 | let panel = me.up('proxmoxNodeAPTRepositories'); | |
207 | ||
208 | let params = { | |
209 | path: record.data.Path, | |
210 | index: record.data.Index, | |
211 | enabled: record.data.Enabled ? 0 : 1, // invert | |
212 | }; | |
213 | ||
214 | if (panel.digest !== undefined) { | |
215 | params.digest = panel.digest; | |
216 | } | |
217 | ||
218 | Proxmox.Utils.API2Request({ | |
219 | url: `/nodes/${panel.nodename}/apt/repositories`, | |
220 | method: 'POST', | |
221 | params: params, | |
222 | failure: function(response, opts) { | |
223 | Ext.Msg.alert(gettext('Error'), response.htmlStatus); | |
224 | panel.reload(); | |
225 | }, | |
226 | success: function(response, opts) { | |
227 | panel.reload(); | |
228 | }, | |
229 | }); | |
230 | }, | |
231 | }, | |
24313a9d FE |
232 | ], |
233 | ||
234 | sortableColumns: false, | |
205d2751 TL |
235 | viewConfig: { |
236 | stripeRows: false, | |
237 | getRowClass: (record, index) => record.get('Enabled') ? '' : 'proxmox-disabled-row', | |
238 | }, | |
24313a9d FE |
239 | |
240 | columns: [ | |
241 | { | |
03c4c65b | 242 | xtype: 'checkcolumn', |
24313a9d FE |
243 | header: gettext('Enabled'), |
244 | dataIndex: 'Enabled', | |
03c4c65b TL |
245 | listeners: { |
246 | beforecheckchange: () => false, // veto, we don't want to allow inline change - to subtle | |
247 | }, | |
24313a9d FE |
248 | width: 90, |
249 | }, | |
250 | { | |
251 | header: gettext('Types'), | |
252 | dataIndex: 'Types', | |
253 | renderer: function(types, cell, record) { | |
254 | return types.join(' '); | |
255 | }, | |
256 | width: 100, | |
257 | }, | |
258 | { | |
259 | header: gettext('URIs'), | |
260 | dataIndex: 'URIs', | |
261 | renderer: function(uris, cell, record) { | |
262 | return uris.join(' '); | |
263 | }, | |
264 | width: 350, | |
265 | }, | |
266 | { | |
267 | header: gettext('Suites'), | |
268 | dataIndex: 'Suites', | |
e71fc6e4 DC |
269 | renderer: function(suites, metaData, record) { |
270 | let err = ''; | |
271 | if (record.data.warnings && record.data.warnings.length > 0) { | |
272 | let txt = [gettext('Warning')]; | |
273 | record.data.warnings.forEach((warning) => { | |
274 | if (warning.property === 'Suites') { | |
275 | txt.push(warning.message); | |
276 | } | |
277 | }); | |
278 | metaData.tdAttr = `data-qtip="${Ext.htmlEncode(txt.join('<br>'))}"`; | |
5a1fddb6 TL |
279 | if (record.data.Enabled) { |
280 | metaData.tdCls = 'proxmox-invalid-row'; | |
281 | err = '<i class="fa fa-fw critical fa-exclamation-circle"></i> '; | |
282 | } else { | |
283 | metaData.tdCls = 'proxmox-warning-row'; | |
284 | err = '<i class="fa fa-fw warning fa-exclamation-circle"></i> '; | |
285 | } | |
e71fc6e4 DC |
286 | } |
287 | return suites.join(' ') + err; | |
24313a9d FE |
288 | }, |
289 | width: 130, | |
290 | }, | |
291 | { | |
292 | header: gettext('Components'), | |
293 | dataIndex: 'Components', | |
06689819 | 294 | renderer: function(components, metaData, record) { |
65f4704b TL |
295 | if (components === undefined) { |
296 | return ''; | |
297 | } | |
06689819 TL |
298 | let err = ''; |
299 | if (components.length === 1) { | |
300 | // FIXME: this should be a flag set to the actual repsotiories, i.e., a tristate | |
4fc57df4 | 301 | // like production-ready = <yes|no|other> (Option<bool>) |
06689819 TL |
302 | if (components[0].match(/\w+(-no-subscription|test)\s*$/i)) { |
303 | metaData.tdCls = 'proxmox-warning-row'; | |
304 | err = '<i class="fa fa-fw warning fa-exclamation-circle"></i> '; | |
305 | ||
306 | let qtip = components[0].match(/no-subscription/) | |
307 | ? gettext('The no-subscription repository is NOT production-ready') | |
308 | : gettext('The test repository may contain unstable updates') | |
309 | ; | |
310 | metaData.tdAttr = `data-qtip="${Ext.htmlEncode(qtip)}"`; | |
311 | } | |
312 | } | |
313 | return components.join(' ') + err; | |
24313a9d FE |
314 | }, |
315 | width: 170, | |
316 | }, | |
317 | { | |
318 | header: gettext('Options'), | |
319 | dataIndex: 'Options', | |
320 | renderer: function(options, cell, record) { | |
321 | if (!options) { | |
322 | return ''; | |
323 | } | |
324 | ||
325 | let filetype = record.data.FileType; | |
326 | let text = ''; | |
327 | ||
328 | options.forEach(function(option) { | |
329 | let key = option.Key; | |
330 | if (filetype === 'list') { | |
331 | let values = option.Values.join(','); | |
332 | text += `${key}=${values} `; | |
333 | } else if (filetype === 'sources') { | |
334 | let values = option.Values.join(' '); | |
335 | text += `${key}: ${values}<br>`; | |
336 | } else { | |
017a6376 | 337 | throw "unknown file type"; |
24313a9d FE |
338 | } |
339 | }); | |
340 | return text; | |
341 | }, | |
342 | flex: 1, | |
343 | }, | |
03c4c65b | 344 | { |
d91987a5 FE |
345 | header: gettext('Origin'), |
346 | dataIndex: 'Origin', | |
036f48c1 TL |
347 | width: 120, |
348 | renderer: (value, meta, rec) => { | |
f0966f29 TL |
349 | if (typeof value !== 'string' || value.length === 0) { |
350 | value = gettext('Other'); | |
351 | } | |
036f48c1 TL |
352 | let cls = 'fa fa-fw fa-question-circle-o'; |
353 | if (value.match(/^\s*Proxmox\s*$/i)) { | |
354 | cls = 'pmx-itype-icon pmx-itype-icon-proxmox-x'; | |
8b06793b | 355 | } else if (value.match(/^\s*Debian\s*(:?Backports)?$/i)) { |
036f48c1 TL |
356 | cls = 'pmx-itype-icon pmx-itype-icon-debian-swirl'; |
357 | } | |
358 | return `<i class='${cls}'></i> ${value}`; | |
359 | }, | |
03c4c65b | 360 | }, |
24313a9d FE |
361 | { |
362 | header: gettext('Comment'), | |
363 | dataIndex: 'Comment', | |
364 | flex: 2, | |
365 | }, | |
366 | ], | |
367 | ||
7705801f TL |
368 | features: [ |
369 | { | |
370 | ftype: 'grouping', | |
371 | groupHeaderTpl: '{[ "File: " + values.name ]} ({rows.length} repositor{[values.rows.length > 1 ? "ies" : "y"]})', | |
372 | enableGroupingMenu: false, | |
373 | }, | |
374 | ], | |
375 | ||
eb1fff82 TL |
376 | store: { |
377 | model: 'apt-repolist', | |
378 | groupField: 'Path', | |
379 | sorters: [ | |
380 | { | |
381 | property: 'Index', | |
382 | direction: 'ASC', | |
383 | }, | |
384 | ], | |
385 | }, | |
386 | ||
24313a9d FE |
387 | initComponent: function() { |
388 | let me = this; | |
389 | ||
390 | if (!me.nodename) { | |
391 | throw "no node name specified"; | |
392 | } | |
393 | ||
24313a9d FE |
394 | me.callParent(); |
395 | }, | |
396 | }); | |
397 | ||
398 | Ext.define('Proxmox.node.APTRepositories', { | |
399 | extend: 'Ext.panel.Panel', | |
24313a9d FE |
400 | xtype: 'proxmoxNodeAPTRepositories', |
401 | mixins: ['Proxmox.Mixin.CBind'], | |
402 | ||
403 | digest: undefined, | |
404 | ||
5e76f730 FE |
405 | onlineHelp: undefined, |
406 | ||
3fc020f4 TL |
407 | product: 'Proxmox VE', // default |
408 | ||
003c4982 DC |
409 | controller: { |
410 | xclass: 'Ext.app.ViewController', | |
411 | ||
412 | selectionChange: function(grid, selection) { | |
413 | let me = this; | |
414 | if (!selection || selection.length < 1) { | |
415 | return; | |
416 | } | |
417 | let rec = selection[0]; | |
418 | let vm = me.getViewModel(); | |
419 | vm.set('selectionenabled', rec.get('Enabled')); | |
f59d1076 DC |
420 | vm.notify(); |
421 | }, | |
422 | ||
423 | updateState: function() { | |
424 | let me = this; | |
425 | let vm = me.getViewModel(); | |
426 | ||
5e0cecb7 DC |
427 | let store = vm.get('errorstore'); |
428 | store.removeAll(); | |
429 | ||
df7def01 TL |
430 | let status = 'good'; // start with best, the helper below will downgrade if needed |
431 | let text = gettext('All OK, you have production-ready repositories configured!'); | |
432 | ||
df7def01 | 433 | let addGood = message => store.add({ status: 'good', message }); |
46231d0d | 434 | let addWarn = (message, important) => { |
fe787c8c | 435 | if (status !== 'critical') { |
df7def01 | 436 | status = 'warning'; |
46231d0d | 437 | text = important ? message : gettext('Warning'); |
df7def01 TL |
438 | } |
439 | store.add({ status: 'warning', message }); | |
440 | }; | |
6c9af178 TL |
441 | let addCritical = (message, important) => { |
442 | status = 'critical'; | |
443 | text = important ? message : gettext('Error'); | |
444 | store.add({ status: 'critical', message }); | |
445 | }; | |
446 | ||
447 | let errors = vm.get('errors'); | |
448 | errors.forEach(error => addCritical(`${error.path} - ${error.error}`)); | |
f59d1076 DC |
449 | |
450 | let activeSubscription = vm.get('subscriptionActive'); | |
451 | let enterprise = vm.get('enterpriseRepo'); | |
452 | let nosubscription = vm.get('noSubscriptionRepo'); | |
453 | let test = vm.get('testRepo'); | |
454 | let wrongSuites = vm.get('suitesWarning'); | |
455 | ||
5e0cecb7 | 456 | if (!enterprise && !nosubscription && !test) { |
6c9af178 TL |
457 | addCritical( |
458 | Ext.String.format(gettext('No {0} repository is enabled, you do not get any updates!'), vm.get('product')), | |
459 | ); | |
6bac17e3 TL |
460 | } else if (errors.length > 0) { |
461 | // nothing extra, just avoid that we show "get updates" | |
5e0cecb7 DC |
462 | } else if (enterprise && !nosubscription && !test && activeSubscription) { |
463 | addGood(Ext.String.format(gettext('You get supported updates for {0}'), vm.get('product'))); | |
464 | } else if (nosubscription || test) { | |
465 | addGood(Ext.String.format(gettext('You get updates for {0}'), vm.get('product'))); | |
466 | } | |
467 | ||
468 | if (wrongSuites) { | |
96ecd62a | 469 | addWarn(gettext('Some suites are misconfigured')); |
5e0cecb7 DC |
470 | } |
471 | ||
f59d1076 | 472 | if (!activeSubscription && enterprise) { |
5e0cecb7 DC |
473 | addWarn(gettext('The enterprise repository is enabled, but there is no active subscription!')); |
474 | } | |
475 | ||
476 | if (nosubscription) { | |
477 | addWarn(gettext('The no-subscription repository is not recommended for production use!')); | |
478 | } | |
479 | ||
480 | if (test) { | |
96ecd62a | 481 | addWarn(gettext('The test repository may pull in unstable updates and is not recommended for production use!')); |
5e0cecb7 DC |
482 | } |
483 | ||
484 | if (errors.length > 0) { | |
4227a557 | 485 | text = gettext('Fatal parsing error for at least one repository'); |
f59d1076 DC |
486 | } |
487 | ||
488 | let iconCls = Proxmox.Utils.get_health_icon(status, true); | |
489 | ||
490 | vm.set('state', { | |
491 | iconCls, | |
492 | text, | |
493 | }); | |
003c4982 DC |
494 | }, |
495 | }, | |
496 | ||
24313a9d FE |
497 | viewModel: { |
498 | data: { | |
3fc020f4 | 499 | product: 'Proxmox VE', // default |
5e0cecb7 | 500 | errors: [], |
f59d1076 | 501 | suitesWarning: false, |
24313a9d FE |
502 | subscriptionActive: '', |
503 | noSubscriptionRepo: '', | |
504 | enterpriseRepo: '', | |
f59d1076 | 505 | testRepo: '', |
003c4982 | 506 | selectionenabled: false, |
f59d1076 | 507 | state: {}, |
24313a9d FE |
508 | }, |
509 | formulas: { | |
003c4982 DC |
510 | enableButtonText: (get) => get('selectionenabled') |
511 | ? gettext('Disable') : gettext('Enable'), | |
24313a9d | 512 | }, |
5e0cecb7 DC |
513 | stores: { |
514 | errorstore: { | |
515 | fields: ['status', 'message'], | |
516 | }, | |
517 | }, | |
24313a9d FE |
518 | }, |
519 | ||
82071150 DC |
520 | scrollable: true, |
521 | layout: { | |
522 | type: 'vbox', | |
523 | align: 'stretch', | |
524 | }, | |
525 | ||
24313a9d FE |
526 | items: [ |
527 | { | |
f59d1076 DC |
528 | xtype: 'panel', |
529 | border: false, | |
530 | layout: { | |
531 | type: 'hbox', | |
532 | align: 'stretch', | |
24313a9d | 533 | }, |
5e0cecb7 | 534 | height: 200, |
f59d1076 DC |
535 | title: gettext('Status'), |
536 | items: [ | |
537 | { | |
538 | xtype: 'box', | |
f411afb4 | 539 | flex: 2, |
f59d1076 DC |
540 | margin: 10, |
541 | data: { | |
542 | iconCls: Proxmox.Utils.get_health_icon(undefined, true), | |
543 | text: '', | |
544 | }, | |
545 | bind: { | |
546 | data: '{state}', | |
547 | }, | |
548 | tpl: [ | |
f411afb4 | 549 | '<center class="centered-flex-column" style="font-size:15px;line-height: 25px;">', |
f59d1076 | 550 | '<i class="fa fa-4x {iconCls}"></i>', |
f59d1076 DC |
551 | '{text}', |
552 | '</center>', | |
553 | ], | |
554 | }, | |
555 | { | |
556 | xtype: 'proxmoxNodeAPTRepositoriesErrors', | |
557 | name: 'repositoriesErrors', | |
f411afb4 | 558 | flex: 7, |
f59d1076 DC |
559 | margin: 10, |
560 | bind: { | |
5e0cecb7 | 561 | store: '{errorstore}', |
f59d1076 DC |
562 | }, |
563 | }, | |
564 | ], | |
24313a9d FE |
565 | }, |
566 | { | |
567 | xtype: 'proxmoxNodeAPTRepositoriesGrid', | |
568 | name: 'repositoriesGrid', | |
f59d1076 | 569 | flex: 1, |
24313a9d FE |
570 | cbind: { |
571 | nodename: '{nodename}', | |
5e76f730 | 572 | onlineHelp: '{onlineHelp}', |
24313a9d FE |
573 | }, |
574 | majorUpgradeAllowed: false, // TODO get release information from an API call? | |
003c4982 DC |
575 | listeners: { |
576 | selectionchange: 'selectionChange', | |
bb64cd03 | 577 | }, |
24313a9d FE |
578 | }, |
579 | ], | |
580 | ||
581 | check_subscription: function() { | |
582 | let me = this; | |
583 | let vm = me.getViewModel(); | |
584 | ||
585 | Proxmox.Utils.API2Request({ | |
586 | url: `/nodes/${me.nodename}/subscription`, | |
587 | method: 'GET', | |
af48de6b | 588 | failure: (response, opts) => Ext.Msg.alert(gettext('Error'), response.htmlStatus), |
24313a9d FE |
589 | success: function(response, opts) { |
590 | const res = response.result; | |
af48de6b | 591 | const subscription = !(!res || !res.data || res.data.status.toLowerCase() !== 'active'); |
24313a9d | 592 | vm.set('subscriptionActive', subscription); |
f59d1076 | 593 | me.getController().updateState(); |
24313a9d FE |
594 | }, |
595 | }); | |
596 | }, | |
597 | ||
598 | updateStandardRepos: function(standardRepos) { | |
599 | let me = this; | |
600 | let vm = me.getViewModel(); | |
601 | ||
faacb77f | 602 | let addButton = me.down('button[name=addRepo]'); |
d76eedb4 | 603 | |
faacb77f | 604 | addButton.repoInfo = []; |
24313a9d FE |
605 | for (const standardRepo of standardRepos) { |
606 | const handle = standardRepo.handle; | |
607 | const status = standardRepo.status; | |
608 | ||
609 | if (handle === "enterprise") { | |
610 | vm.set('enterpriseRepo', status); | |
611 | } else if (handle === "no-subscription") { | |
612 | vm.set('noSubscriptionRepo', status); | |
f59d1076 DC |
613 | } else if (handle === 'test') { |
614 | vm.set('testRepo', status); | |
24313a9d | 615 | } |
f59d1076 | 616 | me.getController().updateState(); |
d76eedb4 | 617 | |
21860ea4 FE |
618 | addButton.repoInfo.push(standardRepo); |
619 | addButton.digest = me.digest; | |
24313a9d | 620 | } |
21860ea4 FE |
621 | |
622 | addButton.setDisabled(false); | |
24313a9d FE |
623 | }, |
624 | ||
625 | reload: function() { | |
626 | let me = this; | |
627 | let vm = me.getViewModel(); | |
628 | let repoGrid = me.down('proxmoxNodeAPTRepositoriesGrid'); | |
24313a9d FE |
629 | |
630 | me.store.load(function(records, operation, success) { | |
631 | let gridData = []; | |
632 | let errors = []; | |
633 | let digest; | |
f59d1076 | 634 | let suitesWarning = false; |
24313a9d FE |
635 | |
636 | if (success && records.length > 0) { | |
637 | let data = records[0].data; | |
638 | let files = data.files; | |
639 | errors = data.errors; | |
640 | digest = data.digest; | |
641 | ||
e71fc6e4 DC |
642 | let infos = {}; |
643 | for (const info of data.infos) { | |
644 | let path = info.path; | |
645 | let idx = info.index; | |
646 | ||
647 | if (!infos[path]) { | |
648 | infos[path] = {}; | |
649 | } | |
650 | if (!infos[path][idx]) { | |
651 | infos[path][idx] = { | |
652 | origin: '', | |
653 | warnings: [], | |
654 | }; | |
655 | } | |
656 | ||
657 | if (info.kind === 'origin') { | |
658 | infos[path][idx].origin = info.message; | |
659 | } else if (info.kind === 'warning' || | |
660 | (info.kind === 'ignore-pre-upgrade-warning' && !repoGrid.majorUpgradeAllowed) | |
661 | ) { | |
662 | infos[path][idx].warnings.push(info); | |
663 | } else { | |
664 | throw 'unknown info'; | |
665 | } | |
666 | } | |
667 | ||
668 | ||
24313a9d FE |
669 | files.forEach(function(file) { |
670 | for (let n = 0; n < file.repositories.length; n++) { | |
671 | let repo = file.repositories[n]; | |
672 | repo.Path = file.path; | |
673 | repo.Index = n; | |
e71fc6e4 DC |
674 | if (infos[file.path] && infos[file.path][n]) { |
675 | repo.Origin = infos[file.path][n].origin || Proxmox.Utils.UnknownText; | |
676 | repo.warnings = infos[file.path][n].warnings || []; | |
e455399a FE |
677 | |
678 | if (repo.Enabled && repo.warnings.some(w => w.property === 'Suites')) { | |
679 | suitesWarning = true; | |
680 | } | |
e71fc6e4 | 681 | } |
24313a9d FE |
682 | gridData.push(repo); |
683 | } | |
684 | }); | |
685 | ||
24313a9d FE |
686 | repoGrid.store.loadData(gridData); |
687 | ||
688 | me.updateStandardRepos(data['standard-repos']); | |
689 | } | |
690 | ||
691 | me.digest = digest; | |
692 | ||
5e0cecb7 | 693 | vm.set('errors', errors); |
f59d1076 DC |
694 | vm.set('suitesWarning', suitesWarning); |
695 | me.getController().updateState(); | |
24313a9d FE |
696 | }); |
697 | ||
698 | me.check_subscription(); | |
699 | }, | |
700 | ||
701 | listeners: { | |
702 | activate: function() { | |
703 | let me = this; | |
704 | me.reload(); | |
705 | }, | |
706 | }, | |
707 | ||
708 | initComponent: function() { | |
709 | let me = this; | |
710 | ||
711 | if (!me.nodename) { | |
712 | throw "no node name specified"; | |
713 | } | |
714 | ||
715 | let store = Ext.create('Ext.data.Store', { | |
716 | proxy: { | |
717 | type: 'proxmox', | |
718 | url: `/api2/json/nodes/${me.nodename}/apt/repositories`, | |
719 | }, | |
720 | }); | |
721 | ||
722 | Ext.apply(me, { store: store }); | |
723 | ||
724 | Proxmox.Utils.monStoreErrors(me, me.store, true); | |
725 | ||
726 | me.callParent(); | |
3fc020f4 TL |
727 | |
728 | me.getViewModel().set('product', me.product); | |
24313a9d FE |
729 | }, |
730 | }); |