]>
Commit | Line | Data |
---|---|---|
42a0470d DM |
1 | Ext.define('PMG.data.StatStore', { |
2 | extend: 'Ext.data.Store', | |
3 | alias: 'store.pmgStatStore', | |
4 | ||
5 | autoDestroy: true, | |
6 | ||
7 | staturl: undefined, | |
3b560b74 DM |
8 | |
9 | includeTimeSpan: false, | |
44230744 | 10 | |
367681b7 | 11 | setUrl: function(url, extraparam) { |
44230744 DM |
12 | var me = this; |
13 | ||
89399b2f DM |
14 | me.proxy.abort(); // abort pending requests |
15 | ||
44230744 DM |
16 | me.staturl = url; |
17 | me.proxy.extraParams = {}; | |
367681b7 SI |
18 | if (extraparam !== undefined) { |
19 | me.proxy.extraParams = extraparam; | |
20 | } | |
21 | ||
89399b2f | 22 | me.setData([]); |
44230744 DM |
23 | }, |
24 | ||
42a0470d DM |
25 | reload: function() { |
26 | var me = this; | |
27 | ||
d6d1af0e | 28 | me.proxy.abort(); // abort pending requests |
44230744 DM |
29 | |
30 | if (me.staturl === undefined) { | |
31 | me.proxy.extraParams = {}; | |
32 | me.setData([]); | |
33 | return; | |
34 | } | |
35 | ||
42a0470d DM |
36 | var ts = PMG.StatTimeSelector.getTimeSpan(); |
37 | ||
38 | var last = me.proxy.extraParams; | |
44230744 | 39 | |
c17f9fe4 | 40 | if (last.starttime === ts.starttime && last.endtime === ts.endtime) { |
42a0470d | 41 | return; // avoid repeated loads |
c17f9fe4 | 42 | } |
42a0470d DM |
43 | |
44 | me.proxy.url = me.staturl; | |
367681b7 SI |
45 | Ext.apply(me.proxy.extraParams, { |
46 | starttime: ts.starttime, | |
47 | endtime: ts.endtime, | |
48 | }); | |
42a0470d | 49 | |
3b560b74 DM |
50 | var timespan = 3600; |
51 | if (me.includeTimeSpan) { | |
52 | var period = ts.endtime - ts.starttime; | |
53 | if (period <= 86400*7) { | |
54 | timespan = 3600; | |
55 | } else { | |
56 | timespan = 3600*24; | |
57 | } | |
58 | me.proxy.extraParams.timespan = timespan; | |
59 | } | |
44230744 | 60 | |
42a0470d DM |
61 | me.load(); |
62 | }, | |
63 | ||
64 | proxy: { | |
c87d46fb | 65 | type: 'proxmox', |
42a0470d DM |
66 | }, |
67 | ||
c1a5d150 DM |
68 | autoReload: true, |
69 | ||
42a0470d DM |
70 | constructor: function(config) { |
71 | var me = this; | |
72 | ||
73 | config = config || {}; | |
74 | ||
c1a5d150 DM |
75 | me.mon(Ext.GlobalEvents, 'pmgStatTimeSelectorUpdate', function() { |
76 | if (me.autoReload) { | |
77 | me.reload(); | |
78 | } | |
79 | }, me); | |
44230744 | 80 | |
42a0470d DM |
81 | me.callParent([config]); |
82 | ||
83 | me.reload(); | |
c87d46fb | 84 | }, |
42a0470d | 85 | }); |