]>
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.node.APTRepositoriesErrors', {
19 extend
: 'Ext.grid.GridPanel',
21 xtype
: 'proxmoxNodeAPTRepositoriesErrors',
23 title
: gettext('Errors'),
29 getRowClass
: () => 'proxmox-invalid-row',
34 header
: gettext('File'),
36 renderer
: value
=> `<i class='pve-grid-fa fa fa-fw fa-exclamation-triangle'></i>${value}`,
40 header
: gettext('Error'),
47 Ext
.define('Proxmox.node.APTRepositoriesGrid', {
48 extend
: 'Ext.grid.GridPanel',
49 xtype
: 'proxmoxNodeAPTRepositoriesGrid',
51 title
: gettext('APT Repositories'),
53 cls
: 'proxmox-apt-repos', // to allow applying styling to general components with local effect
57 text
: gettext('Reload'),
58 iconCls
: 'fa fa-refresh',
61 me
.up('proxmoxNodeAPTRepositories').reload();
74 xtype
: 'proxmoxButton',
75 text
: gettext('Enable'),
76 defaultText
: gettext('Enable'),
77 altText
: gettext('Disable'),
78 id
: 'repoEnableButton',
80 handler: function(button
, event
, record
) {
82 let panel
= me
.up('proxmoxNodeAPTRepositories');
85 path
: record
.data
.Path
,
86 index
: record
.data
.Index
,
87 enabled
: record
.data
.Enabled
? 0 : 1, // invert
90 if (panel
.digest
!== undefined) {
91 params
.digest
= panel
.digest
;
94 Proxmox
.Utils
.API2Request({
95 url
: `/nodes/${panel.nodename}/apt/repositories`,
98 failure: function(response
, opts
) {
99 Ext
.Msg
.alert(gettext('Error'), response
.htmlStatus
);
102 success: function(response
, opts
) {
108 render: function(btn
) {
109 // HACK: calculate the max button width on first render to avoid toolbar glitches
110 let defSize
= btn
.getSize().width
;
112 btn
.setText(btn
.altText
);
113 let altSize
= btn
.getSize().width
;
115 btn
.setText(btn
.defaultText
);
116 btn
.setSize({ width
: altSize
> defSize
? altSize
: defSize
});
122 sortableColumns
: false,
126 xtype
: 'checkcolumn',
127 header
: gettext('Enabled'),
128 dataIndex
: 'Enabled',
130 beforecheckchange
: () => false, // veto, we don't want to allow inline change - to subtle
135 header
: gettext('Types'),
137 renderer: function(types
, cell
, record
) {
138 return types
.join(' ');
143 header
: gettext('URIs'),
145 renderer: function(uris
, cell
, record
) {
146 return uris
.join(' ');
151 header
: gettext('Suites'),
153 renderer: function(suites
, cell
, record
) {
154 return suites
.join(' ');
159 header
: gettext('Components'),
160 dataIndex
: 'Components',
161 renderer: function(components
, cell
, record
) {
162 return components
.join(' ');
167 header
: gettext('Options'),
168 dataIndex
: 'Options',
169 renderer: function(options
, cell
, record
) {
174 let filetype
= record
.data
.FileType
;
177 options
.forEach(function(option
) {
178 let key
= option
.Key
;
179 if (filetype
=== 'list') {
180 let values
= option
.Values
.join(',');
181 text
+= `${key}=${values} `;
182 } else if (filetype
=== 'sources') {
183 let values
= option
.Values
.join(' ');
184 text
+= `${key}: ${values}<br>`;
186 throw "unkown file type";
194 header
: gettext('Origin'),
199 header
: gettext('Comment'),
200 dataIndex
: 'Comment',
205 addAdditionalInfos: function(gridData
, infos
) {
211 let addLine = function(obj
, key
, line
) {
220 for (const info
of infos
) {
221 const key
= `${info.path}:${info.index}`;
222 if (info
.kind
=== 'warning' ||
223 (info
.kind
=== 'ignore-pre-upgrade-warning' && !me
.majorUpgradeAllowed
)
225 addLine(warnings
, key
, gettext('Warning') + ": " + info
.message
);
226 } else if (info
.kind
=== 'origin') {
227 origins
[key
] = info
.message
;
231 gridData
.forEach(function(record
) {
232 const key
= `${record.Path}:${record.Index}`;
233 record
.Origin
= origins
[key
];
236 me
.rowBodyFeature
.getAdditionalData = function(innerData
, rowIndex
, record
, orig
) {
237 let headerCt
= this.view
.headerCt
;
238 let colspan
= headerCt
.getColumnCount();
240 const key
= `${innerData.Path}:${innerData.Index}`;
241 const warning_text
= warnings
[key
];
244 rowBody
: '<div style="color: red; white-space: pre-line">' +
245 Ext
.String
.htmlEncode(warning_text
) + '</div>',
246 rowBodyCls
: warning_text
? '' : Ext
.baseCSSPrefix
+ 'grid-row-body-hidden',
247 rowBodyColspan
: colspan
,
252 initComponent: function() {
256 throw "no node name specified";
259 let store
= Ext
.create('Ext.data.Store', {
260 model
: 'apt-repolist',
270 let rowBodyFeature
= Ext
.create('Ext.grid.feature.RowBody', {});
272 let groupingFeature
= Ext
.create('Ext.grid.feature.Grouping', {
273 groupHeaderTpl
: '{[ "File: " + values.name ]} ({rows.length} ' +
274 'repositor{[values.rows.length > 1 ? "ies" : "y"]})',
275 enableGroupingMenu
: false,
278 let sm
= Ext
.create('Ext.selection.RowModel', {});
283 rowBodyFeature
: rowBodyFeature
,
284 features
: [groupingFeature
, rowBodyFeature
],
291 selectionchange: function() {
294 if (me
.onSelectionChange
) {
295 let sm
= me
.getSelectionModel();
296 let rec
= sm
.getSelection()[0];
298 me
.onSelectionChange(rec
, sm
);
304 Ext
.define('Proxmox.node.APTRepositories', {
305 extend
: 'Ext.panel.Panel',
306 xtype
: 'proxmoxNodeAPTRepositories',
307 mixins
: ['Proxmox.Mixin.CBind'],
311 product
: 'Proxmox VE', // default
315 product
: 'Proxmox VE', // default
317 subscriptionActive
: '',
318 noSubscriptionRepo
: '',
322 noErrors
: (get) => get('errorCount') === 0,
323 mainWarning: function(get) {
324 // Not yet initialized
325 if (get('subscriptionActive') === '' ||
326 get('enterpriseRepo') === '') {
330 let icon
= `<i class='fa fa-fw fa-exclamation-triangle critical'></i>`;
331 let fmt
= (msg
) => `<div class="black">${icon}${gettext('Warning')}: ${msg}</div>`;
333 if (!get('subscriptionActive') && get('enterpriseRepo')) {
334 return fmt(gettext('The enterprise repository is enabled, but there is no active subscription!'));
337 if (get('noSubscriptionRepo')) {
338 return fmt(gettext('The no-subscription repository is not recommended for production use!'));
341 if (!get('enterpriseRepo') && !get('noSubscriptionRepo')) {
342 let msg
= Ext
.String
.format(gettext('No {0} repository is enabled!'), get('product'));
353 title
: gettext('Warning'),
354 name
: 'repositoriesMainWarning',
357 title
: '{mainWarning}',
358 hidden
: '{!mainWarning}',
362 xtype
: 'proxmoxNodeAPTRepositoriesErrors',
363 name
: 'repositoriesErrors',
366 hidden
: '{noErrors}',
370 xtype
: 'proxmoxNodeAPTRepositoriesGrid',
371 name
: 'repositoriesGrid',
373 nodename
: '{nodename}',
375 majorUpgradeAllowed
: false, // TODO get release information from an API call?
376 onSelectionChange: function(rec
, sm
) {
379 let btn
= me
.up('proxmoxNodeAPTRepositories').down('#repoEnableButton');
380 btn
.setText(rec
.get('Enabled') ? gettext('Disable') : gettext('Enable'));
386 check_subscription: function() {
388 let vm
= me
.getViewModel();
390 Proxmox
.Utils
.API2Request({
391 url
: `/nodes/${me.nodename}/subscription`,
393 failure
: (response
, opts
) => Ext
.Msg
.alert(gettext('Error'), response
.htmlStatus
),
394 success: function(response
, opts
) {
395 const res
= response
.result
;
396 const subscription
= !(!res
|| !res
.data
|| res
.data
.status
.toLowerCase() !== 'active');
397 vm
.set('subscriptionActive', subscription
);
402 updateStandardRepos: function(standardRepos
) {
404 let vm
= me
.getViewModel();
406 let menu
= me
.down('#addMenu');
409 for (const standardRepo
of standardRepos
) {
410 const handle
= standardRepo
.handle
;
411 const status
= standardRepo
.status
;
413 if (handle
=== "enterprise") {
414 vm
.set('enterpriseRepo', status
);
415 } else if (handle
=== "no-subscription") {
416 vm
.set('noSubscriptionRepo', status
);
419 let status_text
= '';
420 if (status
!== undefined && status
!== null) {
421 status_text
= Ext
.String
.format(
423 gettext('configured'),
424 status
? gettext('enabled') : gettext('disabled'),
429 text
: standardRepo
.name
+ status_text
,
430 disabled
: status
!== undefined && status
!== null,
432 handler: function(menuItem
) {
433 Proxmox
.Utils
.checked_command(() => {
435 handle
: menuItem
.repoHandle
,
438 if (me
.digest
!== undefined) {
439 params
.digest
= me
.digest
;
442 Proxmox
.Utils
.API2Request({
443 url
: `/nodes/${me.nodename}/apt/repositories`,
446 failure: function(response
, opts
) {
447 Ext
.Msg
.alert(gettext('Error'), response
.htmlStatus
);
450 success: function(response
, opts
) {
462 let vm
= me
.getViewModel();
463 let repoGrid
= me
.down('proxmoxNodeAPTRepositoriesGrid');
464 let errorGrid
= me
.down('proxmoxNodeAPTRepositoriesErrors');
466 me
.store
.load(function(records
, operation
, success
) {
471 if (success
&& records
.length
> 0) {
472 let data
= records
[0].data
;
473 let files
= data
.files
;
474 errors
= data
.errors
;
475 digest
= data
.digest
;
477 files
.forEach(function(file
) {
478 for (let n
= 0; n
< file
.repositories
.length
; n
++) {
479 let repo
= file
.repositories
[n
];
480 repo
.Path
= file
.path
;
486 repoGrid
.addAdditionalInfos(gridData
, data
.infos
);
487 repoGrid
.store
.loadData(gridData
);
489 me
.updateStandardRepos(data
['standard-repos']);
494 vm
.set('errorCount', errors
.length
);
495 errorGrid
.store
.loadData(errors
);
498 me
.check_subscription();
502 activate: function() {
508 initComponent: function() {
512 throw "no node name specified";
515 let store
= Ext
.create('Ext.data.Store', {
518 url
: `/api2/json/nodes/${me.nodename}/apt/repositories`,
522 Ext
.apply(me
, { store
: store
});
524 Proxmox
.Utils
.monStoreErrors(me
, me
.store
, true);
528 me
.getViewModel().set('product', me
.product
);