]>
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',
111 title
: gettext('Errors'),
119 getRowClass
: () => 'proxmox-invalid-row',
124 header
: gettext('File'),
126 renderer
: value
=> `<i class='pve-grid-fa fa fa-fw fa-exclamation-triangle'></i>${value}`,
130 header
: gettext('Error'),
137 Ext
.define('Proxmox.node.APTRepositoriesGrid', {
138 extend
: 'Ext.grid.GridPanel',
139 xtype
: 'proxmoxNodeAPTRepositoriesGrid',
141 title
: gettext('APT Repositories'),
143 cls
: 'proxmox-apt-repos', // to allow applying styling to general components with local effect
149 text
: gettext('Reload'),
150 iconCls
: 'fa fa-refresh',
151 handler: function() {
153 me
.up('proxmoxNodeAPTRepositories').reload();
157 text
: gettext('Add'),
161 handler: function(button
, event
, record
) {
162 Proxmox
.Utils
.checked_command(() => {
164 let panel
= me
.up('proxmoxNodeAPTRepositories');
166 let extraParams
= {};
167 if (panel
.digest
!== undefined) {
168 extraParams
.digest
= panel
.digest
;
171 Ext
.create('Proxmox.window.APTRepositoryAdd', {
172 repoInfo
: me
.repoInfo
,
173 url
: `/api2/extjs/nodes/${panel.nodename}/apt/repositories`,
175 extraRequestParams
: extraParams
,
177 destroy: function() {
187 xtype
: 'proxmoxButton',
188 text
: gettext('Enable'),
189 defaultText
: gettext('Enable'),
190 altText
: gettext('Disable'),
191 id
: 'repoEnableButton',
194 text
: '{enableButtonText}',
196 handler: function(button
, event
, record
) {
198 let panel
= me
.up('proxmoxNodeAPTRepositories');
201 path
: record
.data
.Path
,
202 index
: record
.data
.Index
,
203 enabled
: record
.data
.Enabled
? 0 : 1, // invert
206 if (panel
.digest
!== undefined) {
207 params
.digest
= panel
.digest
;
210 Proxmox
.Utils
.API2Request({
211 url
: `/nodes/${panel.nodename}/apt/repositories`,
214 failure: function(response
, opts
) {
215 Ext
.Msg
.alert(gettext('Error'), response
.htmlStatus
);
218 success: function(response
, opts
) {
224 render: function(btn
) {
225 // HACK: calculate the max button width on first render to avoid toolbar glitches
226 let defSize
= btn
.getSize().width
;
228 btn
.setText(btn
.altText
);
229 let altSize
= btn
.getSize().width
;
231 btn
.setText(btn
.defaultText
);
232 btn
.setSize({ width
: altSize
> defSize
? altSize
: defSize
});
238 sortableColumns
: false,
241 getRowClass
: (record
, index
) => record
.get('Enabled') ? '' : 'proxmox-disabled-row',
246 xtype
: 'checkcolumn',
247 header
: gettext('Enabled'),
248 dataIndex
: 'Enabled',
250 beforecheckchange
: () => false, // veto, we don't want to allow inline change - to subtle
255 header
: gettext('Types'),
257 renderer: function(types
, cell
, record
) {
258 return types
.join(' ');
263 header
: gettext('URIs'),
265 renderer: function(uris
, cell
, record
) {
266 return uris
.join(' ');
271 header
: gettext('Suites'),
273 renderer: function(suites
, metaData
, record
) {
275 if (record
.data
.warnings
&& record
.data
.warnings
.length
> 0) {
276 let txt
= [gettext('Warning')];
277 record
.data
.warnings
.forEach((warning
) => {
278 if (warning
.property
=== 'Suites') {
279 txt
.push(warning
.message
);
282 metaData
.tdAttr
= `data-qtip="${Ext.htmlEncode(txt.join('<br>'))}"`;
283 if (record
.data
.Enabled
) {
284 metaData
.tdCls
= 'proxmox-invalid-row';
285 err
= '<i class="fa fa-fw critical fa-exclamation-circle"></i> ';
287 metaData
.tdCls
= 'proxmox-warning-row';
288 err
= '<i class="fa fa-fw warning fa-exclamation-circle"></i> ';
291 return suites
.join(' ') + err
;
296 header
: gettext('Components'),
297 dataIndex
: 'Components',
298 renderer: function(components
, cell
, record
) {
299 return components
.join(' ');
304 header
: gettext('Options'),
305 dataIndex
: 'Options',
306 renderer: function(options
, cell
, record
) {
311 let filetype
= record
.data
.FileType
;
314 options
.forEach(function(option
) {
315 let key
= option
.Key
;
316 if (filetype
=== 'list') {
317 let values
= option
.Values
.join(',');
318 text
+= `${key}=${values} `;
319 } else if (filetype
=== 'sources') {
320 let values
= option
.Values
.join(' ');
321 text
+= `${key}: ${values}<br>`;
323 throw "unkown file type";
331 header
: gettext('Origin'),
334 renderer
: (value
, meta
, rec
) => {
335 if (typeof value
!== 'string' || value
.length
=== 0) {
336 value
= gettext('Other');
338 let cls
= 'fa fa-fw fa-question-circle-o';
339 if (value
.match(/^\s*Proxmox\s*$/i)) {
340 cls
= 'pmx-itype-icon pmx-itype-icon-proxmox-x';
341 } else if (value
.match(/^\s*Debian\s*$/i)) {
342 cls
= 'pmx-itype-icon pmx-itype-icon-debian-swirl';
344 return `<i class='${cls}'></i> ${value}`;
348 header
: gettext('Comment'),
349 dataIndex
: 'Comment',
354 initComponent: function() {
358 throw "no node name specified";
361 let store
= Ext
.create('Ext.data.Store', {
362 model
: 'apt-repolist',
372 let groupingFeature
= Ext
.create('Ext.grid.feature.Grouping', {
373 groupHeaderTpl
: '{[ "File: " + values.name ]} ({rows.length} ' +
374 'repositor{[values.rows.length > 1 ? "ies" : "y"]})',
375 enableGroupingMenu
: false,
380 features
: [groupingFeature
],
387 Ext
.define('Proxmox.node.APTRepositories', {
388 extend
: 'Ext.panel.Panel',
389 xtype
: 'proxmoxNodeAPTRepositories',
390 mixins
: ['Proxmox.Mixin.CBind'],
394 product
: 'Proxmox VE', // default
397 xclass
: 'Ext.app.ViewController',
399 selectionChange: function(grid
, selection
) {
401 if (!selection
|| selection
.length
< 1) {
404 let rec
= selection
[0];
405 let vm
= me
.getViewModel();
406 vm
.set('selectionenabled', rec
.get('Enabled'));
412 product
: 'Proxmox VE', // default
414 subscriptionActive
: '',
415 noSubscriptionRepo
: '',
417 selectionenabled
: false,
420 noErrors
: (get) => get('errorCount') === 0,
421 enableButtonText
: (get) => get('selectionenabled')
422 ? gettext('Disable') : gettext('Enable'),
423 mainWarning: function(get) {
424 // Not yet initialized
425 if (get('subscriptionActive') === '' ||
426 get('enterpriseRepo') === '') {
430 let icon
= `<i class='fa fa-fw fa-exclamation-triangle critical'></i>`;
431 let fmt
= (msg
) => `<div class="black">${icon}${gettext('Warning')}: ${msg}</div>`;
433 if (!get('subscriptionActive') && get('enterpriseRepo')) {
434 return fmt(gettext('The enterprise repository is enabled, but there is no active subscription!'));
437 if (get('noSubscriptionRepo')) {
438 return fmt(gettext('The no-subscription repository is not recommended for production use!'));
441 if (!get('enterpriseRepo') && !get('noSubscriptionRepo')) {
442 let msg
= Ext
.String
.format(gettext('No {0} repository is enabled!'), get('product'));
460 baseCls
: 'x-panel-header',
462 hidden
: '{!mainWarning}',
463 title
: '{mainWarning}',
469 hidden
: '{!mainWarning}',
474 xtype
: 'proxmoxNodeAPTRepositoriesErrors',
475 name
: 'repositoriesErrors',
479 hidden
: '{noErrors}',
483 xtype
: 'proxmoxNodeAPTRepositoriesGrid',
484 name
: 'repositoriesGrid',
486 nodename
: '{nodename}',
488 majorUpgradeAllowed
: false, // TODO get release information from an API call?
490 selectionchange
: 'selectionChange',
495 check_subscription: function() {
497 let vm
= me
.getViewModel();
499 Proxmox
.Utils
.API2Request({
500 url
: `/nodes/${me.nodename}/subscription`,
502 failure
: (response
, opts
) => Ext
.Msg
.alert(gettext('Error'), response
.htmlStatus
),
503 success: function(response
, opts
) {
504 const res
= response
.result
;
505 const subscription
= !(!res
|| !res
.data
|| res
.data
.status
.toLowerCase() !== 'active');
506 vm
.set('subscriptionActive', subscription
);
511 updateStandardRepos: function(standardRepos
) {
513 let vm
= me
.getViewModel();
515 let addButton
= me
.down('#addButton');
516 addButton
.repoInfo
= [];
518 for (const standardRepo
of standardRepos
) {
519 const handle
= standardRepo
.handle
;
520 const status
= standardRepo
.status
;
522 if (handle
=== "enterprise") {
523 vm
.set('enterpriseRepo', status
);
524 } else if (handle
=== "no-subscription") {
525 vm
.set('noSubscriptionRepo', status
);
528 addButton
.repoInfo
.push(standardRepo
);
529 addButton
.digest
= me
.digest
;
532 addButton
.setDisabled(false);
537 let vm
= me
.getViewModel();
538 let repoGrid
= me
.down('proxmoxNodeAPTRepositoriesGrid');
539 let errorGrid
= me
.down('proxmoxNodeAPTRepositoriesErrors');
541 me
.store
.load(function(records
, operation
, success
) {
546 if (success
&& records
.length
> 0) {
547 let data
= records
[0].data
;
548 let files
= data
.files
;
549 errors
= data
.errors
;
550 digest
= data
.digest
;
553 for (const info
of data
.infos
) {
554 let path
= info
.path
;
555 let idx
= info
.index
;
560 if (!infos
[path
][idx
]) {
567 if (info
.kind
=== 'origin') {
568 infos
[path
][idx
].origin
= info
.message
;
569 } else if (info
.kind
=== 'warning' ||
570 (info
.kind
=== 'ignore-pre-upgrade-warning' && !repoGrid
.majorUpgradeAllowed
)
572 infos
[path
][idx
].warnings
.push(info
);
574 throw 'unknown info';
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
;
584 if (infos
[file
.path
] && infos
[file
.path
][n
]) {
585 repo
.Origin
= infos
[file
.path
][n
].origin
|| Proxmox
.Utils
.UnknownText
;
586 repo
.warnings
= infos
[file
.path
][n
].warnings
|| [];
592 repoGrid
.store
.loadData(gridData
);
594 me
.updateStandardRepos(data
['standard-repos']);
599 vm
.set('errorCount', errors
.length
);
600 errorGrid
.store
.loadData(errors
);
603 me
.check_subscription();
607 activate: function() {
613 initComponent: function() {
617 throw "no node name specified";
620 let store
= Ext
.create('Ext.data.Store', {
623 url
: `/api2/json/nodes/${me.nodename}/apt/repositories`,
627 Ext
.apply(me
, { store
: store
});
629 Proxmox
.Utils
.monStoreErrors(me
, me
.store
, true);
633 me
.getViewModel().set('product', me
.product
);