]>
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
: 'proxmoxButton',
197 text
: gettext('Enable'),
198 defaultText
: gettext('Enable'),
199 altText
: gettext('Disable'),
203 text
: '{enableButtonText}',
205 handler: function(button
, event
, record
) {
207 let panel
= me
.up('proxmoxNodeAPTRepositories');
210 path
: record
.data
.Path
,
211 index
: record
.data
.Index
,
212 enabled
: record
.data
.Enabled
? 0 : 1, // invert
215 if (panel
.digest
!== undefined) {
216 params
.digest
= panel
.digest
;
219 Proxmox
.Utils
.API2Request({
220 url
: `/nodes/${panel.nodename}/apt/repositories`,
223 failure: function(response
, opts
) {
224 Ext
.Msg
.alert(gettext('Error'), response
.htmlStatus
);
227 success: function(response
, opts
) {
233 render: function(btn
) {
234 // HACK: calculate the max button width on first render to avoid toolbar glitches
235 let defSize
= btn
.getSize().width
;
237 btn
.setText(btn
.altText
);
238 let altSize
= btn
.getSize().width
;
240 btn
.setText(btn
.defaultText
);
241 btn
.setSize({ width
: altSize
> defSize
? altSize
: defSize
});
247 sortableColumns
: false,
250 getRowClass
: (record
, index
) => record
.get('Enabled') ? '' : 'proxmox-disabled-row',
255 xtype
: 'checkcolumn',
256 header
: gettext('Enabled'),
257 dataIndex
: 'Enabled',
259 beforecheckchange
: () => false, // veto, we don't want to allow inline change - to subtle
264 header
: gettext('Types'),
266 renderer: function(types
, cell
, record
) {
267 return types
.join(' ');
272 header
: gettext('URIs'),
274 renderer: function(uris
, cell
, record
) {
275 return uris
.join(' ');
280 header
: gettext('Suites'),
282 renderer: function(suites
, metaData
, record
) {
284 if (record
.data
.warnings
&& record
.data
.warnings
.length
> 0) {
285 let txt
= [gettext('Warning')];
286 record
.data
.warnings
.forEach((warning
) => {
287 if (warning
.property
=== 'Suites') {
288 txt
.push(warning
.message
);
291 metaData
.tdAttr
= `data-qtip="${Ext.htmlEncode(txt.join('<br>'))}"`;
292 if (record
.data
.Enabled
) {
293 metaData
.tdCls
= 'proxmox-invalid-row';
294 err
= '<i class="fa fa-fw critical fa-exclamation-circle"></i> ';
296 metaData
.tdCls
= 'proxmox-warning-row';
297 err
= '<i class="fa fa-fw warning fa-exclamation-circle"></i> ';
300 return suites
.join(' ') + err
;
305 header
: gettext('Components'),
306 dataIndex
: 'Components',
307 renderer: function(components
, metaData
, record
) {
308 if (components
=== undefined) {
312 if (components
.length
=== 1) {
313 // FIXME: this should be a flag set to the actual repsotiories, i.e., a tristate
314 // like production-ready = <yes|no|other> (Option<bool>)
315 if (components
[0].match(/\w+(-no-subscription|test)\s*$/i)) {
316 metaData
.tdCls
= 'proxmox-warning-row';
317 err
= '<i class="fa fa-fw warning fa-exclamation-circle"></i> ';
319 let qtip
= components
[0].match(/no-subscription/)
320 ? gettext('The no-subscription repository is NOT production-ready')
321 : gettext('The test repository may contain unstable updates')
323 metaData
.tdAttr
= `data-qtip="${Ext.htmlEncode(qtip)}"`;
326 return components
.join(' ') + err
;
331 header
: gettext('Options'),
332 dataIndex
: 'Options',
333 renderer: function(options
, cell
, record
) {
338 let filetype
= record
.data
.FileType
;
341 options
.forEach(function(option
) {
342 let key
= option
.Key
;
343 if (filetype
=== 'list') {
344 let values
= option
.Values
.join(',');
345 text
+= `${key}=${values} `;
346 } else if (filetype
=== 'sources') {
347 let values
= option
.Values
.join(' ');
348 text
+= `${key}: ${values}<br>`;
350 throw "unknown file type";
358 header
: gettext('Origin'),
361 renderer
: (value
, meta
, rec
) => {
362 if (typeof value
!== 'string' || value
.length
=== 0) {
363 value
= gettext('Other');
365 let cls
= 'fa fa-fw fa-question-circle-o';
366 if (value
.match(/^\s*Proxmox\s*$/i)) {
367 cls
= 'pmx-itype-icon pmx-itype-icon-proxmox-x';
368 } else if (value
.match(/^\s*Debian\s*(:?Backports)?$/i)) {
369 cls
= 'pmx-itype-icon pmx-itype-icon-debian-swirl';
371 return `<i class='${cls}'></i> ${value}`;
375 header
: gettext('Comment'),
376 dataIndex
: 'Comment',
384 groupHeaderTpl
: '{[ "File: " + values.name ]} ({rows.length} repositor{[values.rows.length > 1 ? "ies" : "y"]})',
385 enableGroupingMenu
: false,
390 model
: 'apt-repolist',
400 initComponent: function() {
404 throw "no node name specified";
411 Ext
.define('Proxmox.node.APTRepositories', {
412 extend
: 'Ext.panel.Panel',
413 xtype
: 'proxmoxNodeAPTRepositories',
414 mixins
: ['Proxmox.Mixin.CBind'],
418 onlineHelp
: undefined,
420 product
: 'Proxmox VE', // default
423 xclass
: 'Ext.app.ViewController',
425 selectionChange: function(grid
, selection
) {
427 if (!selection
|| selection
.length
< 1) {
430 let rec
= selection
[0];
431 let vm
= me
.getViewModel();
432 vm
.set('selectionenabled', rec
.get('Enabled'));
436 updateState: function() {
438 let vm
= me
.getViewModel();
440 let store
= vm
.get('errorstore');
443 let status
= 'good'; // start with best, the helper below will downgrade if needed
444 let text
= gettext('All OK, you have production-ready repositories configured!');
446 let addGood
= message
=> store
.add({ status
: 'good', message
});
447 let addWarn
= (message
, important
) => {
448 if (status
!== 'critical') {
450 text
= important
? message
: gettext('Warning');
452 store
.add({ status
: 'warning', message
});
454 let addCritical
= (message
, important
) => {
456 text
= important
? message
: gettext('Error');
457 store
.add({ status
: 'critical', message
});
460 let errors
= vm
.get('errors');
461 errors
.forEach(error
=> addCritical(`${error.path} - ${error.error}`));
463 let activeSubscription
= vm
.get('subscriptionActive');
464 let enterprise
= vm
.get('enterpriseRepo');
465 let nosubscription
= vm
.get('noSubscriptionRepo');
466 let test
= vm
.get('testRepo');
467 let wrongSuites
= vm
.get('suitesWarning');
469 if (!enterprise
&& !nosubscription
&& !test
) {
471 Ext
.String
.format(gettext('No {0} repository is enabled, you do not get any updates!'), vm
.get('product')),
473 } else if (errors
.length
> 0) {
474 // nothing extra, just avoid that we show "get updates"
475 } else if (enterprise
&& !nosubscription
&& !test
&& activeSubscription
) {
476 addGood(Ext
.String
.format(gettext('You get supported updates for {0}'), vm
.get('product')));
477 } else if (nosubscription
|| test
) {
478 addGood(Ext
.String
.format(gettext('You get updates for {0}'), vm
.get('product')));
482 addWarn(gettext('Some suites are misconfigured'));
485 if (!activeSubscription
&& enterprise
) {
486 addWarn(gettext('The enterprise repository is enabled, but there is no active subscription!'));
489 if (nosubscription
) {
490 addWarn(gettext('The no-subscription repository is not recommended for production use!'));
494 addWarn(gettext('The test repository may pull in unstable updates and is not recommended for production use!'));
497 if (errors
.length
> 0) {
498 text
= gettext('Fatal parsing error for at least one repository');
501 let iconCls
= Proxmox
.Utils
.get_health_icon(status
, true);
512 product
: 'Proxmox VE', // default
514 suitesWarning
: false,
515 subscriptionActive
: '',
516 noSubscriptionRepo
: '',
519 selectionenabled
: false,
523 enableButtonText
: (get) => get('selectionenabled')
524 ? gettext('Disable') : gettext('Enable'),
528 fields
: ['status', 'message'],
548 title
: gettext('Status'),
555 iconCls
: Proxmox
.Utils
.get_health_icon(undefined, true),
562 '<center class="centered-flex-column" style="font-size:15px;line-height: 25px;">',
563 '<i class="fa fa-4x {iconCls}"></i>',
569 xtype
: 'proxmoxNodeAPTRepositoriesErrors',
570 name
: 'repositoriesErrors',
574 store
: '{errorstore}',
580 xtype
: 'proxmoxNodeAPTRepositoriesGrid',
581 name
: 'repositoriesGrid',
584 nodename
: '{nodename}',
585 onlineHelp
: '{onlineHelp}',
587 majorUpgradeAllowed
: false, // TODO get release information from an API call?
589 selectionchange
: 'selectionChange',
594 check_subscription: function() {
596 let vm
= me
.getViewModel();
598 Proxmox
.Utils
.API2Request({
599 url
: `/nodes/${me.nodename}/subscription`,
601 failure
: (response
, opts
) => Ext
.Msg
.alert(gettext('Error'), response
.htmlStatus
),
602 success: function(response
, opts
) {
603 const res
= response
.result
;
604 const subscription
= !(!res
|| !res
.data
|| res
.data
.status
.toLowerCase() !== 'active');
605 vm
.set('subscriptionActive', subscription
);
606 me
.getController().updateState();
611 updateStandardRepos: function(standardRepos
) {
613 let vm
= me
.getViewModel();
615 let addButton
= me
.down('button[name=addRepo]');
617 addButton
.repoInfo
= [];
618 for (const standardRepo
of standardRepos
) {
619 const handle
= standardRepo
.handle
;
620 const status
= standardRepo
.status
;
622 if (handle
=== "enterprise") {
623 vm
.set('enterpriseRepo', status
);
624 } else if (handle
=== "no-subscription") {
625 vm
.set('noSubscriptionRepo', status
);
626 } else if (handle
=== 'test') {
627 vm
.set('testRepo', status
);
629 me
.getController().updateState();
631 addButton
.repoInfo
.push(standardRepo
);
632 addButton
.digest
= me
.digest
;
635 addButton
.setDisabled(false);
640 let vm
= me
.getViewModel();
641 let repoGrid
= me
.down('proxmoxNodeAPTRepositoriesGrid');
643 me
.store
.load(function(records
, operation
, success
) {
647 let suitesWarning
= false;
649 if (success
&& records
.length
> 0) {
650 let data
= records
[0].data
;
651 let files
= data
.files
;
652 errors
= data
.errors
;
653 digest
= data
.digest
;
656 for (const info
of data
.infos
) {
657 let path
= info
.path
;
658 let idx
= info
.index
;
663 if (!infos
[path
][idx
]) {
670 if (info
.kind
=== 'origin') {
671 infos
[path
][idx
].origin
= info
.message
;
672 } else if (info
.kind
=== 'warning' ||
673 (info
.kind
=== 'ignore-pre-upgrade-warning' && !repoGrid
.majorUpgradeAllowed
)
675 infos
[path
][idx
].warnings
.push(info
);
677 throw 'unknown info';
682 files
.forEach(function(file
) {
683 for (let n
= 0; n
< file
.repositories
.length
; n
++) {
684 let repo
= file
.repositories
[n
];
685 repo
.Path
= file
.path
;
687 if (infos
[file
.path
] && infos
[file
.path
][n
]) {
688 repo
.Origin
= infos
[file
.path
][n
].origin
|| Proxmox
.Utils
.UnknownText
;
689 repo
.warnings
= infos
[file
.path
][n
].warnings
|| [];
691 if (repo
.Enabled
&& repo
.warnings
.some(w
=> w
.property
=== 'Suites')) {
692 suitesWarning
= true;
699 repoGrid
.store
.loadData(gridData
);
701 me
.updateStandardRepos(data
['standard-repos']);
706 vm
.set('errors', errors
);
707 vm
.set('suitesWarning', suitesWarning
);
708 me
.getController().updateState();
711 me
.check_subscription();
715 activate: function() {
721 initComponent: function() {
725 throw "no node name specified";
728 let store
= Ext
.create('Ext.data.Store', {
731 url
: `/api2/json/nodes/${me.nodename}/apt/repositories`,
735 Ext
.apply(me
, { store
: store
});
737 Proxmox
.Utils
.monStoreErrors(me
, me
.store
, true);
741 me
.getViewModel().set('product', me
.product
);