2020-03-26 10:17:15 +00:00
|
|
|
Ext.define('pbs-data-store-snapshots', {
|
2019-12-20 11:46:09 +00:00
|
|
|
extend: 'Ext.data.Model',
|
2019-12-20 16:04:45 +00:00
|
|
|
fields: [
|
|
|
|
'backup-type',
|
2019-12-22 09:43:57 +00:00
|
|
|
'backup-id',
|
|
|
|
{
|
2020-03-25 14:17:28 +00:00
|
|
|
name: 'backup-time',
|
2019-12-22 09:43:57 +00:00
|
|
|
type: 'date',
|
|
|
|
dateFormat: 'timestamp'
|
|
|
|
},
|
2019-12-20 16:04:45 +00:00
|
|
|
'files',
|
2020-03-25 14:17:28 +00:00
|
|
|
{ name: 'size', type: 'int' },
|
2020-03-26 10:17:15 +00:00
|
|
|
]
|
2019-12-20 11:46:09 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
Ext.define('PBS.DataStoreContent', {
|
2020-03-25 14:17:28 +00:00
|
|
|
extend: 'Ext.tree.Panel',
|
2019-12-20 11:46:09 +00:00
|
|
|
alias: 'widget.pbsDataStoreContent',
|
|
|
|
|
2020-03-25 14:17:28 +00:00
|
|
|
rootVisible: false,
|
2019-12-22 09:43:57 +00:00
|
|
|
|
2020-05-20 10:15:38 +00:00
|
|
|
title: gettext('Content'),
|
|
|
|
|
2019-12-20 16:17:44 +00:00
|
|
|
controller: {
|
|
|
|
xclass: 'Ext.app.ViewController',
|
|
|
|
|
|
|
|
init: function(view) {
|
|
|
|
if (!view.datastore) {
|
|
|
|
throw "no datastore specified";
|
|
|
|
}
|
|
|
|
|
2020-05-26 10:46:45 +00:00
|
|
|
this.store = Ext.create('Ext.data.Store', {
|
2020-03-26 10:17:15 +00:00
|
|
|
model: 'pbs-data-store-snapshots',
|
2020-03-25 14:17:28 +00:00
|
|
|
sorters: 'backup-group',
|
|
|
|
groupField: 'backup-group',
|
|
|
|
});
|
2020-05-26 10:46:45 +00:00
|
|
|
this.store.on('load', this.onLoad, this);
|
2020-03-25 14:17:28 +00:00
|
|
|
|
2019-12-20 16:17:44 +00:00
|
|
|
Proxmox.Utils.monStoreErrors(view, view.store, true);
|
|
|
|
this.reload(); // initial load
|
|
|
|
},
|
|
|
|
|
|
|
|
reload: function() {
|
2020-05-26 10:46:45 +00:00
|
|
|
let view = this.getView();
|
|
|
|
|
|
|
|
if (!view.store || !this.store) {
|
|
|
|
console.warn('cannot reload, no store(s)');
|
|
|
|
return;
|
|
|
|
}
|
2019-12-20 16:17:44 +00:00
|
|
|
|
2020-03-25 14:17:28 +00:00
|
|
|
let url = `/api2/json/admin/datastore/${view.datastore}/snapshots`;
|
2020-05-26 10:46:45 +00:00
|
|
|
this.store.setProxy({
|
2019-12-20 16:17:44 +00:00
|
|
|
type: 'proxmox',
|
|
|
|
url: url
|
|
|
|
});
|
2020-03-25 14:17:28 +00:00
|
|
|
|
2020-05-26 10:46:45 +00:00
|
|
|
this.store.load();
|
|
|
|
},
|
2020-03-25 14:17:28 +00:00
|
|
|
|
2020-05-26 10:46:45 +00:00
|
|
|
getRecordGroups: function(records) {
|
|
|
|
let groups = {};
|
|
|
|
|
|
|
|
for (const item of records) {
|
|
|
|
var btype = item.data["backup-type"];
|
|
|
|
let group = btype + "/" + item.data["backup-id"];
|
|
|
|
|
|
|
|
if (groups[group] !== undefined) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
var cls = '';
|
|
|
|
if (btype === 'vm') {
|
|
|
|
cls = 'fa-desktop';
|
|
|
|
} else if (btype === 'ct') {
|
|
|
|
cls = 'fa-cube';
|
|
|
|
} else if (btype === 'host') {
|
|
|
|
cls = 'fa-building';
|
|
|
|
} else {
|
|
|
|
console.warn(`got unkown backup-type '${btype}'`);
|
|
|
|
continue; // FIXME: auto render? what do?
|
|
|
|
}
|
|
|
|
|
|
|
|
groups[group] = {
|
|
|
|
text: group,
|
|
|
|
leaf: false,
|
|
|
|
iconCls: "fa " + cls,
|
|
|
|
expanded: false,
|
|
|
|
backup_type: item.data["backup-type"],
|
|
|
|
backup_id: item.data["backup-id"],
|
|
|
|
children: []
|
2020-03-26 17:01:04 +00:00
|
|
|
};
|
2020-05-26 10:46:45 +00:00
|
|
|
}
|
2020-03-26 17:01:04 +00:00
|
|
|
|
2020-05-26 10:46:45 +00:00
|
|
|
return groups;
|
|
|
|
},
|
2020-03-25 14:17:28 +00:00
|
|
|
|
2020-05-26 10:46:45 +00:00
|
|
|
onLoad: function(store, records, success) {
|
|
|
|
let view = this.getView();
|
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let groups = this.getRecordGroups(records);
|
2020-03-25 14:17:28 +00:00
|
|
|
|
2020-05-26 10:46:45 +00:00
|
|
|
let backup_time_to_string = function(backup_time) {
|
|
|
|
let pad = (number) => number < 10 ? '0' + number : number;
|
|
|
|
return backup_time.getUTCFullYear() +
|
|
|
|
'-' + pad(backup_time.getUTCMonth() + 1) +
|
|
|
|
'-' + pad(backup_time.getUTCDate()) +
|
|
|
|
'T' + pad(backup_time.getUTCHours()) +
|
|
|
|
':' + pad(backup_time.getUTCMinutes()) +
|
|
|
|
':' + pad(backup_time.getUTCSeconds()) +
|
|
|
|
'Z';
|
|
|
|
};
|
|
|
|
|
|
|
|
for (const item of records) {
|
|
|
|
let group = item.data["backup-type"] + "/" + item.data["backup-id"];
|
|
|
|
let children = groups[group].children;
|
|
|
|
|
|
|
|
let data = item.data;
|
|
|
|
|
|
|
|
data.text = Ext.Date.format(data["backup-time"], 'Y-m-d H:i:s');
|
|
|
|
data.text = group + '/' + backup_time_to_string(data["backup-time"]);
|
|
|
|
data.leaf = true;
|
|
|
|
data.cls = 'no-leaf-icons';
|
|
|
|
|
|
|
|
children.push(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
let children = [];
|
|
|
|
for (const [_key, group] of Object.entries(groups)) {
|
|
|
|
let last_backup = 0;
|
|
|
|
for (const item of group.children) {
|
|
|
|
if (item["backup-time"] > last_backup) {
|
|
|
|
last_backup = item["backup-time"];
|
|
|
|
group["backup-time"] = last_backup;
|
|
|
|
group.files = item.files;
|
|
|
|
group.size = item.size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
group.count = group.children.length;
|
|
|
|
children.push(group);
|
|
|
|
}
|
|
|
|
|
|
|
|
view.setRootNode({
|
|
|
|
expanded: true,
|
|
|
|
children: children
|
|
|
|
});
|
2019-12-20 16:17:44 +00:00
|
|
|
},
|
2020-03-26 16:23:51 +00:00
|
|
|
|
|
|
|
onPrune: function() {
|
|
|
|
var view = this.getView();
|
|
|
|
|
|
|
|
let rec = view.selModel.getSelection()[0];
|
|
|
|
if (!(rec && rec.data)) return;
|
|
|
|
let data = rec.data;
|
|
|
|
if (data.leaf) return;
|
|
|
|
|
|
|
|
if (!view.datastore) return;
|
|
|
|
|
|
|
|
let win = Ext.create('PBS.DataStorePrune', {
|
|
|
|
datastore: view.datastore,
|
|
|
|
backup_type: data.backup_type,
|
|
|
|
backup_id: data.backup_id,
|
|
|
|
});
|
|
|
|
win.on('destroy', this.reload, this);
|
|
|
|
win.show();
|
|
|
|
}
|
2019-12-20 16:17:44 +00:00
|
|
|
},
|
|
|
|
|
2019-12-22 09:43:57 +00:00
|
|
|
initComponent: function() {
|
|
|
|
var me = this;
|
2019-12-20 16:03:28 +00:00
|
|
|
|
2020-03-26 12:23:28 +00:00
|
|
|
var sm = Ext.create('Ext.selection.RowModel', {});
|
|
|
|
|
|
|
|
var prune_btn = new Proxmox.button.Button({
|
|
|
|
text: gettext('Prune'),
|
|
|
|
disabled: true,
|
|
|
|
selModel: sm,
|
2020-03-26 16:23:51 +00:00
|
|
|
enableFn: function(record) { return !record.data.leaf; },
|
|
|
|
handler: 'onPrune',
|
2020-03-26 12:23:28 +00:00
|
|
|
});
|
|
|
|
|
2019-12-22 09:43:57 +00:00
|
|
|
Ext.apply(me, {
|
2020-03-26 12:23:28 +00:00
|
|
|
selModel: sm,
|
2019-12-22 09:43:57 +00:00
|
|
|
columns: [
|
|
|
|
{
|
2020-03-25 14:17:28 +00:00
|
|
|
xtype: 'treecolumn',
|
|
|
|
header: gettext("Backup Group"),
|
|
|
|
dataIndex: 'text',
|
2019-12-22 09:43:57 +00:00
|
|
|
flex: 1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
xtype: 'datecolumn',
|
2020-03-25 14:17:28 +00:00
|
|
|
header: gettext('Backup Time'),
|
2019-12-22 09:43:57 +00:00
|
|
|
sortable: true,
|
2020-03-25 14:17:28 +00:00
|
|
|
dataIndex: 'backup-time',
|
2019-12-22 09:43:57 +00:00
|
|
|
format: 'Y-m-d H:i:s',
|
2020-03-25 14:17:28 +00:00
|
|
|
width: 150
|
|
|
|
},
|
|
|
|
{
|
|
|
|
header: gettext("Size"),
|
|
|
|
sortable: true,
|
|
|
|
dataIndex: 'size',
|
|
|
|
renderer: Proxmox.Utils.format_size,
|
2019-12-22 09:43:57 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
xtype: 'numbercolumn',
|
|
|
|
format: '0',
|
2020-03-25 14:17:28 +00:00
|
|
|
header: gettext("Count"),
|
2019-12-22 09:43:57 +00:00
|
|
|
sortable: true,
|
2020-03-25 14:17:28 +00:00
|
|
|
dataIndex: 'count',
|
2019-12-22 09:43:57 +00:00
|
|
|
},
|
2020-03-25 14:17:28 +00:00
|
|
|
{
|
|
|
|
header: gettext("Files"),
|
|
|
|
sortable: false,
|
|
|
|
dataIndex: 'files',
|
2020-03-26 17:01:04 +00:00
|
|
|
flex: 2
|
2020-03-25 14:17:28 +00:00
|
|
|
}
|
2019-12-22 09:43:57 +00:00
|
|
|
],
|
|
|
|
|
|
|
|
tbar: [
|
|
|
|
{
|
|
|
|
text: gettext('Reload'),
|
|
|
|
iconCls: 'fa fa-refresh',
|
|
|
|
handler: 'reload',
|
|
|
|
},
|
2020-03-26 12:23:28 +00:00
|
|
|
prune_btn
|
2019-12-22 09:43:57 +00:00
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
me.callParent();
|
2019-12-20 16:03:28 +00:00
|
|
|
},
|
2019-12-20 11:46:09 +00:00
|
|
|
});
|