all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Hannes Laimer <h.laimer@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 2/3] report: add webui button for system report
Date: Tue,  3 Nov 2020 13:29:07 +0100	[thread overview]
Message-ID: <20201103122908.114524-3-h.laimer@proxmox.com> (raw)
In-Reply-To: <20201103122908.114524-1-h.laimer@proxmox.com>

Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
---
 www/Subscription.js | 75 ++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 74 insertions(+), 1 deletion(-)

diff --git a/www/Subscription.js b/www/Subscription.js
index d2ad5af0..498600bf 100644
--- a/www/Subscription.js
+++ b/www/Subscription.js
@@ -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,
 	});
-- 
2.20.1





  parent reply	other threads:[~2020-11-03 12:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-03 12:29 [pbs-devel] [PATCH proxmox-backup 0/3] add " Hannes Laimer
2020-11-03 12:29 ` [pbs-devel] [PATCH proxmox-backup 1/3] report: add api endpoint and function to generate report Hannes Laimer
2020-11-03 12:29 ` Hannes Laimer [this message]
2020-11-03 12:29 ` [pbs-devel] [PATCH proxmox-backup 3/3] manager: add report cli command Hannes Laimer
2020-11-04  7:49 ` [pbs-devel] applied-series: [PATCH proxmox-backup 0/3] add system report Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201103122908.114524-3-h.laimer@proxmox.com \
    --to=h.laimer@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal