]>
git.proxmox.com Git - proxmox-widget-toolkit.git/blob - src/node/APTRepositories.js
4288e1a5d821227808129d2815e3cc7c81096102
1 Ext
.define('apt-repolist', {
2 extend
: 'Ext.data.Model',
18 Ext
.define('Proxmox.window.APTRepositoryAdd', {
19 extend
: 'Proxmox.window.Edit',
20 alias
: 'widget.pmxAPTRepositoryAdd',
25 subject
: gettext('Repository'),
28 initComponent: function() {
31 if (!me
.repoInfo
|| me
.repoInfo
.length
=== 0) {
32 throw "repository information not initialized";
35 let description
= Ext
.create('Ext.form.field.Display', {
36 fieldLabel
: gettext('Description'),
40 let status
= Ext
.create('Ext.form.field.Display', {
41 fieldLabel
: gettext('Status'),
43 renderer: function(value
) {
44 let statusText
= gettext('Not yet configured');
46 statusText
= Ext
.String
.format(
48 gettext('Configured'),
49 value
? gettext('enabled') : gettext('disabled'),
57 let repoSelector
= Ext
.create('Proxmox.form.KVComboBox', {
58 fieldLabel
: gettext('Repository'),
59 xtype
: 'proxmoxKVComboBox',
62 comboItems
: me
.repoInfo
.map(info
=> [info
.handle
, info
.name
]),
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
);
68 if (!valid
|| !handle
) {
72 const info
= me
.repoInfo
.find(elem
=> elem
.handle
=== handle
);
78 return Ext
.String
.format(gettext('{0} is already configured'), renderedValue
);
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
);
91 repoSelector
.setValue(me
.repoInfo
[0].handle
);
99 repoSelector
: repoSelector
,
106 Ext
.define('Proxmox.node.APTRepositoriesErrors', {
107 extend
: 'Ext.grid.GridPanel',
109 xtype
: 'proxmoxNodeAPTRepositoriesErrors',
117 getRowClass
: (record
) => {
118 switch (record
.data
.status
) {
119 case 'warning': return 'proxmox-warning-row';
120 case 'critical': return 'proxmox-invalid-row';
131 renderer
: (value
) => `<i class="fa fa-fw ${Proxmox.Utils.get_health_icon(value, true)}"></i>`,
135 dataIndex
: 'message',
141 Ext
.define('Proxmox.node.APTRepositoriesGrid', {
142 extend
: 'Ext.grid.GridPanel',
143 xtype
: 'proxmoxNodeAPTRepositoriesGrid',
145 title
: gettext('APT Repositories'),
147 cls
: 'proxmox-apt-repos', // to allow applying styling to general components with local effect
153 text
: gettext('Reload'),
154 iconCls
: 'fa fa-refresh',
155 handler: function() {
157 me
.up('proxmoxNodeAPTRepositories').reload();
161 text
: gettext('Add'),
165 handler: function(button
, event
, record
) {
166 Proxmox
.Utils
.checked_command(() => {
168 let panel
= me
.up('proxmoxNodeAPTRepositories');
170 let extraParams
= {};
171 if (panel
.digest
!== undefined) {
172 extraParams
.digest
= panel
.digest
;
175 Ext
.create('Proxmox.window.APTRepositoryAdd', {
176 repoInfo
: me
.repoInfo
,
177 url
: `/api2/extjs/nodes/${panel.nodename}/apt/repositories`,
179 extraRequestParams
: extraParams
,
181 destroy: function() {
191 xtype
: 'proxmoxButton',
192 text
: gettext('Enable'),
193 defaultText
: gettext('Enable'),
194 altText
: gettext('Disable'),
198 text
: '{enableButtonText}',
200 handler: function(button
, event
, record
) {
202 let panel
= me
.up('proxmoxNodeAPTRepositories');
205 path
: record
.data
.Path
,
206 index
: record
.data
.Index
,
207 enabled
: record
.data
.Enabled
? 0 : 1, // invert
210 if (panel
.digest
!== undefined) {
211 params
.digest
= panel
.digest
;
214 Proxmox
.Utils
.API2Request({
215 url
: `/nodes/${panel.nodename}/apt/repositories`,
218 failure: function(response
, opts
) {
219 Ext
.Msg
.alert(gettext('Error'), response
.htmlStatus
);
222 success: function(response
, opts
) {
228 render: function(btn
) {
229 // HACK: calculate the max button width on first render to avoid toolbar glitches
230 let defSize
= btn
.getSize().width
;
232 btn
.setText(btn
.altText
);
233 let altSize
= btn
.getSize().width
;
235 btn
.setText(btn
.defaultText
);
236 btn
.setSize({ width
: altSize
> defSize
? altSize
: defSize
});
242 sortableColumns
: false,
245 getRowClass
: (record
, index
) => record
.get('Enabled') ? '' : 'proxmox-disabled-row',
250 xtype
: 'checkcolumn',
251 header
: gettext('Enabled'),
252 dataIndex
: 'Enabled',
254 beforecheckchange
: () => false, // veto, we don't want to allow inline change - to subtle
259 header
: gettext('Types'),
261 renderer: function(types
, cell
, record
) {
262 return types
.join(' ');
267 header
: gettext('URIs'),
269 renderer: function(uris
, cell
, record
) {
270 return uris
.join(' ');
275 header
: gettext('Suites'),
277 renderer: function(suites
, metaData
, record
) {
279 if (record
.data
.warnings
&& record
.data
.warnings
.length
> 0) {
280 let txt
= [gettext('Warning')];
281 record
.data
.warnings
.forEach((warning
) => {
282 if (warning
.property
=== 'Suites') {
283 txt
.push(warning
.message
);
286 metaData
.tdAttr
= `data-qtip="${Ext.htmlEncode(txt.join('<br>'))}"`;
287 if (record
.data
.Enabled
) {
288 metaData
.tdCls
= 'proxmox-invalid-row';
289 err
= '<i class="fa fa-fw critical fa-exclamation-circle"></i> ';
291 metaData
.tdCls
= 'proxmox-warning-row';
292 err
= '<i class="fa fa-fw warning fa-exclamation-circle"></i> ';
295 return suites
.join(' ') + err
;
300 header
: gettext('Components'),
301 dataIndex
: 'Components',
302 renderer: function(components
, metaData
, record
) {
303 if (components
=== undefined) {
307 if (components
.length
=== 1) {
308 // FIXME: this should be a flag set to the actual repsotiories, i.e., a tristate
309 // like production-ready = <yes|no|other> (Option<bool>)
310 if (components
[0].match(/\w+(-no-subscription|test)\s*$/i)) {
311 metaData
.tdCls
= 'proxmox-warning-row';
312 err
= '<i class="fa fa-fw warning fa-exclamation-circle"></i> ';
314 let qtip
= components
[0].match(/no-subscription/)
315 ? gettext('The no-subscription repository is NOT production-ready')
316 : gettext('The test repository may contain unstable updates')
318 metaData
.tdAttr
= `data-qtip="${Ext.htmlEncode(qtip)}"`;
321 return components
.join(' ') + err
;
326 header
: gettext('Options'),
327 dataIndex
: 'Options',
328 renderer: function(options
, cell
, record
) {
333 let filetype
= record
.data
.FileType
;
336 options
.forEach(function(option
) {
337 let key
= option
.Key
;
338 if (filetype
=== 'list') {
339 let values
= option
.Values
.join(',');
340 text
+= `${key}=${values} `;
341 } else if (filetype
=== 'sources') {
342 let values
= option
.Values
.join(' ');
343 text
+= `${key}: ${values}<br>`;
345 throw "unkown file type";
353 header
: gettext('Origin'),
356 renderer
: (value
, meta
, rec
) => {
357 if (typeof value
!== 'string' || value
.length
=== 0) {
358 value
= gettext('Other');
360 let cls
= 'fa fa-fw fa-question-circle-o';
361 if (value
.match(/^\s*Proxmox\s*$/i)) {
362 cls
= 'pmx-itype-icon pmx-itype-icon-proxmox-x';
363 } else if (value
.match(/^\s*Debian\s*(:?Backports)?$/i)) {
364 cls
= 'pmx-itype-icon pmx-itype-icon-debian-swirl';
366 return `<i class='${cls}'></i> ${value}`;
370 header
: gettext('Comment'),
371 dataIndex
: 'Comment',
379 groupHeaderTpl
: '{[ "File: " + values.name ]} ({rows.length} repositor{[values.rows.length > 1 ? "ies" : "y"]})',
380 enableGroupingMenu
: false,
385 model
: 'apt-repolist',
395 initComponent: function() {
399 throw "no node name specified";
406 Ext
.define('Proxmox.node.APTRepositories', {
407 extend
: 'Ext.panel.Panel',
408 xtype
: 'proxmoxNodeAPTRepositories',
409 mixins
: ['Proxmox.Mixin.CBind'],
413 product
: 'Proxmox VE', // default
416 xclass
: 'Ext.app.ViewController',
418 selectionChange: function(grid
, selection
) {
420 if (!selection
|| selection
.length
< 1) {
423 let rec
= selection
[0];
424 let vm
= me
.getViewModel();
425 vm
.set('selectionenabled', rec
.get('Enabled'));
429 updateState: function() {
431 let vm
= me
.getViewModel();
433 let store
= vm
.get('errorstore');
436 let status
= 'good'; // start with best, the helper below will downgrade if needed
437 let text
= gettext('All OK, you have production-ready repositories configured!');
439 let addGood
= message
=> store
.add({ status
: 'good', message
});
440 let addWarn
= (message
, important
) => {
441 if (status
!== 'critical') {
443 text
= important
? message
: gettext('Warning');
445 store
.add({ status
: 'warning', message
});
447 let addCritical
= (message
, important
) => {
449 text
= important
? message
: gettext('Error');
450 store
.add({ status
: 'critical', message
});
453 let errors
= vm
.get('errors');
454 errors
.forEach(error
=> addCritical(`${error.path} - ${error.error}`));
456 let activeSubscription
= vm
.get('subscriptionActive');
457 let enterprise
= vm
.get('enterpriseRepo');
458 let nosubscription
= vm
.get('noSubscriptionRepo');
459 let test
= vm
.get('testRepo');
460 let wrongSuites
= vm
.get('suitesWarning');
462 if (!enterprise
&& !nosubscription
&& !test
) {
464 Ext
.String
.format(gettext('No {0} repository is enabled, you do not get any updates!'), vm
.get('product')),
466 } else if (errors
.length
> 0) {
467 // nothing extra, just avoid that we show "get updates"
468 } else if (enterprise
&& !nosubscription
&& !test
&& activeSubscription
) {
469 addGood(Ext
.String
.format(gettext('You get supported updates for {0}'), vm
.get('product')));
470 } else if (nosubscription
|| test
) {
471 addGood(Ext
.String
.format(gettext('You get updates for {0}'), vm
.get('product')));
475 addWarn(gettext('Some suites are misconfigured'));
478 if (!activeSubscription
&& enterprise
) {
479 addWarn(gettext('The enterprise repository is enabled, but there is no active subscription!'));
482 if (nosubscription
) {
483 addWarn(gettext('The no-subscription repository is not recommended for production use!'));
487 addWarn(gettext('The test repository may pull in unstable updates and is not recommended for production use!'));
490 if (errors
.length
> 0) {
491 text
= gettext('Fatal parsing error for at least one repository');
494 let iconCls
= Proxmox
.Utils
.get_health_icon(status
, true);
505 product
: 'Proxmox VE', // default
507 suitesWarning
: false,
508 subscriptionActive
: '',
509 noSubscriptionRepo
: '',
512 selectionenabled
: false,
516 enableButtonText
: (get) => get('selectionenabled')
517 ? gettext('Disable') : gettext('Enable'),
521 fields
: ['status', 'message'],
541 title
: gettext('Status'),
548 iconCls
: Proxmox
.Utils
.get_health_icon(undefined, true),
555 '<center class="centered-flex-column" style="font-size:15px;line-height: 25px;">',
556 '<i class="fa fa-4x {iconCls}"></i>',
562 xtype
: 'proxmoxNodeAPTRepositoriesErrors',
563 name
: 'repositoriesErrors',
567 store
: '{errorstore}',
573 xtype
: 'proxmoxNodeAPTRepositoriesGrid',
574 name
: 'repositoriesGrid',
577 nodename
: '{nodename}',
579 majorUpgradeAllowed
: false, // TODO get release information from an API call?
581 selectionchange
: 'selectionChange',
586 check_subscription: function() {
588 let vm
= me
.getViewModel();
590 Proxmox
.Utils
.API2Request({
591 url
: `/nodes/${me.nodename}/subscription`,
593 failure
: (response
, opts
) => Ext
.Msg
.alert(gettext('Error'), response
.htmlStatus
),
594 success: function(response
, opts
) {
595 const res
= response
.result
;
596 const subscription
= !(!res
|| !res
.data
|| res
.data
.status
.toLowerCase() !== 'active');
597 vm
.set('subscriptionActive', subscription
);
598 me
.getController().updateState();
603 updateStandardRepos: function(standardRepos
) {
605 let vm
= me
.getViewModel();
607 let addButton
= me
.down('button[name=addRepo]');
609 addButton
.repoInfo
= [];
610 for (const standardRepo
of standardRepos
) {
611 const handle
= standardRepo
.handle
;
612 const status
= standardRepo
.status
;
614 if (handle
=== "enterprise") {
615 vm
.set('enterpriseRepo', status
);
616 } else if (handle
=== "no-subscription") {
617 vm
.set('noSubscriptionRepo', status
);
618 } else if (handle
=== 'test') {
619 vm
.set('testRepo', status
);
621 me
.getController().updateState();
623 addButton
.repoInfo
.push(standardRepo
);
624 addButton
.digest
= me
.digest
;
627 addButton
.setDisabled(false);
632 let vm
= me
.getViewModel();
633 let repoGrid
= me
.down('proxmoxNodeAPTRepositoriesGrid');
635 me
.store
.load(function(records
, operation
, success
) {
639 let suitesWarning
= false;
641 if (success
&& records
.length
> 0) {
642 let data
= records
[0].data
;
643 let files
= data
.files
;
644 errors
= data
.errors
;
645 digest
= data
.digest
;
648 for (const info
of data
.infos
) {
649 let path
= info
.path
;
650 let idx
= info
.index
;
655 if (!infos
[path
][idx
]) {
662 if (info
.kind
=== 'origin') {
663 infos
[path
][idx
].origin
= info
.message
;
664 } else if (info
.kind
=== 'warning' ||
665 (info
.kind
=== 'ignore-pre-upgrade-warning' && !repoGrid
.majorUpgradeAllowed
)
667 infos
[path
][idx
].warnings
.push(info
);
669 throw 'unknown info';
674 files
.forEach(function(file
) {
675 for (let n
= 0; n
< file
.repositories
.length
; n
++) {
676 let repo
= file
.repositories
[n
];
677 repo
.Path
= file
.path
;
679 if (infos
[file
.path
] && infos
[file
.path
][n
]) {
680 repo
.Origin
= infos
[file
.path
][n
].origin
|| Proxmox
.Utils
.UnknownText
;
681 repo
.warnings
= infos
[file
.path
][n
].warnings
|| [];
683 if (repo
.Enabled
&& repo
.warnings
.some(w
=> w
.property
=== 'Suites')) {
684 suitesWarning
= true;
691 repoGrid
.store
.loadData(gridData
);
693 me
.updateStandardRepos(data
['standard-repos']);
698 vm
.set('errors', errors
);
699 vm
.set('suitesWarning', suitesWarning
);
700 me
.getController().updateState();
703 me
.check_subscription();
707 activate: function() {
713 initComponent: function() {
717 throw "no node name specified";
720 let store
= Ext
.create('Ext.data.Store', {
723 url
: `/api2/json/nodes/${me.nodename}/apt/repositories`,
727 Ext
.apply(me
, { store
: store
});
729 Proxmox
.Utils
.monStoreErrors(me
, me
.store
, true);
733 me
.getViewModel().set('product', me
.product
);