]>
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'),
27 initComponent: function() {
30 if (!me
.repoInfo
|| me
.repoInfo
.length
=== 0) {
31 throw "repository information not initialized";
34 let description
= Ext
.create('Ext.form.field.Display', {
35 fieldLabel
: gettext('Description'),
39 let status
= Ext
.create('Ext.form.field.Display', {
40 fieldLabel
: gettext('Status'),
42 renderer: function(value
) {
43 let statusText
= gettext('Not yet configured');
45 statusText
= Ext
.String
.format(
47 gettext('Configured'),
48 value
? gettext('enabled') : gettext('disabled'),
56 let repoSelector
= Ext
.create('Proxmox.form.KVComboBox', {
57 fieldLabel
: gettext('Repository'),
58 xtype
: 'proxmoxKVComboBox',
61 comboItems
: me
.repoInfo
.map(info
=> [info
.handle
, info
.name
]),
63 const handle
= this.value
;
69 const info
= me
.repoInfo
.find(elem
=> elem
.handle
=== handle
);
76 return info
.status
=== undefined || info
.status
=== null;
79 change: function(f
, value
) {
80 const info
= me
.repoInfo
.find(elem
=> elem
.handle
=== value
);
81 description
.setValue(info
.description
);
82 status
.setValue(info
.status
);
87 repoSelector
.setValue(me
.repoInfo
[0].handle
);
97 repoSelector
: repoSelector
,
104 Ext
.define('Proxmox.node.APTRepositoriesErrors', {
105 extend
: 'Ext.grid.GridPanel',
107 xtype
: 'proxmoxNodeAPTRepositoriesErrors',
109 title
: gettext('Errors'),
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/json/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,
240 xtype
: 'checkcolumn',
241 header
: gettext('Enabled'),
242 dataIndex
: 'Enabled',
244 beforecheckchange
: () => false, // veto, we don't want to allow inline change - to subtle
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
, cell
, record
) {
268 return suites
.join(' ');
273 header
: gettext('Components'),
274 dataIndex
: 'Components',
275 renderer: function(components
, cell
, record
) {
276 return components
.join(' ');
281 header
: gettext('Options'),
282 dataIndex
: 'Options',
283 renderer: function(options
, cell
, record
) {
288 let filetype
= record
.data
.FileType
;
291 options
.forEach(function(option
) {
292 let key
= option
.Key
;
293 if (filetype
=== 'list') {
294 let values
= option
.Values
.join(',');
295 text
+= `${key}=${values} `;
296 } else if (filetype
=== 'sources') {
297 let values
= option
.Values
.join(' ');
298 text
+= `${key}: ${values}<br>`;
300 throw "unkown file type";
308 header
: gettext('Origin'),
311 renderer
: (value
, meta
, rec
) => {
312 let cls
= 'fa fa-fw fa-question-circle-o';
313 if (value
.match(/^\s*Proxmox\s*$/i)) {
314 cls
= 'pmx-itype-icon pmx-itype-icon-proxmox-x';
315 } else if (value
.match(/^\s*Debian\s*$/i)) {
316 cls
= 'pmx-itype-icon pmx-itype-icon-debian-swirl';
318 return `<i class='${cls}'></i> ${value}`;
322 header
: gettext('Comment'),
323 dataIndex
: 'Comment',
328 addAdditionalInfos: function(gridData
, infos
) {
334 let addLine = function(obj
, key
, line
) {
343 for (const info
of infos
) {
344 const key
= `${info.path}:${info.index}`;
345 if (info
.kind
=== 'warning' ||
346 (info
.kind
=== 'ignore-pre-upgrade-warning' && !me
.majorUpgradeAllowed
)
348 addLine(warnings
, key
, gettext('Warning') + ": " + info
.message
);
349 } else if (info
.kind
=== 'origin') {
350 origins
[key
] = info
.message
;
354 gridData
.forEach(function(record
) {
355 const key
= `${record.Path}:${record.Index}`;
356 record
.Origin
= origins
[key
];
359 me
.rowBodyFeature
.getAdditionalData = function(innerData
, rowIndex
, record
, orig
) {
360 let headerCt
= this.view
.headerCt
;
361 let colspan
= headerCt
.getColumnCount();
363 const key
= `${innerData.Path}:${innerData.Index}`;
364 const warning_text
= warnings
[key
];
367 rowBody
: '<div style="color: red; white-space: pre-line">' +
368 Ext
.String
.htmlEncode(warning_text
) + '</div>',
369 rowBodyCls
: warning_text
? '' : Ext
.baseCSSPrefix
+ 'grid-row-body-hidden',
370 rowBodyColspan
: colspan
,
375 initComponent: function() {
379 throw "no node name specified";
382 let store
= Ext
.create('Ext.data.Store', {
383 model
: 'apt-repolist',
393 let rowBodyFeature
= Ext
.create('Ext.grid.feature.RowBody', {});
395 let groupingFeature
= Ext
.create('Ext.grid.feature.Grouping', {
396 groupHeaderTpl
: '{[ "File: " + values.name ]} ({rows.length} ' +
397 'repositor{[values.rows.length > 1 ? "ies" : "y"]})',
398 enableGroupingMenu
: false,
401 let sm
= Ext
.create('Ext.selection.RowModel', {});
406 rowBodyFeature
: rowBodyFeature
,
407 features
: [groupingFeature
, rowBodyFeature
],
414 Ext
.define('Proxmox.node.APTRepositories', {
415 extend
: 'Ext.panel.Panel',
416 xtype
: 'proxmoxNodeAPTRepositories',
417 mixins
: ['Proxmox.Mixin.CBind'],
421 product
: 'Proxmox VE', // default
424 xclass
: 'Ext.app.ViewController',
426 selectionChange: function(grid
, selection
) {
428 if (!selection
|| selection
.length
< 1) {
431 let rec
= selection
[0];
432 let vm
= me
.getViewModel();
433 vm
.set('selectionenabled', rec
.get('Enabled'));
439 product
: 'Proxmox VE', // default
441 subscriptionActive
: '',
442 noSubscriptionRepo
: '',
444 selectionenabled
: false,
447 noErrors
: (get) => get('errorCount') === 0,
448 enableButtonText
: (get) => get('selectionenabled')
449 ? gettext('Disable') : gettext('Enable'),
450 mainWarning: function(get) {
451 // Not yet initialized
452 if (get('subscriptionActive') === '' ||
453 get('enterpriseRepo') === '') {
457 let icon
= `<i class='fa fa-fw fa-exclamation-triangle critical'></i>`;
458 let fmt
= (msg
) => `<div class="black">${icon}${gettext('Warning')}: ${msg}</div>`;
460 if (!get('subscriptionActive') && get('enterpriseRepo')) {
461 return fmt(gettext('The enterprise repository is enabled, but there is no active subscription!'));
464 if (get('noSubscriptionRepo')) {
465 return fmt(gettext('The no-subscription repository is not recommended for production use!'));
468 if (!get('enterpriseRepo') && !get('noSubscriptionRepo')) {
469 let msg
= Ext
.String
.format(gettext('No {0} repository is enabled!'), get('product'));
487 baseCls
: 'x-panel-header',
489 hidden
: '{!mainWarning}',
490 title
: '{mainWarning}',
496 hidden
: '{!mainWarning}',
501 xtype
: 'proxmoxNodeAPTRepositoriesErrors',
502 name
: 'repositoriesErrors',
506 hidden
: '{noErrors}',
510 xtype
: 'proxmoxNodeAPTRepositoriesGrid',
511 name
: 'repositoriesGrid',
513 nodename
: '{nodename}',
515 majorUpgradeAllowed
: false, // TODO get release information from an API call?
517 selectionchange
: 'selectionChange',
522 check_subscription: function() {
524 let vm
= me
.getViewModel();
526 Proxmox
.Utils
.API2Request({
527 url
: `/nodes/${me.nodename}/subscription`,
529 failure
: (response
, opts
) => Ext
.Msg
.alert(gettext('Error'), response
.htmlStatus
),
530 success: function(response
, opts
) {
531 const res
= response
.result
;
532 const subscription
= !(!res
|| !res
.data
|| res
.data
.status
.toLowerCase() !== 'active');
533 vm
.set('subscriptionActive', subscription
);
538 updateStandardRepos: function(standardRepos
) {
540 let vm
= me
.getViewModel();
542 let addButton
= me
.down('#addButton');
543 addButton
.repoInfo
= [];
545 for (const standardRepo
of standardRepos
) {
546 const handle
= standardRepo
.handle
;
547 const status
= standardRepo
.status
;
549 if (handle
=== "enterprise") {
550 vm
.set('enterpriseRepo', status
);
551 } else if (handle
=== "no-subscription") {
552 vm
.set('noSubscriptionRepo', status
);
555 addButton
.repoInfo
.push(standardRepo
);
556 addButton
.digest
= me
.digest
;
559 addButton
.setDisabled(false);
564 let vm
= me
.getViewModel();
565 let repoGrid
= me
.down('proxmoxNodeAPTRepositoriesGrid');
566 let errorGrid
= me
.down('proxmoxNodeAPTRepositoriesErrors');
568 me
.store
.load(function(records
, operation
, success
) {
573 if (success
&& records
.length
> 0) {
574 let data
= records
[0].data
;
575 let files
= data
.files
;
576 errors
= data
.errors
;
577 digest
= data
.digest
;
579 files
.forEach(function(file
) {
580 for (let n
= 0; n
< file
.repositories
.length
; n
++) {
581 let repo
= file
.repositories
[n
];
582 repo
.Path
= file
.path
;
588 repoGrid
.addAdditionalInfos(gridData
, data
.infos
);
589 repoGrid
.store
.loadData(gridData
);
591 me
.updateStandardRepos(data
['standard-repos']);
596 vm
.set('errorCount', errors
.length
);
597 errorGrid
.store
.loadData(errors
);
600 me
.check_subscription();
604 activate: function() {
610 initComponent: function() {
614 throw "no node name specified";
617 let store
= Ext
.create('Ext.data.Store', {
620 url
: `/api2/json/nodes/${me.nodename}/apt/repositories`,
624 Ext
.apply(me
, { store
: store
});
626 Proxmox
.Utils
.monStoreErrors(me
, me
.store
, true);
630 me
.getViewModel().set('product', me
.product
);