]>
git.proxmox.com Git - proxmox-widget-toolkit.git/blob - src/node/APTRepositories.js
43d6faf7f71bdf5810294e289cb813b1da3c0493
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
: () => 'proxmox-invalid-row',
122 header
: gettext('File'),
124 renderer
: value
=> `<i class='pve-grid-fa fa fa-fw fa-exclamation-triangle'></i>${value}`,
128 header
: gettext('Error'),
135 Ext
.define('Proxmox.node.APTRepositoriesGrid', {
136 extend
: 'Ext.grid.GridPanel',
137 xtype
: 'proxmoxNodeAPTRepositoriesGrid',
139 title
: gettext('APT Repositories'),
141 cls
: 'proxmox-apt-repos', // to allow applying styling to general components with local effect
147 text
: gettext('Reload'),
148 iconCls
: 'fa fa-refresh',
149 handler: function() {
151 me
.up('proxmoxNodeAPTRepositories').reload();
155 text
: gettext('Add'),
159 handler: function(button
, event
, record
) {
160 Proxmox
.Utils
.checked_command(() => {
162 let panel
= me
.up('proxmoxNodeAPTRepositories');
164 let extraParams
= {};
165 if (panel
.digest
!== undefined) {
166 extraParams
.digest
= panel
.digest
;
169 Ext
.create('Proxmox.window.APTRepositoryAdd', {
170 repoInfo
: me
.repoInfo
,
171 url
: `/api2/extjs/nodes/${panel.nodename}/apt/repositories`,
173 extraRequestParams
: extraParams
,
175 destroy: function() {
185 xtype
: 'proxmoxButton',
186 text
: gettext('Enable'),
187 defaultText
: gettext('Enable'),
188 altText
: gettext('Disable'),
189 id
: 'repoEnableButton',
192 text
: '{enableButtonText}',
194 handler: function(button
, event
, record
) {
196 let panel
= me
.up('proxmoxNodeAPTRepositories');
199 path
: record
.data
.Path
,
200 index
: record
.data
.Index
,
201 enabled
: record
.data
.Enabled
? 0 : 1, // invert
204 if (panel
.digest
!== undefined) {
205 params
.digest
= panel
.digest
;
208 Proxmox
.Utils
.API2Request({
209 url
: `/nodes/${panel.nodename}/apt/repositories`,
212 failure: function(response
, opts
) {
213 Ext
.Msg
.alert(gettext('Error'), response
.htmlStatus
);
216 success: function(response
, opts
) {
222 render: function(btn
) {
223 // HACK: calculate the max button width on first render to avoid toolbar glitches
224 let defSize
= btn
.getSize().width
;
226 btn
.setText(btn
.altText
);
227 let altSize
= btn
.getSize().width
;
229 btn
.setText(btn
.defaultText
);
230 btn
.setSize({ width
: altSize
> defSize
? altSize
: defSize
});
236 sortableColumns
: false,
239 getRowClass
: (record
, index
) => record
.get('Enabled') ? '' : 'proxmox-disabled-row',
244 xtype
: 'checkcolumn',
245 header
: gettext('Enabled'),
246 dataIndex
: 'Enabled',
248 beforecheckchange
: () => false, // veto, we don't want to allow inline change - to subtle
253 header
: gettext('Types'),
255 renderer: function(types
, cell
, record
) {
256 return types
.join(' ');
261 header
: gettext('URIs'),
263 renderer: function(uris
, cell
, record
) {
264 return uris
.join(' ');
269 header
: gettext('Suites'),
271 renderer: function(suites
, metaData
, record
) {
273 if (record
.data
.warnings
&& record
.data
.warnings
.length
> 0) {
274 let txt
= [gettext('Warning')];
275 record
.data
.warnings
.forEach((warning
) => {
276 if (warning
.property
=== 'Suites') {
277 txt
.push(warning
.message
);
280 metaData
.tdAttr
= `data-qtip="${Ext.htmlEncode(txt.join('<br>'))}"`;
281 if (record
.data
.Enabled
) {
282 metaData
.tdCls
= 'proxmox-invalid-row';
283 err
= '<i class="fa fa-fw critical fa-exclamation-circle"></i> ';
285 metaData
.tdCls
= 'proxmox-warning-row';
286 err
= '<i class="fa fa-fw warning fa-exclamation-circle"></i> ';
289 return suites
.join(' ') + err
;
294 header
: gettext('Components'),
295 dataIndex
: 'Components',
296 renderer: function(components
, metaData
, record
) {
298 if (components
.length
=== 1) {
299 // FIXME: this should be a flag set to the actual repsotiories, i.e., a tristate
300 // like production-ready = <yes|no|other> (Option<bool>)
301 if (components
[0].match(/\w+(-no-subscription|test)\s*$/i)) {
302 metaData
.tdCls
= 'proxmox-warning-row';
303 err
= '<i class="fa fa-fw warning fa-exclamation-circle"></i> ';
305 let qtip
= components
[0].match(/no-subscription/)
306 ? gettext('The no-subscription repository is NOT production-ready')
307 : gettext('The test repository may contain unstable updates')
309 metaData
.tdAttr
= `data-qtip="${Ext.htmlEncode(qtip)}"`;
312 return components
.join(' ') + err
;
317 header
: gettext('Options'),
318 dataIndex
: 'Options',
319 renderer: function(options
, cell
, record
) {
324 let filetype
= record
.data
.FileType
;
327 options
.forEach(function(option
) {
328 let key
= option
.Key
;
329 if (filetype
=== 'list') {
330 let values
= option
.Values
.join(',');
331 text
+= `${key}=${values} `;
332 } else if (filetype
=== 'sources') {
333 let values
= option
.Values
.join(' ');
334 text
+= `${key}: ${values}<br>`;
336 throw "unkown file type";
344 header
: gettext('Origin'),
347 renderer
: (value
, meta
, rec
) => {
348 if (typeof value
!== 'string' || value
.length
=== 0) {
349 value
= gettext('Other');
351 let cls
= 'fa fa-fw fa-question-circle-o';
352 if (value
.match(/^\s*Proxmox\s*$/i)) {
353 cls
= 'pmx-itype-icon pmx-itype-icon-proxmox-x';
354 } else if (value
.match(/^\s*Debian\s*$/i)) {
355 cls
= 'pmx-itype-icon pmx-itype-icon-debian-swirl';
357 return `<i class='${cls}'></i> ${value}`;
361 header
: gettext('Comment'),
362 dataIndex
: 'Comment',
367 initComponent: function() {
371 throw "no node name specified";
374 let store
= Ext
.create('Ext.data.Store', {
375 model
: 'apt-repolist',
385 let groupingFeature
= Ext
.create('Ext.grid.feature.Grouping', {
386 groupHeaderTpl
: '{[ "File: " + values.name ]} ({rows.length} ' +
387 'repositor{[values.rows.length > 1 ? "ies" : "y"]})',
388 enableGroupingMenu
: false,
393 features
: [groupingFeature
],
400 Ext
.define('Proxmox.node.APTRepositories', {
401 extend
: 'Ext.panel.Panel',
402 xtype
: 'proxmoxNodeAPTRepositories',
403 mixins
: ['Proxmox.Mixin.CBind'],
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 if (vm
.get('errorCount') > 0) {
429 iconCls
: Proxmox
.Utils
.get_health_icon('critical', true),
430 text
: gettext('Error parsing repositories'),
435 let text
= gettext('Repositories are configured in a recommended way');
436 let status
= 'warning';
438 let activeSubscription
= vm
.get('subscriptionActive');
439 let enterprise
= vm
.get('enterpriseRepo');
440 let nosubscription
= vm
.get('noSubscriptionRepo');
441 let test
= vm
.get('testRepo');
442 let wrongSuites
= vm
.get('suitesWarning');
444 if (!activeSubscription
&& enterprise
) {
445 text
= gettext('The enterprise repository is enabled, but there is no active subscription!');
446 } else if (nosubscription
) {
447 text
= gettext('The no-subscription repository is not recommended for production use!');
449 text
= gettext('The test repository is not recommended for production use!');
450 } else if (!enterprise
&& !nosubscription
&& !test
) {
451 text
= Ext
.String
.format(gettext('No {0} repository is enabled!'), vm
.get('product'));
452 } else if (wrongSuites
) {
453 text
= gettext('Some Suites are misconfigured');
458 let iconCls
= Proxmox
.Utils
.get_health_icon(status
, true);
469 product
: 'Proxmox VE', // default
471 suitesWarning
: false,
472 subscriptionActive
: '',
473 noSubscriptionRepo
: '',
476 selectionenabled
: false,
480 noErrors
: (get) => get('errorCount') === 0,
481 enableButtonText
: (get) => get('selectionenabled')
482 ? gettext('Disable') : gettext('Enable'),
501 title
: gettext('Status'),
508 iconCls
: Proxmox
.Utils
.get_health_icon(undefined, true),
516 '<i class="fa fa-4x {iconCls}"></i>',
523 xtype
: 'proxmoxNodeAPTRepositoriesErrors',
524 name
: 'repositoriesErrors',
529 hidden
: '{noErrors}',
535 xtype
: 'proxmoxNodeAPTRepositoriesGrid',
536 name
: 'repositoriesGrid',
539 nodename
: '{nodename}',
541 majorUpgradeAllowed
: false, // TODO get release information from an API call?
543 selectionchange
: 'selectionChange',
548 check_subscription: function() {
550 let vm
= me
.getViewModel();
552 Proxmox
.Utils
.API2Request({
553 url
: `/nodes/${me.nodename}/subscription`,
555 failure
: (response
, opts
) => Ext
.Msg
.alert(gettext('Error'), response
.htmlStatus
),
556 success: function(response
, opts
) {
557 const res
= response
.result
;
558 const subscription
= !(!res
|| !res
.data
|| res
.data
.status
.toLowerCase() !== 'active');
559 vm
.set('subscriptionActive', subscription
);
560 me
.getController().updateState();
565 updateStandardRepos: function(standardRepos
) {
567 let vm
= me
.getViewModel();
569 let addButton
= me
.down('#addButton');
570 addButton
.repoInfo
= [];
572 for (const standardRepo
of standardRepos
) {
573 const handle
= standardRepo
.handle
;
574 const status
= standardRepo
.status
;
576 if (handle
=== "enterprise") {
577 vm
.set('enterpriseRepo', status
);
578 } else if (handle
=== "no-subscription") {
579 vm
.set('noSubscriptionRepo', status
);
580 } else if (handle
=== 'test') {
581 vm
.set('testRepo', status
);
583 me
.getController().updateState();
585 addButton
.repoInfo
.push(standardRepo
);
586 addButton
.digest
= me
.digest
;
589 addButton
.setDisabled(false);
594 let vm
= me
.getViewModel();
595 let repoGrid
= me
.down('proxmoxNodeAPTRepositoriesGrid');
596 let errorGrid
= me
.down('proxmoxNodeAPTRepositoriesErrors');
598 me
.store
.load(function(records
, operation
, success
) {
602 let suitesWarning
= false;
604 if (success
&& records
.length
> 0) {
605 let data
= records
[0].data
;
606 let files
= data
.files
;
607 errors
= data
.errors
;
608 digest
= data
.digest
;
611 for (const info
of data
.infos
) {
612 let path
= info
.path
;
613 let idx
= info
.index
;
618 if (!infos
[path
][idx
]) {
625 if (info
.kind
=== 'origin') {
626 infos
[path
][idx
].origin
= info
.message
;
627 } else if (info
.kind
=== 'warning' ||
628 (info
.kind
=== 'ignore-pre-upgrade-warning' && !repoGrid
.majorUpgradeAllowed
)
630 infos
[path
][idx
].warnings
.push(info
);
631 if (!suitesWarning
&& info
.property
=== 'Suites') {
632 suitesWarning
= true;
635 throw 'unknown info';
640 files
.forEach(function(file
) {
641 for (let n
= 0; n
< file
.repositories
.length
; n
++) {
642 let repo
= file
.repositories
[n
];
643 repo
.Path
= file
.path
;
645 if (infos
[file
.path
] && infos
[file
.path
][n
]) {
646 repo
.Origin
= infos
[file
.path
][n
].origin
|| Proxmox
.Utils
.UnknownText
;
647 repo
.warnings
= infos
[file
.path
][n
].warnings
|| [];
653 repoGrid
.store
.loadData(gridData
);
655 me
.updateStandardRepos(data
['standard-repos']);
660 vm
.set('errorCount', errors
.length
);
661 vm
.set('suitesWarning', suitesWarning
);
662 me
.getController().updateState();
664 errorGrid
.store
.loadData(errors
);
667 me
.check_subscription();
671 activate: function() {
677 initComponent: function() {
681 throw "no node name specified";
684 let store
= Ext
.create('Ext.data.Store', {
687 url
: `/api2/json/nodes/${me.nodename}/apt/repositories`,
691 Ext
.apply(me
, { store
: store
});
693 Proxmox
.Utils
.monStoreErrors(me
, me
.store
, true);
697 me
.getViewModel().set('product', me
.product
);