[pmg-devel] [PATCH pmg-gui] add system report to gui

Dominik Csapak d.csapak at proxmox.com
Tue Feb 26 11:27:35 CET 2019


Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 js/Subscription.js | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)

diff --git a/js/Subscription.js b/js/Subscription.js
index b09ff27..2cbd272 100644
--- a/js/Subscription.js
+++ b/js/Subscription.js
@@ -30,6 +30,73 @@ Ext.define('PMG.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 Proxmox.NodeName + '-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 = 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/' + Proxmox.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() {
 	var me = this;
 
@@ -106,6 +173,12 @@ Ext.define('PMG.Subscription', {
 			    callback: reload
 			});
 		    }
+		},
+		{
+		    text: gettext('System Report'),
+		    handler: function() {
+			Proxmox.Utils.checked_command(function (){ me.showReport(); });
+		    }
 		}
 	    ],
 	    rows: rows
-- 
2.11.0




More information about the pmg-devel mailing list