]>
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 header
: gettext('Enabled'),
243 dataIndex
: 'Enabled',
245 renderer
: Proxmox
.Utils
.renderEnabledIcon
,
249 header
: gettext('Types'),
251 renderer: function(types
, cell
, record
) {
252 return types
.join(' ');
257 header
: gettext('URIs'),
259 renderer: function(uris
, cell
, record
) {
260 return uris
.join(' ');
265 header
: gettext('Suites'),
267 renderer: function(suites
, metaData
, record
) {
269 if (record
.data
.warnings
&& record
.data
.warnings
.length
> 0) {
270 let txt
= [gettext('Warning')];
271 record
.data
.warnings
.forEach((warning
) => {
272 if (warning
.property
=== 'Suites') {
273 txt
.push(warning
.message
);
276 metaData
.tdAttr
= `data-qtip="${Ext.htmlEncode(txt.join('<br>'))}"`;
277 if (record
.data
.Enabled
) {
278 metaData
.tdCls
= 'proxmox-invalid-row';
279 err
= '<i class="fa fa-fw critical fa-exclamation-circle"></i> ';
281 metaData
.tdCls
= 'proxmox-warning-row';
282 err
= '<i class="fa fa-fw warning fa-exclamation-circle"></i> ';
285 return suites
.join(' ') + err
;
290 header
: gettext('Components'),
291 dataIndex
: 'Components',
292 renderer: function(components
, metaData
, record
) {
293 if (components
=== undefined) {
297 if (components
.length
=== 1) {
298 // FIXME: this should be a flag set to the actual repsotiories, i.e., a tristate
299 // like production-ready = <yes|no|other> (Option<bool>)
300 if (components
[0].match(/\w+(-no-subscription|test)\s*$/i)) {
301 metaData
.tdCls
= 'proxmox-warning-row';
302 err
= '<i class="fa fa-fw warning fa-exclamation-circle"></i> ';
304 let qtip
= components
[0].match(/no-subscription/)
305 ? gettext('The no-subscription repository is NOT production-ready')
306 : gettext('The test repository may contain unstable updates')
308 metaData
.tdAttr
= `data-qtip="${Ext.htmlEncode(qtip)}"`;
311 return components
.join(' ') + err
;
316 header
: gettext('Options'),
317 dataIndex
: 'Options',
318 renderer: function(options
, cell
, record
) {
323 let filetype
= record
.data
.FileType
;
326 options
.forEach(function(option
) {
327 let key
= option
.Key
;
328 if (filetype
=== 'list') {
329 let values
= option
.Values
.join(',');
330 text
+= `${key}=${values} `;
331 } else if (filetype
=== 'sources') {
332 let values
= option
.Values
.join(' ');
333 text
+= `${key}: ${values}<br>`;
335 throw "unknown file type";
343 header
: gettext('Origin'),
346 renderer
: (value
, meta
, rec
) => {
347 if (typeof value
!== 'string' || value
.length
=== 0) {
348 value
= gettext('Other');
350 let cls
= 'fa fa-fw fa-question-circle-o';
351 if (value
.match(/^\s*Proxmox\s*$/i)) {
352 cls
= 'pmx-itype-icon pmx-itype-icon-proxmox-x';
353 } else if (value
.match(/^\s*Debian\s*(:?Backports)?$/i)) {
354 cls
= 'pmx-itype-icon pmx-itype-icon-debian-swirl';
356 return `<i class='${cls}'></i> ${value}`;
360 header
: gettext('Comment'),
361 dataIndex
: 'Comment',
369 groupHeaderTpl
: '{[ "File: " + values.name ]} ({rows.length} repositor{[values.rows.length > 1 ? "ies" : "y"]})',
370 enableGroupingMenu
: false,
375 model
: 'apt-repolist',
385 initComponent: function() {
389 throw "no node name specified";
396 Ext
.define('Proxmox.node.APTRepositories', {
397 extend
: 'Ext.panel.Panel',
398 xtype
: 'proxmoxNodeAPTRepositories',
399 mixins
: ['Proxmox.Mixin.CBind'],
403 onlineHelp
: undefined,
405 product
: 'Proxmox VE', // default
408 xclass
: 'Ext.app.ViewController',
410 selectionChange: function(grid
, selection
) {
412 if (!selection
|| selection
.length
< 1) {
415 let rec
= selection
[0];
416 let vm
= me
.getViewModel();
417 vm
.set('selectionenabled', rec
.get('Enabled'));
421 updateState: function() {
423 let vm
= me
.getViewModel();
425 let store
= vm
.get('errorstore');
428 let status
= 'good'; // start with best, the helper below will downgrade if needed
429 let text
= gettext('All OK, you have production-ready repositories configured!');
431 let addGood
= message
=> store
.add({ status
: 'good', message
});
432 let addWarn
= (message
, important
) => {
433 if (status
!== 'critical') {
435 text
= important
? message
: gettext('Warning');
437 store
.add({ status
: 'warning', message
});
439 let addCritical
= (message
, important
) => {
441 text
= important
? message
: gettext('Error');
442 store
.add({ status
: 'critical', message
});
445 let errors
= vm
.get('errors');
446 errors
.forEach(error
=> addCritical(`${error.path} - ${error.error}`));
448 let activeSubscription
= vm
.get('subscriptionActive');
449 let enterprise
= vm
.get('enterpriseRepo');
450 let nosubscription
= vm
.get('noSubscriptionRepo');
451 let test
= vm
.get('testRepo');
452 let wrongSuites
= vm
.get('suitesWarning');
454 if (!enterprise
&& !nosubscription
&& !test
) {
456 Ext
.String
.format(gettext('No {0} repository is enabled, you do not get any updates!'), vm
.get('product')),
458 } else if (errors
.length
> 0) {
459 // nothing extra, just avoid that we show "get updates"
460 } else if (enterprise
&& !nosubscription
&& !test
&& activeSubscription
) {
461 addGood(Ext
.String
.format(gettext('You get supported updates for {0}'), vm
.get('product')));
462 } else if (nosubscription
|| test
) {
463 addGood(Ext
.String
.format(gettext('You get updates for {0}'), vm
.get('product')));
467 addWarn(gettext('Some suites are misconfigured'));
470 if (!activeSubscription
&& enterprise
) {
471 addWarn(gettext('The enterprise repository is enabled, but there is no active subscription!'));
474 if (nosubscription
) {
475 addWarn(gettext('The no-subscription repository is not recommended for production use!'));
479 addWarn(gettext('The test repository may pull in unstable updates and is not recommended for production use!'));
482 if (errors
.length
> 0) {
483 text
= gettext('Fatal parsing error for at least one repository');
486 let iconCls
= Proxmox
.Utils
.get_health_icon(status
, true);
497 product
: 'Proxmox VE', // default
499 suitesWarning
: false,
500 subscriptionActive
: '',
501 noSubscriptionRepo
: '',
504 selectionenabled
: false,
508 enableButtonText
: (get) => get('selectionenabled')
509 ? gettext('Disable') : gettext('Enable'),
513 fields
: ['status', 'message'],
533 title
: gettext('Status'),
540 iconCls
: Proxmox
.Utils
.get_health_icon(undefined, true),
547 '<center class="centered-flex-column" style="font-size:15px;line-height: 25px;">',
548 '<i class="fa fa-4x {iconCls}"></i>',
554 xtype
: 'proxmoxNodeAPTRepositoriesErrors',
555 name
: 'repositoriesErrors',
559 store
: '{errorstore}',
565 xtype
: 'proxmoxNodeAPTRepositoriesGrid',
566 name
: 'repositoriesGrid',
569 nodename
: '{nodename}',
570 onlineHelp
: '{onlineHelp}',
572 majorUpgradeAllowed
: false, // TODO get release information from an API call?
574 selectionchange
: 'selectionChange',
579 check_subscription: function() {
581 let vm
= me
.getViewModel();
583 Proxmox
.Utils
.API2Request({
584 url
: `/nodes/${me.nodename}/subscription`,
586 failure
: (response
, opts
) => Ext
.Msg
.alert(gettext('Error'), response
.htmlStatus
),
587 success: function(response
, opts
) {
588 const res
= response
.result
;
589 const subscription
= !(!res
|| !res
.data
|| res
.data
.status
.toLowerCase() !== 'active');
590 vm
.set('subscriptionActive', subscription
);
591 me
.getController().updateState();
596 updateStandardRepos: function(standardRepos
) {
598 let vm
= me
.getViewModel();
600 let addButton
= me
.down('button[name=addRepo]');
602 addButton
.repoInfo
= [];
603 for (const standardRepo
of standardRepos
) {
604 const handle
= standardRepo
.handle
;
605 const status
= standardRepo
.status
;
607 if (handle
=== "enterprise") {
608 vm
.set('enterpriseRepo', status
);
609 } else if (handle
=== "no-subscription") {
610 vm
.set('noSubscriptionRepo', status
);
611 } else if (handle
=== 'test') {
612 vm
.set('testRepo', status
);
614 me
.getController().updateState();
616 addButton
.repoInfo
.push(standardRepo
);
617 addButton
.digest
= me
.digest
;
620 addButton
.setDisabled(false);
625 let vm
= me
.getViewModel();
626 let repoGrid
= me
.down('proxmoxNodeAPTRepositoriesGrid');
628 me
.store
.load(function(records
, operation
, success
) {
632 let suitesWarning
= false;
634 if (success
&& records
.length
> 0) {
635 let data
= records
[0].data
;
636 let files
= data
.files
;
637 errors
= data
.errors
;
638 digest
= data
.digest
;
641 for (const info
of data
.infos
) {
642 let path
= info
.path
;
643 let idx
= info
.index
;
648 if (!infos
[path
][idx
]) {
655 if (info
.kind
=== 'origin') {
656 infos
[path
][idx
].origin
= info
.message
;
657 } else if (info
.kind
=== 'warning' ||
658 (info
.kind
=== 'ignore-pre-upgrade-warning' && !repoGrid
.majorUpgradeAllowed
)
660 infos
[path
][idx
].warnings
.push(info
);
662 throw 'unknown info';
667 files
.forEach(function(file
) {
668 for (let n
= 0; n
< file
.repositories
.length
; n
++) {
669 let repo
= file
.repositories
[n
];
670 repo
.Path
= file
.path
;
672 if (infos
[file
.path
] && infos
[file
.path
][n
]) {
673 repo
.Origin
= infos
[file
.path
][n
].origin
|| Proxmox
.Utils
.UnknownText
;
674 repo
.warnings
= infos
[file
.path
][n
].warnings
|| [];
676 if (repo
.Enabled
&& repo
.warnings
.some(w
=> w
.property
=== 'Suites')) {
677 suitesWarning
= true;
684 repoGrid
.store
.loadData(gridData
);
686 me
.updateStandardRepos(data
['standard-repos']);
691 vm
.set('errors', errors
);
692 vm
.set('suitesWarning', suitesWarning
);
693 me
.getController().updateState();
696 me
.check_subscription();
700 activate: function() {
706 initComponent: function() {
710 throw "no node name specified";
713 let store
= Ext
.create('Ext.data.Store', {
716 url
: `/api2/json/nodes/${me.nodename}/apt/repositories`,
720 Ext
.apply(me
, { store
: store
});
722 Proxmox
.Utils
.monStoreErrors(me
, me
.store
, true);
726 me
.getViewModel().set('product', me
.product
);