[pve-devel] [PATCH pve-manager 2/2] Add report modal window, containing pvereport content

Emmanuel Kasper e.kasper at proxmox.com
Thu Nov 5 17:20:16 CET 2015


Signed-off-by: Emmanuel Kasper <e.kasper at proxmox.com>
---
 www/manager/node/Subscription.js | 73 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)

diff --git a/www/manager/node/Subscription.js b/www/manager/node/Subscription.js
index ac4d2f4..9e54335 100644
--- a/www/manager/node/Subscription.js
+++ b/www/manager/node/Subscription.js
@@ -28,6 +28,73 @@ Ext.define('PVE.node.Subscription', {
 
     features: [ {ftype: 'selectable'}],
 
+    showReport: function() {
+	var me = this;
+	var nodename = me.pveSelNode.data.node;
+
+	var getReportFileName= function() {
+	    var now = Ext.Date.format(new Date(), 'D-d-F-Y-G-i');
+	    return me.nodename + '-report-'  + now + '.txt';
+	}
+
+	var view = Ext.createWidget('component', {
+	    itemId: 'system-report-view',
+	    autoScroll: 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,
+	    tbar: [
+			{
+			    text: gettext('Download') + gettext('System Report'),
+			    handler: function() {
+				fileContent = reportWindow.getComponent('system-report-view').html;
+				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 ]
+	});
+
+	PVE.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() {
 	var me = this;
 
@@ -108,6 +175,12 @@ Ext.define('PVE.node.Subscription', {
 			    callback: reload
 			});
 		    }
+		},
+		{
+		    text: gettext('System Report'),
+		    handler: function() {
+			PVE.Utils.checked_command(me.showReport());
+		    }
 		}
 	    ],
 	    rows: rows,
-- 
2.1.4




More information about the pve-devel mailing list