pmg-gui/js/StatStore.js
Stoiko Ivanov 367681b750 statistics: use new api call for detailed stats
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@proxmox.com>
2021-02-10 10:45:08 +01:00

86 lines
1.5 KiB
JavaScript

Ext.define('PMG.data.StatStore', {
extend: 'Ext.data.Store',
alias: 'store.pmgStatStore',
autoDestroy: true,
staturl: undefined,
includeTimeSpan: false,
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([]);
},
reload: function() {
var me = this;
me.proxy.abort(); // abort pending requests
if (me.staturl === undefined) {
me.proxy.extraParams = {};
me.setData([]);
return;
}
var ts = PMG.StatTimeSelector.getTimeSpan();
var last = me.proxy.extraParams;
if (last.starttime === ts.starttime && last.endtime === ts.endtime) {
return; // avoid repeated loads
}
me.proxy.url = me.staturl;
Ext.apply(me.proxy.extraParams, {
starttime: ts.starttime,
endtime: ts.endtime,
});
var timespan = 3600;
if (me.includeTimeSpan) {
var period = ts.endtime - ts.starttime;
if (period <= 86400*7) {
timespan = 3600;
} else {
timespan = 3600*24;
}
me.proxy.extraParams.timespan = timespan;
}
me.load();
},
proxy: {
type: 'proxmox',
},
autoReload: true,
constructor: function(config) {
var me = this;
config = config || {};
me.mon(Ext.GlobalEvents, 'pmgStatTimeSelectorUpdate', function() {
if (me.autoReload) {
me.reload();
}
}, me);
me.callParent([config]);
me.reload();
},
});