]>
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'), | |
26 | ||
27 | initComponent: function() { | |
28 | let me = this; | |
29 | ||
30 | if (!me.repoInfo || me.repoInfo.length === 0) { | |
31 | throw "repository information not initialized"; | |
32 | } | |
33 | ||
34 | let description = Ext.create('Ext.form.field.Display', { | |
35 | fieldLabel: gettext('Description'), | |
36 | name: 'description', | |
37 | }); | |
38 | ||
39 | let status = Ext.create('Ext.form.field.Display', { | |
40 | fieldLabel: gettext('Status'), | |
41 | name: 'status', | |
42 | renderer: function(value) { | |
43 | let statusText = gettext('Not yet configured'); | |
44 | if (value !== '') { | |
45 | statusText = Ext.String.format( | |
46 | '{0}: {1}', | |
47 | gettext('Configured'), | |
48 | value ? gettext('enabled') : gettext('disabled'), | |
49 | ); | |
50 | } | |
51 | ||
52 | return statusText; | |
53 | }, | |
54 | }); | |
55 | ||
56 | let repoSelector = Ext.create('Proxmox.form.KVComboBox', { | |
57 | fieldLabel: gettext('Repository'), | |
58 | xtype: 'proxmoxKVComboBox', | |
59 | name: 'handle', | |
60 | allowBlank: false, | |
61 | comboItems: me.repoInfo.map(info => [info.handle, info.name]), | |
62 | isValid: function() { | |
63 | const handle = this.value; | |
64 | ||
65 | if (!handle) { | |
66 | return false; | |
67 | } | |
68 | ||
69 | const info = me.repoInfo.find(elem => elem.handle === handle); | |
70 | ||
71 | if (!info) { | |
72 | return false; | |
73 | } | |
74 | ||
75 | // not yet configured | |
76 | return info.status === undefined || info.status === null; | |
77 | }, | |
78 | listeners: { | |
79 | change: function(f, value) { | |
80 | const info = me.repoInfo.find(elem => elem.handle === value); | |
81 | description.setValue(info.description); | |
82 | status.setValue(info.status); | |
83 | }, | |
84 | }, | |
85 | }); | |
86 | ||
87 | repoSelector.setValue(me.repoInfo[0].handle); | |
88 | ||
89 | let items = [ | |
90 | repoSelector, | |
91 | description, | |
92 | status, | |
93 | ]; | |
94 | ||
95 | Ext.apply(me, { | |
96 | items: items, | |
97 | repoSelector: repoSelector, | |
98 | }); | |
99 | ||
100 | me.callParent(); | |
101 | }, | |
102 | }); | |
103 | ||
24313a9d FE |
104 | Ext.define('Proxmox.node.APTRepositoriesErrors', { |
105 | extend: 'Ext.grid.GridPanel', | |
106 | ||
107 | xtype: 'proxmoxNodeAPTRepositoriesErrors', | |
108 | ||
109 | title: gettext('Errors'), | |
110 | ||
111 | store: {}, | |
112 | ||
113 | viewConfig: { | |
114 | stripeRows: false, | |
115 | getRowClass: () => 'proxmox-invalid-row', | |
116 | }, | |
117 | ||
118 | columns: [ | |
119 | { | |
120 | header: gettext('File'), | |
121 | dataIndex: 'path', | |
af48de6b | 122 | renderer: value => `<i class='pve-grid-fa fa fa-fw fa-exclamation-triangle'></i>${value}`, |
24313a9d FE |
123 | width: 350, |
124 | }, | |
125 | { | |
126 | header: gettext('Error'), | |
127 | dataIndex: 'error', | |
128 | flex: 1, | |
129 | }, | |
130 | ], | |
131 | }); | |
132 | ||
133 | Ext.define('Proxmox.node.APTRepositoriesGrid', { | |
134 | extend: 'Ext.grid.GridPanel', | |
24313a9d FE |
135 | xtype: 'proxmoxNodeAPTRepositoriesGrid', |
136 | ||
137 | title: gettext('APT Repositories'), | |
138 | ||
994fe897 TL |
139 | cls: 'proxmox-apt-repos', // to allow applying styling to general components with local effect |
140 | ||
24313a9d FE |
141 | tbar: [ |
142 | { | |
143 | text: gettext('Reload'), | |
144 | iconCls: 'fa fa-refresh', | |
145 | handler: function() { | |
146 | let me = this; | |
147 | me.up('proxmoxNodeAPTRepositories').reload(); | |
148 | }, | |
149 | }, | |
d76eedb4 FE |
150 | { |
151 | text: gettext('Add'), | |
21860ea4 FE |
152 | id: 'addButton', |
153 | disabled: true, | |
154 | repoInfo: undefined, | |
155 | handler: function(button, event, record) { | |
156 | Proxmox.Utils.checked_command(() => { | |
157 | let me = this; | |
158 | let panel = me.up('proxmoxNodeAPTRepositories'); | |
159 | ||
160 | let extraParams = {}; | |
161 | if (panel.digest !== undefined) { | |
162 | extraParams.digest = panel.digest; | |
163 | } | |
164 | ||
165 | Ext.create('Proxmox.window.APTRepositoryAdd', { | |
166 | repoInfo: me.repoInfo, | |
167 | url: `/api2/json/nodes/${panel.nodename}/apt/repositories`, | |
168 | method: 'PUT', | |
169 | extraRequestParams: extraParams, | |
170 | listeners: { | |
171 | destroy: function() { | |
172 | panel.reload(); | |
173 | }, | |
174 | }, | |
175 | }).show(); | |
176 | }); | |
d76eedb4 FE |
177 | }, |
178 | }, | |
af48de6b | 179 | '-', |
d76eedb4 FE |
180 | { |
181 | xtype: 'proxmoxButton', | |
bb64cd03 TL |
182 | text: gettext('Enable'), |
183 | defaultText: gettext('Enable'), | |
184 | altText: gettext('Disable'), | |
185 | id: 'repoEnableButton', | |
d76eedb4 FE |
186 | disabled: true, |
187 | handler: function(button, event, record) { | |
188 | let me = this; | |
189 | let panel = me.up('proxmoxNodeAPTRepositories'); | |
190 | ||
191 | let params = { | |
192 | path: record.data.Path, | |
193 | index: record.data.Index, | |
194 | enabled: record.data.Enabled ? 0 : 1, // invert | |
195 | }; | |
196 | ||
197 | if (panel.digest !== undefined) { | |
198 | params.digest = panel.digest; | |
199 | } | |
200 | ||
201 | Proxmox.Utils.API2Request({ | |
202 | url: `/nodes/${panel.nodename}/apt/repositories`, | |
203 | method: 'POST', | |
204 | params: params, | |
205 | failure: function(response, opts) { | |
206 | Ext.Msg.alert(gettext('Error'), response.htmlStatus); | |
207 | panel.reload(); | |
208 | }, | |
209 | success: function(response, opts) { | |
210 | panel.reload(); | |
211 | }, | |
212 | }); | |
213 | }, | |
bb64cd03 TL |
214 | listeners: { |
215 | render: function(btn) { | |
216 | // HACK: calculate the max button width on first render to avoid toolbar glitches | |
217 | let defSize = btn.getSize().width; | |
218 | ||
219 | btn.setText(btn.altText); | |
220 | let altSize = btn.getSize().width; | |
221 | ||
222 | btn.setText(btn.defaultText); | |
223 | btn.setSize({ width: altSize > defSize ? altSize : defSize }); | |
224 | }, | |
225 | }, | |
d76eedb4 | 226 | }, |
24313a9d FE |
227 | ], |
228 | ||
229 | sortableColumns: false, | |
230 | ||
231 | columns: [ | |
232 | { | |
03c4c65b | 233 | xtype: 'checkcolumn', |
24313a9d FE |
234 | header: gettext('Enabled'), |
235 | dataIndex: 'Enabled', | |
03c4c65b TL |
236 | listeners: { |
237 | beforecheckchange: () => false, // veto, we don't want to allow inline change - to subtle | |
238 | }, | |
24313a9d FE |
239 | width: 90, |
240 | }, | |
241 | { | |
242 | header: gettext('Types'), | |
243 | dataIndex: 'Types', | |
244 | renderer: function(types, cell, record) { | |
245 | return types.join(' '); | |
246 | }, | |
247 | width: 100, | |
248 | }, | |
249 | { | |
250 | header: gettext('URIs'), | |
251 | dataIndex: 'URIs', | |
252 | renderer: function(uris, cell, record) { | |
253 | return uris.join(' '); | |
254 | }, | |
255 | width: 350, | |
256 | }, | |
257 | { | |
258 | header: gettext('Suites'), | |
259 | dataIndex: 'Suites', | |
260 | renderer: function(suites, cell, record) { | |
261 | return suites.join(' '); | |
262 | }, | |
263 | width: 130, | |
264 | }, | |
265 | { | |
266 | header: gettext('Components'), | |
267 | dataIndex: 'Components', | |
268 | renderer: function(components, cell, record) { | |
269 | return components.join(' '); | |
270 | }, | |
271 | width: 170, | |
272 | }, | |
273 | { | |
274 | header: gettext('Options'), | |
275 | dataIndex: 'Options', | |
276 | renderer: function(options, cell, record) { | |
277 | if (!options) { | |
278 | return ''; | |
279 | } | |
280 | ||
281 | let filetype = record.data.FileType; | |
282 | let text = ''; | |
283 | ||
284 | options.forEach(function(option) { | |
285 | let key = option.Key; | |
286 | if (filetype === 'list') { | |
287 | let values = option.Values.join(','); | |
288 | text += `${key}=${values} `; | |
289 | } else if (filetype === 'sources') { | |
290 | let values = option.Values.join(' '); | |
291 | text += `${key}: ${values}<br>`; | |
292 | } else { | |
293 | throw "unkown file type"; | |
294 | } | |
295 | }); | |
296 | return text; | |
297 | }, | |
298 | flex: 1, | |
299 | }, | |
03c4c65b | 300 | { |
d91987a5 FE |
301 | header: gettext('Origin'), |
302 | dataIndex: 'Origin', | |
036f48c1 TL |
303 | width: 120, |
304 | renderer: (value, meta, rec) => { | |
305 | let cls = 'fa fa-fw fa-question-circle-o'; | |
306 | if (value.match(/^\s*Proxmox\s*$/i)) { | |
307 | cls = 'pmx-itype-icon pmx-itype-icon-proxmox-x'; | |
308 | } else if (value.match(/^\s*Debian\s*$/i)) { | |
309 | cls = 'pmx-itype-icon pmx-itype-icon-debian-swirl'; | |
310 | } | |
311 | return `<i class='${cls}'></i> ${value}`; | |
312 | }, | |
03c4c65b | 313 | }, |
24313a9d FE |
314 | { |
315 | header: gettext('Comment'), | |
316 | dataIndex: 'Comment', | |
317 | flex: 2, | |
318 | }, | |
319 | ], | |
320 | ||
321 | addAdditionalInfos: function(gridData, infos) { | |
322 | let me = this; | |
323 | ||
324 | let warnings = {}; | |
d91987a5 | 325 | let origins = {}; |
24313a9d FE |
326 | |
327 | let addLine = function(obj, key, line) { | |
328 | if (obj[key]) { | |
329 | obj[key] += "\n"; | |
330 | obj[key] += line; | |
331 | } else { | |
332 | obj[key] = line; | |
333 | } | |
334 | }; | |
335 | ||
336 | for (const info of infos) { | |
337 | const key = `${info.path}:${info.index}`; | |
338 | if (info.kind === 'warning' || | |
af48de6b TL |
339 | (info.kind === 'ignore-pre-upgrade-warning' && !me.majorUpgradeAllowed) |
340 | ) { | |
24313a9d | 341 | addLine(warnings, key, gettext('Warning') + ": " + info.message); |
d91987a5 FE |
342 | } else if (info.kind === 'origin') { |
343 | origins[key] = info.message; | |
24313a9d FE |
344 | } |
345 | } | |
346 | ||
347 | gridData.forEach(function(record) { | |
348 | const key = `${record.Path}:${record.Index}`; | |
d91987a5 | 349 | record.Origin = origins[key]; |
24313a9d FE |
350 | }); |
351 | ||
352 | me.rowBodyFeature.getAdditionalData = function(innerData, rowIndex, record, orig) { | |
353 | let headerCt = this.view.headerCt; | |
354 | let colspan = headerCt.getColumnCount(); | |
355 | ||
356 | const key = `${innerData.Path}:${innerData.Index}`; | |
357 | const warning_text = warnings[key]; | |
358 | ||
359 | return { | |
360 | rowBody: '<div style="color: red; white-space: pre-line">' + | |
361 | Ext.String.htmlEncode(warning_text) + '</div>', | |
362 | rowBodyCls: warning_text ? '' : Ext.baseCSSPrefix + 'grid-row-body-hidden', | |
363 | rowBodyColspan: colspan, | |
364 | }; | |
365 | }; | |
366 | }, | |
367 | ||
368 | initComponent: function() { | |
369 | let me = this; | |
370 | ||
371 | if (!me.nodename) { | |
372 | throw "no node name specified"; | |
373 | } | |
374 | ||
375 | let store = Ext.create('Ext.data.Store', { | |
376 | model: 'apt-repolist', | |
377 | groupField: 'Path', | |
378 | sorters: [ | |
379 | { | |
380 | property: 'Index', | |
381 | direction: 'ASC', | |
382 | }, | |
383 | ], | |
384 | }); | |
385 | ||
386 | let rowBodyFeature = Ext.create('Ext.grid.feature.RowBody', {}); | |
387 | ||
388 | let groupingFeature = Ext.create('Ext.grid.feature.Grouping', { | |
389 | groupHeaderTpl: '{[ "File: " + values.name ]} ({rows.length} ' + | |
390 | 'repositor{[values.rows.length > 1 ? "ies" : "y"]})', | |
391 | enableGroupingMenu: false, | |
392 | }); | |
393 | ||
394 | let sm = Ext.create('Ext.selection.RowModel', {}); | |
395 | ||
396 | Ext.apply(me, { | |
397 | store: store, | |
398 | selModel: sm, | |
399 | rowBodyFeature: rowBodyFeature, | |
400 | features: [groupingFeature, rowBodyFeature], | |
401 | }); | |
402 | ||
403 | me.callParent(); | |
404 | }, | |
bb64cd03 TL |
405 | |
406 | listeners: { | |
407 | selectionchange: function() { | |
408 | let me = this; | |
409 | ||
410 | if (me.onSelectionChange) { | |
411 | let sm = me.getSelectionModel(); | |
412 | let rec = sm.getSelection()[0]; | |
413 | ||
414 | me.onSelectionChange(rec, sm); | |
415 | } | |
416 | }, | |
417 | }, | |
24313a9d FE |
418 | }); |
419 | ||
420 | Ext.define('Proxmox.node.APTRepositories', { | |
421 | extend: 'Ext.panel.Panel', | |
24313a9d FE |
422 | xtype: 'proxmoxNodeAPTRepositories', |
423 | mixins: ['Proxmox.Mixin.CBind'], | |
424 | ||
425 | digest: undefined, | |
426 | ||
3fc020f4 TL |
427 | product: 'Proxmox VE', // default |
428 | ||
24313a9d FE |
429 | viewModel: { |
430 | data: { | |
3fc020f4 | 431 | product: 'Proxmox VE', // default |
24313a9d FE |
432 | errorCount: 0, |
433 | subscriptionActive: '', | |
434 | noSubscriptionRepo: '', | |
435 | enterpriseRepo: '', | |
436 | }, | |
437 | formulas: { | |
438 | noErrors: (get) => get('errorCount') === 0, | |
439 | mainWarning: function(get) { | |
440 | // Not yet initialized | |
441 | if (get('subscriptionActive') === '' || | |
442 | get('enterpriseRepo') === '') { | |
443 | return ''; | |
444 | } | |
445 | ||
3fc020f4 TL |
446 | let icon = `<i class='fa fa-fw fa-exclamation-triangle critical'></i>`; |
447 | let fmt = (msg) => `<div class="black">${icon}${gettext('Warning')}: ${msg}</div>`; | |
24313a9d FE |
448 | |
449 | if (!get('subscriptionActive') && get('enterpriseRepo')) { | |
3fc020f4 | 450 | return fmt(gettext('The enterprise repository is enabled, but there is no active subscription!')); |
24313a9d FE |
451 | } |
452 | ||
453 | if (get('noSubscriptionRepo')) { | |
3fc020f4 | 454 | return fmt(gettext('The no-subscription repository is not recommended for production use!')); |
24313a9d FE |
455 | } |
456 | ||
457 | if (!get('enterpriseRepo') && !get('noSubscriptionRepo')) { | |
3fc020f4 TL |
458 | let msg = Ext.String.format(gettext('No {0} repository is enabled!'), get('product')); |
459 | return fmt(msg); | |
24313a9d FE |
460 | } |
461 | ||
462 | return ''; | |
463 | }, | |
464 | }, | |
465 | }, | |
466 | ||
467 | items: [ | |
468 | { | |
469 | title: gettext('Warning'), | |
470 | name: 'repositoriesMainWarning', | |
471 | xtype: 'panel', | |
472 | bind: { | |
473 | title: '{mainWarning}', | |
474 | hidden: '{!mainWarning}', | |
475 | }, | |
476 | }, | |
477 | { | |
478 | xtype: 'proxmoxNodeAPTRepositoriesErrors', | |
479 | name: 'repositoriesErrors', | |
480 | hidden: true, | |
481 | bind: { | |
482 | hidden: '{noErrors}', | |
483 | }, | |
484 | }, | |
485 | { | |
486 | xtype: 'proxmoxNodeAPTRepositoriesGrid', | |
487 | name: 'repositoriesGrid', | |
488 | cbind: { | |
489 | nodename: '{nodename}', | |
490 | }, | |
491 | majorUpgradeAllowed: false, // TODO get release information from an API call? | |
bb64cd03 TL |
492 | onSelectionChange: function(rec, sm) { |
493 | let me = this; | |
494 | if (rec) { | |
495 | let btn = me.up('proxmoxNodeAPTRepositories').down('#repoEnableButton'); | |
496 | btn.setText(rec.get('Enabled') ? gettext('Disable') : gettext('Enable')); | |
497 | } | |
498 | }, | |
24313a9d FE |
499 | }, |
500 | ], | |
501 | ||
502 | check_subscription: function() { | |
503 | let me = this; | |
504 | let vm = me.getViewModel(); | |
505 | ||
506 | Proxmox.Utils.API2Request({ | |
507 | url: `/nodes/${me.nodename}/subscription`, | |
508 | method: 'GET', | |
af48de6b | 509 | failure: (response, opts) => Ext.Msg.alert(gettext('Error'), response.htmlStatus), |
24313a9d FE |
510 | success: function(response, opts) { |
511 | const res = response.result; | |
af48de6b | 512 | const subscription = !(!res || !res.data || res.data.status.toLowerCase() !== 'active'); |
24313a9d FE |
513 | vm.set('subscriptionActive', subscription); |
514 | }, | |
515 | }); | |
516 | }, | |
517 | ||
518 | updateStandardRepos: function(standardRepos) { | |
519 | let me = this; | |
520 | let vm = me.getViewModel(); | |
521 | ||
21860ea4 FE |
522 | let addButton = me.down('#addButton'); |
523 | addButton.repoInfo = []; | |
d76eedb4 | 524 | |
24313a9d FE |
525 | for (const standardRepo of standardRepos) { |
526 | const handle = standardRepo.handle; | |
527 | const status = standardRepo.status; | |
528 | ||
529 | if (handle === "enterprise") { | |
530 | vm.set('enterpriseRepo', status); | |
531 | } else if (handle === "no-subscription") { | |
532 | vm.set('noSubscriptionRepo', status); | |
533 | } | |
d76eedb4 | 534 | |
21860ea4 FE |
535 | addButton.repoInfo.push(standardRepo); |
536 | addButton.digest = me.digest; | |
24313a9d | 537 | } |
21860ea4 FE |
538 | |
539 | addButton.setDisabled(false); | |
24313a9d FE |
540 | }, |
541 | ||
542 | reload: function() { | |
543 | let me = this; | |
544 | let vm = me.getViewModel(); | |
545 | let repoGrid = me.down('proxmoxNodeAPTRepositoriesGrid'); | |
546 | let errorGrid = me.down('proxmoxNodeAPTRepositoriesErrors'); | |
547 | ||
548 | me.store.load(function(records, operation, success) { | |
549 | let gridData = []; | |
550 | let errors = []; | |
551 | let digest; | |
552 | ||
553 | if (success && records.length > 0) { | |
554 | let data = records[0].data; | |
555 | let files = data.files; | |
556 | errors = data.errors; | |
557 | digest = data.digest; | |
558 | ||
559 | files.forEach(function(file) { | |
560 | for (let n = 0; n < file.repositories.length; n++) { | |
561 | let repo = file.repositories[n]; | |
562 | repo.Path = file.path; | |
563 | repo.Index = n; | |
564 | gridData.push(repo); | |
565 | } | |
566 | }); | |
567 | ||
568 | repoGrid.addAdditionalInfos(gridData, data.infos); | |
569 | repoGrid.store.loadData(gridData); | |
570 | ||
571 | me.updateStandardRepos(data['standard-repos']); | |
572 | } | |
573 | ||
574 | me.digest = digest; | |
575 | ||
576 | vm.set('errorCount', errors.length); | |
577 | errorGrid.store.loadData(errors); | |
578 | }); | |
579 | ||
580 | me.check_subscription(); | |
581 | }, | |
582 | ||
583 | listeners: { | |
584 | activate: function() { | |
585 | let me = this; | |
586 | me.reload(); | |
587 | }, | |
588 | }, | |
589 | ||
590 | initComponent: function() { | |
591 | let me = this; | |
592 | ||
593 | if (!me.nodename) { | |
594 | throw "no node name specified"; | |
595 | } | |
596 | ||
597 | let store = Ext.create('Ext.data.Store', { | |
598 | proxy: { | |
599 | type: 'proxmox', | |
600 | url: `/api2/json/nodes/${me.nodename}/apt/repositories`, | |
601 | }, | |
602 | }); | |
603 | ||
604 | Ext.apply(me, { store: store }); | |
605 | ||
606 | Proxmox.Utils.monStoreErrors(me, me.store, true); | |
607 | ||
608 | me.callParent(); | |
3fc020f4 TL |
609 | |
610 | me.getViewModel().set('product', me.product); | |
24313a9d FE |
611 | }, |
612 | }); |