proxmox-backup/www/config/GCView.js
Stefan Lendl db3fd2132d fix #3217: ui: global prune and gc job view
In the global datastore view, extend the prune view to display gc job
status as a table.  Use the same widget in the local view and dispaly gc
job status as a single row.

The local PruneAndGC view is parameterized (cbind) with the datastore.
At initialization the only row is selected.  This allows the rest of the
grid to act on selected rows and it requires far less special casing if
the datastore is set on the view or not.

Having a single row always selected and therefore highlighted, is
visually not appealing.  Therefore, highlighting of selected rows is
disabled in the local view.

Moved GCView to different file and enhanced it with last, next run,
status and duration. Added button to show task log.

Changed `render_task_status()` to also take in account upids stored in
other 'columns'.

Signed-off-by: Stefan Lendl <s.lendl@proxmox.com>
  [LW: include ref to bugzilla in commit message]
Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
Originally-by: Gabriel Goller <g.goller@proxmox.com>
Tested-by: Gabriel Goller <g.goller@proxmox.com>
Reviewd-by: Gabriel Goller <g.goller@proxmox.com>
Tested-by: Lukas Wagner <l.wagner@proxmox.com>
Reviewed-by: Lukas Wagner <l.wagner@proxmox.com>
2024-04-22 13:58:08 +02:00

208 lines
4.6 KiB
JavaScript

Ext.define('pbs-gc-jobs-status', {
extend: 'Ext.data.Model',
fields: [
'store', 'last-run-upid', 'removed-chunks', 'pending-chunks', 'schedule',
'next-run', 'last-run-endtime', 'last-run-state',
{
name: 'duration',
calculate: function(data) {
let endtime = data['last-run-endtime'];
if (!endtime) return undefined;
let task = Proxmox.Utils.parse_task_upid(data['last-run-upid']);
return endtime - task.starttime;
},
},
],
idProperty: 'store',
proxy: {
type: 'proxmox',
url: '/api2/json/admin/gc',
},
});
Ext.define('PBS.config.GCJobView', {
extend: 'Ext.grid.GridPanel',
alias: 'widget.pbsGCJobView',
stateful: true,
stateId: 'grid-gc-jobs-v1',
allowDeselect: false,
title: gettext('Garbage Collect Jobs'),
controller: {
xclass: 'Ext.app.ViewController',
init: function(view) {
let params = {};
let store = view.getStore();
let proxy = store.rstore.getProxy();
if (view.datastore) {
params.store = view.datastore;
// after the store is loaded, select the row to enable the Edit,.. buttons
store.rstore.proxy.on({
'afterload': {
fn: () => view.getSelectionModel().select(0),
single: true,
},
});
// do not highlight the selected row
view.items.items[0].selectedItemCls = '';
view.items.items[0].overItemCls = '';
}
proxy.setExtraParams(params);
Proxmox.Utils.monStoreErrors(view, store.rstore);
},
getDatastoreName: function() {
return this.getView().getSelection()[0]?.data.store;
},
getData: function() {
let view = this.getView();
let datastore = this.getDatastoreName();
return view.getStore().getById(datastore).data;
},
editGCJob: function() {
let data = this.getData();
Ext.create('PBS.window.GCJobEdit', {
datastore: data.store,
id: data.store,
schedule: data.schedule,
listeners: {
destroy: () => this.reload(),
},
}).show();
},
garbageCollect: function() {
let datastore = this.getDatastoreName();
Proxmox.Utils.API2Request({
url: `/admin/datastore/${datastore}/gc`,
method: 'POST',
failure: function(response) {
Ext.Msg.alert(gettext('Error'), response.htmlStatus);
},
success: function(response, options) {
Ext.create('Proxmox.window.TaskViewer', {
upid: response.result.data,
}).show();
},
});
},
showTaskLog: function() {
let me = this;
let upid = this.getData()['last-run-upid'];
if (!upid) return;
Ext.create('Proxmox.window.TaskViewer', { upid }).show();
},
startStore: function() { this.getView().getStore().rstore.startUpdate(); },
stopStore: function() { this.getView().getStore().rstore.stopUpdate(); },
reload: function() { this.getView().getStore().rstore.load(); },
},
listeners: {
activate: 'startStore',
destroy: 'stopStore',
deactivate: 'stopStore',
itemdblclick: 'editGCJob',
},
store: {
type: 'diff',
autoDestroy: true,
autoDestroyRstore: true,
sorters: 'store',
rstore: {
type: 'update',
storeid: 'pbs-gc-jobs-status',
model: 'pbs-gc-jobs-status',
interval: 5000,
},
},
tbar: [
{
xtype: 'proxmoxButton',
text: gettext('Edit'),
handler: 'editGCJob',
enableFn: (rec) => !!rec,
disabled: true,
},
'-',
{
xtype: 'proxmoxButton',
text: gettext('Show Log'),
handler: 'showTaskLog',
enableFn: (rec) => !!rec.data["last-run-upid"],
disabled: true,
},
{
xtype: 'proxmoxButton',
text: gettext('Run now'),
handler: 'garbageCollect',
enableFn: (rec) => !!rec,
disabled: true,
},
],
columns: [
{
header: gettext('Datastore'),
dataIndex: 'store',
renderer: Ext.String.htmlEncode,
width: 120,
sortable: true,
hideable: false,
},
{
header: gettext('Schedule'),
dataIndex: 'schedule',
maxWidth: 220,
minWidth: 80,
flex: 1,
sortable: false,
hideable: false,
renderer: (value) => value ? value : Proxmox.Utils.NoneText,
},
{
header: gettext('Last GC'),
dataIndex: 'last-run-endtime',
renderer: PBS.Utils.render_optional_timestamp,
minWidth: 150,
sortable: true,
},
{
text: gettext('Duration'),
dataIndex: 'duration',
renderer: Proxmox.Utils.render_duration,
sortable: false,
width: 80,
},
{
header: gettext('Last Status'),
dataIndex: 'last-run-state',
renderer: PBS.Utils.render_task_status,
sortable: true,
flex: 3,
maxWidth: 100,
minWidth: 80,
},
{
header: gettext('Next Run'),
dataIndex: 'next-run',
renderer: PBS.Utils.render_next_task_run,
width: 150,
sortable: true,
},
],
});