]>
git.proxmox.com Git - proxmox-widget-toolkit.git/blob - src/node/APTRepositories.js
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',
144 mixins
: ['Proxmox.Mixin.CBind'],
146 title
: gettext('APT Repositories'),
148 cls
: 'proxmox-apt-repos', // to allow applying styling to general components with local effect
154 text
: gettext('Reload'),
155 iconCls
: 'fa fa-refresh',
156 handler: function() {
158 me
.up('proxmoxNodeAPTRepositories').reload();
162 text
: gettext('Add'),
167 onlineHelp
: '{onlineHelp}',
169 handler: function(button
, event
, record
) {
170 Proxmox
.Utils
.checked_command(() => {
172 let panel
= me
.up('proxmoxNodeAPTRepositories');
174 let extraParams
= {};
175 if (panel
.digest
!== undefined) {
176 extraParams
.digest
= panel
.digest
;
179 Ext
.create('Proxmox.window.APTRepositoryAdd', {
180 repoInfo
: me
.repoInfo
,
181 url
: `/api2/extjs/nodes/${panel.nodename}/apt/repositories`,
183 extraRequestParams
: extraParams
,
184 onlineHelp
: me
.onlineHelp
,
186 destroy: function() {
196 xtype
: 'proxmoxAltTextButton',
197 defaultText
: gettext('Enable'),
198 altText
: gettext('Disable'),
202 text
: '{enableButtonText}',
204 handler: function(button
, event
, record
) {
206 let panel
= me
.up('proxmoxNodeAPTRepositories');
209 path
: record
.data
.Path
,
210 index
: record
.data
.Index
,
211 enabled
: record
.data
.Enabled
? 0 : 1, // invert
214 if (panel
.digest
!== undefined) {
215 params
.digest
= panel
.digest
;
218 Proxmox
.Utils
.API2Request({
219 url
: `/nodes/${panel.nodename}/apt/repositories`,
222 failure: function(response
, opts
) {
223 Ext
.Msg
.alert(gettext('Error'), response
.htmlStatus
);
226 success: function(response
, opts
) {
234 sortableColumns
: false,
237 getRowClass
: (record
, index
) => record
.get('Enabled') ? '' : 'proxmox-disabled-row',
242 xtype
: 'checkcolumn',
243 header
: gettext('Enabled'),
244 dataIndex
: 'Enabled',
246 beforecheckchange
: () => false, // veto, we don't want to allow inline change - to subtle
251 header
: gettext('Types'),
253 renderer: function(types
, cell
, record
) {
254 return types
.join(' ');
259 header
: gettext('URIs'),
261 renderer: function(uris
, cell
, record
) {
262 return uris
.join(' ');
267 header
: gettext('Suites'),
269 renderer: function(suites
, metaData
, record
) {
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
);
278 metaData
.tdAttr
= `data-qtip="${Ext.htmlEncode(txt.join('<br>'))}"`;
279 if (record
.data
.Enabled
) {
280 metaData
.tdCls
= 'proxmox-invalid-row';
281 err
= '<i class="fa fa-fw critical fa-exclamation-circle"></i> ';
283 metaData
.tdCls
= 'proxmox-warning-row';
284 err
= '<i class="fa fa-fw warning fa-exclamation-circle"></i> ';
287 return suites
.join(' ') + err
;
292 header
: gettext('Components'),
293 dataIndex
: 'Components',
294 renderer: function(components
, metaData
, record
) {
295 if (components
=== undefined) {
299 if (components
.length
=== 1) {
300 // FIXME: this should be a flag set to the actual repsotiories, i.e., a tristate
301 // like production-ready = <yes|no|other> (Option<bool>)
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> ';
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')
310 metaData
.tdAttr
= `data-qtip="${Ext.htmlEncode(qtip)}"`;
313 return components
.join(' ') + err
;
318 header
: gettext('Options'),
319 dataIndex
: 'Options',
320 renderer: function(options
, cell
, record
) {
325 let filetype
= record
.data
.FileType
;
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>`;
337 throw "unknown file type";
345 header
: gettext('Origin'),
348 renderer
: (value
, meta
, rec
) => {
349 if (typeof value
!== 'string' || value
.length
=== 0) {
350 value
= gettext('Other');
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';
355 } else if (value
.match(/^\s*Debian\s*(:?Backports)?$/i)) {
356 cls
= 'pmx-itype-icon pmx-itype-icon-debian-swirl';
358 return `<i class='${cls}'></i> ${value}`;
362 header
: gettext('Comment'),
363 dataIndex
: 'Comment',
371 groupHeaderTpl
: '{[ "File: " + values.name ]} ({rows.length} repositor{[values.rows.length > 1 ? "ies" : "y"]})',
372 enableGroupingMenu
: false,
377 model
: 'apt-repolist',
387 initComponent: function() {
391 throw "no node name specified";
398 Ext
.define('Proxmox.node.APTRepositories', {
399 extend
: 'Ext.panel.Panel',
400 xtype
: 'proxmoxNodeAPTRepositories',
401 mixins
: ['Proxmox.Mixin.CBind'],
405 onlineHelp
: undefined,
407 product
: 'Proxmox VE', // default
410 xclass
: 'Ext.app.ViewController',
412 selectionChange: function(grid
, selection
) {
414 if (!selection
|| selection
.length
< 1) {
417 let rec
= selection
[0];
418 let vm
= me
.getViewModel();
419 vm
.set('selectionenabled', rec
.get('Enabled'));
423 updateState: function() {
425 let vm
= me
.getViewModel();
427 let store
= vm
.get('errorstore');
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!');
433 let addGood
= message
=> store
.add({ status
: 'good', message
});
434 let addWarn
= (message
, important
) => {
435 if (status
!== 'critical') {
437 text
= important
? message
: gettext('Warning');
439 store
.add({ status
: 'warning', message
});
441 let addCritical
= (message
, important
) => {
443 text
= important
? message
: gettext('Error');
444 store
.add({ status
: 'critical', message
});
447 let errors
= vm
.get('errors');
448 errors
.forEach(error
=> addCritical(`${error.path} - ${error.error}`));
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');
456 if (!enterprise
&& !nosubscription
&& !test
) {
458 Ext
.String
.format(gettext('No {0} repository is enabled, you do not get any updates!'), vm
.get('product')),
460 } else if (errors
.length
> 0) {
461 // nothing extra, just avoid that we show "get updates"
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')));
469 addWarn(gettext('Some suites are misconfigured'));
472 if (!activeSubscription
&& enterprise
) {
473 addWarn(gettext('The enterprise repository is enabled, but there is no active subscription!'));
476 if (nosubscription
) {
477 addWarn(gettext('The no-subscription repository is not recommended for production use!'));
481 addWarn(gettext('The test repository may pull in unstable updates and is not recommended for production use!'));
484 if (errors
.length
> 0) {
485 text
= gettext('Fatal parsing error for at least one repository');
488 let iconCls
= Proxmox
.Utils
.get_health_icon(status
, true);
499 product
: 'Proxmox VE', // default
501 suitesWarning
: false,
502 subscriptionActive
: '',
503 noSubscriptionRepo
: '',
506 selectionenabled
: false,
510 enableButtonText
: (get) => get('selectionenabled')
511 ? gettext('Disable') : gettext('Enable'),
515 fields
: ['status', 'message'],
535 title
: gettext('Status'),
542 iconCls
: Proxmox
.Utils
.get_health_icon(undefined, true),
549 '<center class="centered-flex-column" style="font-size:15px;line-height: 25px;">',
550 '<i class="fa fa-4x {iconCls}"></i>',
556 xtype
: 'proxmoxNodeAPTRepositoriesErrors',
557 name
: 'repositoriesErrors',
561 store
: '{errorstore}',
567 xtype
: 'proxmoxNodeAPTRepositoriesGrid',
568 name
: 'repositoriesGrid',
571 nodename
: '{nodename}',
572 onlineHelp
: '{onlineHelp}',
574 majorUpgradeAllowed
: false, // TODO get release information from an API call?
576 selectionchange
: 'selectionChange',
581 check_subscription: function() {
583 let vm
= me
.getViewModel();
585 Proxmox
.Utils
.API2Request({
586 url
: `/nodes/${me.nodename}/subscription`,
588 failure
: (response
, opts
) => Ext
.Msg
.alert(gettext('Error'), response
.htmlStatus
),
589 success: function(response
, opts
) {
590 const res
= response
.result
;
591 const subscription
= !(!res
|| !res
.data
|| res
.data
.status
.toLowerCase() !== 'active');
592 vm
.set('subscriptionActive', subscription
);
593 me
.getController().updateState();
598 updateStandardRepos: function(standardRepos
) {
600 let vm
= me
.getViewModel();
602 let addButton
= me
.down('button[name=addRepo]');
604 addButton
.repoInfo
= [];
605 for (const standardRepo
of standardRepos
) {
606 const handle
= standardRepo
.handle
;
607 const status
= standardRepo
.status
;
609 if (handle
=== "enterprise") {
610 vm
.set('enterpriseRepo', status
);
611 } else if (handle
=== "no-subscription") {
612 vm
.set('noSubscriptionRepo', status
);
613 } else if (handle
=== 'test') {
614 vm
.set('testRepo', status
);
616 me
.getController().updateState();
618 addButton
.repoInfo
.push(standardRepo
);
619 addButton
.digest
= me
.digest
;
622 addButton
.setDisabled(false);
627 let vm
= me
.getViewModel();
628 let repoGrid
= me
.down('proxmoxNodeAPTRepositoriesGrid');
630 me
.store
.load(function(records
, operation
, success
) {
634 let suitesWarning
= false;
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
;
643 for (const info
of data
.infos
) {
644 let path
= info
.path
;
645 let idx
= info
.index
;
650 if (!infos
[path
][idx
]) {
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
)
662 infos
[path
][idx
].warnings
.push(info
);
664 throw 'unknown info';
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
;
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
|| [];
678 if (repo
.Enabled
&& repo
.warnings
.some(w
=> w
.property
=== 'Suites')) {
679 suitesWarning
= true;
686 repoGrid
.store
.loadData(gridData
);
688 me
.updateStandardRepos(data
['standard-repos']);
693 vm
.set('errors', errors
);
694 vm
.set('suitesWarning', suitesWarning
);
695 me
.getController().updateState();
698 me
.check_subscription();
702 activate: function() {
708 initComponent: function() {
712 throw "no node name specified";
715 let store
= Ext
.create('Ext.data.Store', {
718 url
: `/api2/json/nodes/${me.nodename}/apt/repositories`,
722 Ext
.apply(me
, { store
: store
});
724 Proxmox
.Utils
.monStoreErrors(me
, me
.store
, true);
728 me
.getViewModel().set('product', me
.product
);