pmg-gui/js/StatStore.js
Thomas Lamprecht c87d46fbe8 tree wide: eslint --fix
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-10-23 13:17:15 +02:00

79 lines
1.4 KiB
JavaScript

Ext.define('PMG.data.StatStore', {
extend: 'Ext.data.Store',
alias: 'store.pmgStatStore',
autoDestroy: true,
staturl: undefined,
includeTimeSpan: false,
setUrl: function(url) {
var me = this;
me.proxy.abort(); // abort pending requests
me.staturl = url;
me.proxy.extraParams = {};
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;
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();
},
});