[pmg-devel] [PATCH pmg-gui v3 1/1] statistics: use new api call for detailed stats

Stoiko Ivanov s.ivanov at proxmox.com
Tue Feb 2 14:03:17 CET 2021


the new /statistics/detail api calls takes the type (contact, sender,
receiver) and address for which to display the statistics as explicit
parameter instead of path-component.

This makes it possible to accept '/' as part of an e-mail address
which is allowed (in the local-part by RFC5322 [0], and accepted by
postfix.

[0] https://tools.ietf.org/html/rfc5322

Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
 js/ContactStatistics.js  | 10 +++++-----
 js/ReceiverStatistics.js | 10 +++++-----
 js/SenderStatistics.js   | 10 +++++-----
 js/StatStore.js          | 11 +++++++++--
 4 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/js/ContactStatistics.js b/js/ContactStatistics.js
index 6c9d2d4..7f448af 100644
--- a/js/ContactStatistics.js
+++ b/js/ContactStatistics.js
@@ -16,10 +16,10 @@ Ext.define('PMG.ContactDetails', {
 
     plugins: 'gridfilters',
 
-    setUrl: function(url, title) {
+    setUrl: function(url, extraparam, title) {
 	var me = this;
 
-	me.store.setUrl(url);
+	me.store.setUrl(url, extraparam);
 	me.store.setRemoteFilter(url !== undefined);
 	Proxmox.Utils.setErrorMask(me, false);
 	me.store.reload();
@@ -201,9 +201,9 @@ Ext.define('PMG.ContactStatistics', {
 	    var details = this.lookupReference('details');
 	    if (selected.length > 0) {
 		var contact = selected[0].data.contact;
-		var url = "/api2/json/statistics/contact/" +
-		    encodeURIComponent(contact);
-		details.setUrl(url, '<b>' + gettext('Contact') + ':</b> ' + Ext.htmlEncode(contact));
+		var extraparam = { address: contact, type: 'contact' };
+		var url = "/api2/json/statistics/detail";
+		details.setUrl(url, extraparam, '<b>' + gettext('Contact') + ':</b> ' + Ext.htmlEncode(contact));
 	    } else {
 		details.setUrl();
 	    }
diff --git a/js/ReceiverStatistics.js b/js/ReceiverStatistics.js
index 6378e06..bf86745 100644
--- a/js/ReceiverStatistics.js
+++ b/js/ReceiverStatistics.js
@@ -16,10 +16,10 @@ Ext.define('PMG.ReceiverDetails', {
 
     plugins: 'gridfilters',
 
-    setUrl: function(url, title) {
+    setUrl: function(url, extraparam, title) {
 	var me = this;
 
-	me.store.setUrl(url);
+	me.store.setUrl(url, extraparam);
 	me.store.setRemoteFilter(url !== undefined);
 	Proxmox.Utils.setErrorMask(me, false);
 	me.store.reload();
@@ -212,10 +212,10 @@ Ext.define('PMG.ReceiverStatistics', {
 	selectionChange: function(grid, selected, eOpts) {
 	    var details = this.lookupReference('details');
 	    if (selected.length > 0) {
+		var url = "/api2/json/statistics/detail";
 		var receiver = selected[0].data.receiver;
-		var url = "/api2/json/statistics/receiver/" +
-		    encodeURIComponent(receiver);
-		details.setUrl(url, '<b>' + gettext('Receiver') + ':</b> ' + Ext.htmlEncode(receiver));
+		var extraparam = { address: receiver, type: 'receiver' };
+		details.setUrl(url, extraparam, '<b>' + gettext('Receiver') + ':</b> ' + Ext.htmlEncode(receiver));
 	    } else {
 		details.setUrl();
 	    }
diff --git a/js/SenderStatistics.js b/js/SenderStatistics.js
index 43c5438..830f5fb 100644
--- a/js/SenderStatistics.js
+++ b/js/SenderStatistics.js
@@ -16,10 +16,10 @@ Ext.define('PMG.SenderDetails', {
 
     plugins: 'gridfilters',
 
-    setUrl: function(url, title) {
+    setUrl: function(url, extraparam, title) {
 	var me = this;
 
-	me.store.setUrl(url);
+	me.store.setUrl(url, extraparam);
 	me.store.setRemoteFilter(url !== undefined);
 	Proxmox.Utils.setErrorMask(me, false);
 	me.store.reload();
@@ -201,9 +201,9 @@ Ext.define('PMG.SenderStatistics', {
 	    var details = this.lookupReference('details');
 	    if (selected.length > 0) {
 		var sender = selected[0].data.sender;
-		var url = "/api2/json/statistics/sender/" +
-		    encodeURIComponent(sender);
-		details.setUrl(url, '<b>' + gettext('Sender') + ':</b> ' + Ext.htmlEncode(sender));
+		var extraparam = { address: sender, type: 'sender' };
+		var url = "/api2/json/statistics/detail";
+		details.setUrl(url, extraparam, '<b>' + gettext('Sender') + ':</b> ' + Ext.htmlEncode(sender));
 	    } else {
 		details.setUrl();
 	    }
diff --git a/js/StatStore.js b/js/StatStore.js
index ec11777..0fc1d31 100644
--- a/js/StatStore.js
+++ b/js/StatStore.js
@@ -8,13 +8,17 @@ Ext.define('PMG.data.StatStore', {
 
     includeTimeSpan: false,
 
-    setUrl: function(url) {
+    setUrl: function(url, extraparam) {
 	var me = this;
 
 	me.proxy.abort(); // abort pending requests
 
 	me.staturl = url;
 	me.proxy.extraParams = {};
+	if (extraparam !== undefined) {
+	    me.proxy.extraParams = extraparam;
+	}
+
 	me.setData([]);
     },
 
@@ -38,7 +42,10 @@ Ext.define('PMG.data.StatStore', {
 	}
 
 	me.proxy.url = me.staturl;
-	me.proxy.extraParams = { starttime: ts.starttime, endtime: ts.endtime };
+	Ext.apply(me.proxy.extraParams, {
+	    starttime: ts.starttime,
+	    endtime: ts.endtime,
+	});
 
 	var timespan = 3600;
 	if (me.includeTimeSpan) {
-- 
2.20.1





More information about the pmg-devel mailing list