]>
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 header
: gettext('Official'),
127 dataIndex
: 'OfficialHost',
128 renderer: function(value
, cell
, record
) {
129 let icon
= (cls
) => `<i class="fa fa-fw ${cls}"></i>`;
131 const enabled
= record
.data
.Enabled
;
133 if (value
=== undefined || value
=== null) {
134 return icon('fa-question-circle-o');
137 return icon('fa-times ' + (enabled
? 'critical' : 'faded'));
139 return icon('fa-check ' + (enabled
? 'good' : 'faded'));
144 header
: gettext('Enabled'),
145 dataIndex
: 'Enabled',
146 renderer
: Proxmox
.Utils
.format_enabled_toggle
,
150 header
: gettext('Types'),
152 renderer: function(types
, cell
, record
) {
153 return types
.join(' ');
158 header
: gettext('URIs'),
160 renderer: function(uris
, cell
, record
) {
161 return uris
.join(' ');
166 header
: gettext('Suites'),
168 renderer: function(suites
, cell
, record
) {
169 return suites
.join(' ');
174 header
: gettext('Components'),
175 dataIndex
: 'Components',
176 renderer: function(components
, cell
, record
) {
177 return components
.join(' ');
182 header
: gettext('Options'),
183 dataIndex
: 'Options',
184 renderer: function(options
, cell
, record
) {
189 let filetype
= record
.data
.FileType
;
192 options
.forEach(function(option
) {
193 let key
= option
.Key
;
194 if (filetype
=== 'list') {
195 let values
= option
.Values
.join(',');
196 text
+= `${key}=${values} `;
197 } else if (filetype
=== 'sources') {
198 let values
= option
.Values
.join(' ');
199 text
+= `${key}: ${values}<br>`;
201 throw "unkown file type";
209 header
: gettext('Comment'),
210 dataIndex
: 'Comment',
215 addAdditionalInfos: function(gridData
, infos
) {
219 let officialHosts
= {};
221 let addLine = function(obj
, key
, line
) {
230 for (const info
of infos
) {
231 const key
= `${info.path}:${info.index}`;
232 if (info
.kind
=== 'warning' ||
233 (info
.kind
=== 'ignore-pre-upgrade-warning' && !me
.majorUpgradeAllowed
)
235 addLine(warnings
, key
, gettext('Warning') + ": " + info
.message
);
236 } else if (info
.kind
=== 'badge' && info
.message
=== 'official host name') {
237 officialHosts
[key
] = true;
241 gridData
.forEach(function(record
) {
242 const key
= `${record.Path}:${record.Index}`;
243 record
.OfficialHost
= !!officialHosts
[key
];
246 me
.rowBodyFeature
.getAdditionalData = function(innerData
, rowIndex
, record
, orig
) {
247 let headerCt
= this.view
.headerCt
;
248 let colspan
= headerCt
.getColumnCount();
250 const key
= `${innerData.Path}:${innerData.Index}`;
251 const warning_text
= warnings
[key
];
254 rowBody
: '<div style="color: red; white-space: pre-line">' +
255 Ext
.String
.htmlEncode(warning_text
) + '</div>',
256 rowBodyCls
: warning_text
? '' : Ext
.baseCSSPrefix
+ 'grid-row-body-hidden',
257 rowBodyColspan
: colspan
,
262 initComponent: function() {
266 throw "no node name specified";
269 let store
= Ext
.create('Ext.data.Store', {
270 model
: 'apt-repolist',
280 let rowBodyFeature
= Ext
.create('Ext.grid.feature.RowBody', {});
282 let groupingFeature
= Ext
.create('Ext.grid.feature.Grouping', {
283 groupHeaderTpl
: '{[ "File: " + values.name ]} ({rows.length} ' +
284 'repositor{[values.rows.length > 1 ? "ies" : "y"]})',
285 enableGroupingMenu
: false,
288 let sm
= Ext
.create('Ext.selection.RowModel', {});
293 rowBodyFeature
: rowBodyFeature
,
294 features
: [groupingFeature
, rowBodyFeature
],
301 selectionchange: function() {
304 if (me
.onSelectionChange
) {
305 let sm
= me
.getSelectionModel();
306 let rec
= sm
.getSelection()[0];
308 me
.onSelectionChange(rec
, sm
);
314 Ext
.define('Proxmox.node.APTRepositories', {
315 extend
: 'Ext.panel.Panel',
316 xtype
: 'proxmoxNodeAPTRepositories',
317 mixins
: ['Proxmox.Mixin.CBind'],
324 subscriptionActive
: '',
325 noSubscriptionRepo
: '',
329 noErrors
: (get) => get('errorCount') === 0,
330 mainWarning: function(get) {
331 // Not yet initialized
332 if (get('subscriptionActive') === '' ||
333 get('enterpriseRepo') === '') {
337 let withStyle
= (msg
) => "<div style='color:red;'><i class='fa fa-fw " +
338 "fa-exclamation-triangle'></i>" + gettext('Warning') + ': ' + msg
+ "</div>";
340 if (!get('subscriptionActive') && get('enterpriseRepo')) {
341 return withStyle(gettext('The enterprise repository is ' +
342 'enabled, but there is no active subscription!'));
345 if (get('noSubscriptionRepo')) {
346 return withStyle(gettext('The no-subscription repository is ' +
347 'not recommended for production use!'));
350 if (!get('enterpriseRepo') && !get('noSubscriptionRepo')) {
351 return withStyle(gettext('No Proxmox repository is enabled!'));
361 title
: gettext('Warning'),
362 name
: 'repositoriesMainWarning',
365 title
: '{mainWarning}',
366 hidden
: '{!mainWarning}',
370 xtype
: 'proxmoxNodeAPTRepositoriesErrors',
371 name
: 'repositoriesErrors',
374 hidden
: '{noErrors}',
378 xtype
: 'proxmoxNodeAPTRepositoriesGrid',
379 name
: 'repositoriesGrid',
381 nodename
: '{nodename}',
383 majorUpgradeAllowed
: false, // TODO get release information from an API call?
384 onSelectionChange: function(rec
, sm
) {
387 let btn
= me
.up('proxmoxNodeAPTRepositories').down('#repoEnableButton');
388 btn
.setText(rec
.get('Enabled') ? gettext('Disable') : gettext('Enable'));
394 check_subscription: function() {
396 let vm
= me
.getViewModel();
398 Proxmox
.Utils
.API2Request({
399 url
: `/nodes/${me.nodename}/subscription`,
401 failure
: (response
, opts
) => Ext
.Msg
.alert(gettext('Error'), response
.htmlStatus
),
402 success: function(response
, opts
) {
403 const res
= response
.result
;
404 const subscription
= !(!res
|| !res
.data
|| res
.data
.status
.toLowerCase() !== 'active');
405 vm
.set('subscriptionActive', subscription
);
410 updateStandardRepos: function(standardRepos
) {
412 let vm
= me
.getViewModel();
414 let menu
= me
.down('#addMenu');
417 for (const standardRepo
of standardRepos
) {
418 const handle
= standardRepo
.handle
;
419 const status
= standardRepo
.status
;
421 if (handle
=== "enterprise") {
422 vm
.set('enterpriseRepo', status
);
423 } else if (handle
=== "no-subscription") {
424 vm
.set('noSubscriptionRepo', status
);
427 let status_text
= '';
428 if (status
!== undefined && status
!== null) {
429 status_text
= Ext
.String
.format(
431 gettext('configured'),
432 status
? gettext('enabled') : gettext('disabled'),
437 text
: standardRepo
.name
+ status_text
,
438 disabled
: status
!== undefined && status
!== null,
440 handler: function(menuItem
) {
441 Proxmox
.Utils
.checked_command(() => {
443 handle
: menuItem
.repoHandle
,
446 if (me
.digest
!== undefined) {
447 params
.digest
= me
.digest
;
450 Proxmox
.Utils
.API2Request({
451 url
: `/nodes/${me.nodename}/apt/repositories`,
454 failure: function(response
, opts
) {
455 Ext
.Msg
.alert(gettext('Error'), response
.htmlStatus
);
458 success: function(response
, opts
) {
470 let vm
= me
.getViewModel();
471 let repoGrid
= me
.down('proxmoxNodeAPTRepositoriesGrid');
472 let errorGrid
= me
.down('proxmoxNodeAPTRepositoriesErrors');
474 me
.store
.load(function(records
, operation
, success
) {
479 if (success
&& records
.length
> 0) {
480 let data
= records
[0].data
;
481 let files
= data
.files
;
482 errors
= data
.errors
;
483 digest
= data
.digest
;
485 files
.forEach(function(file
) {
486 for (let n
= 0; n
< file
.repositories
.length
; n
++) {
487 let repo
= file
.repositories
[n
];
488 repo
.Path
= file
.path
;
494 repoGrid
.addAdditionalInfos(gridData
, data
.infos
);
495 repoGrid
.store
.loadData(gridData
);
497 me
.updateStandardRepos(data
['standard-repos']);
502 vm
.set('errorCount', errors
.length
);
503 errorGrid
.store
.loadData(errors
);
506 me
.check_subscription();
510 activate: function() {
516 initComponent: function() {
520 throw "no node name specified";
523 let store
= Ext
.create('Ext.data.Store', {
526 url
: `/api2/json/nodes/${me.nodename}/apt/repositories`,
530 Ext
.apply(me
, { store
: store
});
532 Proxmox
.Utils
.monStoreErrors(me
, me
.store
, true);