report: add webui button for system report

Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
This commit is contained in:
Hannes Laimer 2020-11-03 13:29:07 +01:00 committed by Thomas Lamprecht
parent b0ef9631e6
commit 46dce62be6

View File

@ -28,6 +28,73 @@ Ext.define('PBS.Subscription', {
enableTextSelection: true,
},
showReport: function() {
var me = this;
var getReportFileName = function() {
var now = Ext.Date.format(new Date(), 'D-d-F-Y-G-i');
return `${me.nodename}-pbs-report-${now}.txt`;
};
var view = Ext.createWidget('component', {
itemId: 'system-report-view',
scrollable: true,
style: {
'background-color': 'white',
'white-space': 'pre',
'font-family': 'monospace',
padding: '5px',
},
});
var reportWindow = Ext.create('Ext.window.Window', {
title: gettext('System Report'),
width: 1024,
height: 600,
layout: 'fit',
modal: true,
buttons: [
'->',
{
text: gettext('Download'),
handler: function() {
var fileContent = Ext.String.htmlDecode(reportWindow.getComponent('system-report-view').html);
var fileName = getReportFileName();
// Internet Explorer
if (window.navigator.msSaveOrOpenBlob) {
navigator.msSaveOrOpenBlob(new Blob([fileContent]), fileName);
} else {
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' +
encodeURIComponent(fileContent));
element.setAttribute('download', fileName);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
},
},
],
items: view,
});
Proxmox.Utils.API2Request({
url: '/api2/extjs/nodes/' + me.nodename + '/report',
method: 'GET',
waitMsgTarget: me,
failure: function(response) {
Ext.Msg.alert(gettext('Error'), response.htmlStatus);
},
success: function(response) {
var report = Ext.htmlEncode(response.result.data);
reportWindow.show();
view.update(report);
},
});
},
initComponent: function() {
let me = this;
@ -105,7 +172,13 @@ Ext.define('PBS.Subscription', {
selModel: false,
callback: reload,
},
//'-',
'-',
{
text: gettext('System Report'),
handler: function() {
Proxmox.Utils.checked_command(function() { me.showReport(); });
},
},
],
rows: rows,
});