mirror of
https://git.proxmox.com/git/proxmox-widget-toolkit
synced 2025-05-06 18:10:47 +00:00
node apt: cleanup and modernize code
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
7f14a081af
commit
261f558105
@ -1,7 +1,9 @@
|
|||||||
Ext.define('apt-pkglist', {
|
Ext.define('apt-pkglist', {
|
||||||
extend: 'Ext.data.Model',
|
extend: 'Ext.data.Model',
|
||||||
fields: ['Package', 'Title', 'Description', 'Section', 'Arch',
|
fields: [
|
||||||
'Priority', 'Version', 'OldVersion', 'ChangeLogUrl', 'Origin'],
|
'Package', 'Title', 'Description', 'Section', 'Arch', 'Priority', 'Version', 'OldVersion',
|
||||||
|
'ChangeLogUrl', 'Origin',
|
||||||
|
],
|
||||||
idProperty: 'Package',
|
idProperty: 'Package',
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -56,7 +58,7 @@ Ext.define('Proxmox.node.APT', {
|
|||||||
groupField: 'Origin',
|
groupField: 'Origin',
|
||||||
proxy: {
|
proxy: {
|
||||||
type: 'proxmox',
|
type: 'proxmox',
|
||||||
url: "/api2/json/nodes/" + me.nodename + "/apt/update",
|
url: `/api2/json/nodes/${me.nodename}/apt/update`,
|
||||||
},
|
},
|
||||||
sorters: [
|
sorters: [
|
||||||
{
|
{
|
||||||
@ -65,6 +67,7 @@ Ext.define('Proxmox.node.APT', {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
Proxmox.Utils.monStoreErrors(me, store, true);
|
||||||
|
|
||||||
let groupingFeature = Ext.create('Ext.grid.feature.Grouping', {
|
let groupingFeature = Ext.create('Ext.grid.feature.Grouping', {
|
||||||
groupHeaderTpl: '{[ "Origin: " + values.name ]} ({rows.length} Item{[values.rows.length > 1 ? "s" : ""]})',
|
groupHeaderTpl: '{[ "Origin: " + values.name ]} ({rows.length} Item{[values.rows.length > 1 ? "s" : ""]})',
|
||||||
@ -76,37 +79,24 @@ Ext.define('Proxmox.node.APT', {
|
|||||||
let headerCt = this.view.headerCt;
|
let headerCt = this.view.headerCt;
|
||||||
let colspan = headerCt.getColumnCount();
|
let colspan = headerCt.getColumnCount();
|
||||||
return {
|
return {
|
||||||
rowBody: '<div style="padding: 1em">' +
|
rowBody: `<div style="padding: 1em">${Ext.htmlEncode(data.Description)}</div>`,
|
||||||
Ext.String.htmlEncode(data.Description) +
|
|
||||||
'</div>',
|
|
||||||
rowBodyCls: me.full_description ? '' : Ext.baseCSSPrefix + 'grid-row-body-hidden',
|
rowBodyCls: me.full_description ? '' : Ext.baseCSSPrefix + 'grid-row-body-hidden',
|
||||||
rowBodyColspan: colspan,
|
rowBodyColspan: colspan,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
let reload = function() {
|
|
||||||
store.load();
|
|
||||||
};
|
|
||||||
|
|
||||||
Proxmox.Utils.monStoreErrors(me, store, true);
|
|
||||||
|
|
||||||
let apt_command = function(cmd) {
|
let apt_command = function(cmd) {
|
||||||
Proxmox.Utils.API2Request({
|
Proxmox.Utils.API2Request({
|
||||||
url: "/nodes/" + me.nodename + "/apt/" + cmd,
|
url: `/nodes/${me.nodename}/apt/${cmd}`,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
failure: function(response, opts) {
|
success: ({ result }) => Ext.create('Proxmox.window.TaskViewer', {
|
||||||
Ext.Msg.alert(gettext('Error'), response.htmlStatus);
|
autoShow: true,
|
||||||
},
|
upid: result.data,
|
||||||
success: function(response, opts) {
|
listeners: {
|
||||||
let upid = response.result.data;
|
close: () => store.load(),
|
||||||
|
},
|
||||||
let win = Ext.create('Proxmox.window.TaskViewer', {
|
}),
|
||||||
upid: upid,
|
|
||||||
});
|
|
||||||
win.show();
|
|
||||||
me.mon(win, 'close', reload);
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -114,13 +104,12 @@ Ext.define('Proxmox.node.APT', {
|
|||||||
|
|
||||||
let update_btn = new Ext.Button({
|
let update_btn = new Ext.Button({
|
||||||
text: gettext('Refresh'),
|
text: gettext('Refresh'),
|
||||||
handler: function() {
|
handler: () => Proxmox.Utils.checked_command(function() { apt_command('update'); }),
|
||||||
Proxmox.Utils.checked_command(function() { apt_command('update'); });
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let show_changelog = function(rec) {
|
let show_changelog = function(rec) {
|
||||||
if (!rec || !rec.data || !(rec.data.ChangeLogUrl && rec.data.Package)) {
|
if (!rec?.data?.ChangeLogUrl || !rec?.data?.Package) {
|
||||||
|
console.debug('cannot show changelog, missing Package and/or ChangeLogUrl', rec);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,15 +155,8 @@ Ext.define('Proxmox.node.APT', {
|
|||||||
text: gettext('Changelog'),
|
text: gettext('Changelog'),
|
||||||
selModel: sm,
|
selModel: sm,
|
||||||
disabled: true,
|
disabled: true,
|
||||||
enableFn: function(rec) {
|
enableFn: rec => !!rec?.data?.ChangeLogUrl && !!rec?.data?.Package,
|
||||||
if (!rec || !rec.data || !(rec.data.ChangeLogUrl && rec.data.Package)) {
|
handler: (b, e, rec) => show_changelog(rec),
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
handler: function(b, e, rec) {
|
|
||||||
show_changelog(rec);
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let verbose_desc_checkbox = new Ext.form.field.Checkbox({
|
let verbose_desc_checkbox = new Ext.form.field.Checkbox({
|
||||||
@ -205,10 +187,8 @@ Ext.define('Proxmox.node.APT', {
|
|||||||
},
|
},
|
||||||
features: [groupingFeature, rowBodyFeature],
|
features: [groupingFeature, rowBodyFeature],
|
||||||
listeners: {
|
listeners: {
|
||||||
activate: reload,
|
activate: () => store.load(),
|
||||||
itemdblclick: function(v, rec) {
|
itemdblclick: (v, rec) => show_changelog(rec),
|
||||||
show_changelog(rec);
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user