|
12 | 12 | _initialized = false,
|
13 | 13 | _period = null;
|
14 | 14 | _overviewList = [];
|
15 |
| - |
| 15 | + var _activeLoadedEvent=""; |
| 16 | + var _activeLoadedSegmentation=""; |
| 17 | + |
| 18 | + countlyEvent.hasLoadedData = function() |
| 19 | + { |
| 20 | + if(_activeLoadedEvent && _activeLoadedEvent == _activeEvent && _activeLoadedSegmentation==_activeSegmentation) |
| 21 | + { |
| 22 | + return true; |
| 23 | + } |
| 24 | + return false; |
| 25 | + } |
| 26 | + |
16 | 27 | //Public Methods
|
17 | 28 | countlyEvent.initialize = function(forceReload) {
|
| 29 | + |
18 | 30 | if (!forceReload && _initialized && _period == countlyCommon.getPeriodForAjax() && _activeAppKey == countlyCommon.ACTIVE_APP_KEY) {
|
19 | 31 | return countlyEvent.refresh();
|
20 | 32 | }
|
21 |
| - |
| 33 | + if(forceReload && countlyEvent.hasLoadedData()) |
| 34 | + { |
| 35 | + return true; |
| 36 | + } |
| 37 | + var currentActiveEvent = _activeEvent; |
| 38 | + var currentActiveSegmentation = _activeSegmentation |
22 | 39 | _period = countlyCommon.getPeriodForAjax();
|
23 | 40 |
|
24 | 41 | if (!countlyCommon.DEBUG) {
|
|
41 | 58 | _activeEvents = json;
|
42 | 59 | if (!_activeEvent && countlyEvent.getEvents()[0]) {
|
43 | 60 | _activeEvent = countlyEvent.getEvents()[0].key;
|
| 61 | + currentActiveEvent = _activeEvent; |
44 | 62 | }
|
45 | 63 | }
|
46 | 64 | }))
|
47 | 65 | .then(
|
48 |
| - $.ajax({ |
49 |
| - type: "GET", |
50 |
| - url: countlyCommon.API_PARTS.data.r, |
51 |
| - data: { |
52 |
| - "api_key": countlyGlobal.member.api_key, |
53 |
| - "app_id" : countlyCommon.ACTIVE_APP_ID, |
54 |
| - "method" : "events", |
55 |
| - "event": _activeEvent, |
56 |
| - "segmentation": _activeSegmentation, |
57 |
| - "period":_period, |
58 |
| - "preventRequestAbort":true |
59 |
| - }, |
60 |
| - dataType: "jsonp", |
61 |
| - success: function(json) { |
62 |
| - _activeEventDb = json; |
63 |
| - setMeta(); |
64 |
| - } |
65 |
| - }) |
66 |
| - ).then(function(){ |
67 |
| - return true; |
68 |
| - }); |
| 66 | + function(){ |
| 67 | + return $.when( $.ajax({ |
| 68 | + type: "GET", |
| 69 | + url: countlyCommon.API_PARTS.data.r, |
| 70 | + data: { |
| 71 | + "api_key": countlyGlobal.member.api_key, |
| 72 | + "app_id" : countlyCommon.ACTIVE_APP_ID, |
| 73 | + "method" : "events", |
| 74 | + "event": _activeEvent, |
| 75 | + "segmentation": currentActiveSegmentation, |
| 76 | + "period":_period, |
| 77 | + "preventRequestAbort":true |
| 78 | + }, |
| 79 | + dataType: "jsonp", |
| 80 | + success: function(json) { |
| 81 | + if(currentActiveEvent == _activeEvent && currentActiveSegmentation == _activeSegmentation) |
| 82 | + { |
| 83 | + _activeLoadedEvent=_activeEvent; |
| 84 | + _activeLoadedSegmentation = _activeSegmentation |
| 85 | + _activeEventDb = json; |
| 86 | + setMeta(); |
| 87 | + } |
| 88 | + } |
| 89 | + })).then(function(){ |
| 90 | + return true; |
| 91 | + }); |
| 92 | + } |
| 93 | + ) |
69 | 94 | } else {
|
70 | 95 | _activeEventDb = {"2012":{}};
|
71 | 96 | return true;
|
|
190 | 215 | };
|
191 | 216 |
|
192 | 217 | countlyEvent.refresh = function() {
|
| 218 | + |
| 219 | + var currentActiveEvent = _activeEvent; |
| 220 | + var currentActiveSegmentation = _activeSegmentation |
193 | 221 | if (!countlyCommon.DEBUG) {
|
194 | 222 | return $.when(
|
195 | 223 | $.ajax({
|
|
207 | 235 | _activeEvent = countlyEvent.getEvents()[0].key;
|
208 | 236 | }
|
209 | 237 | }
|
210 |
| - }), |
211 |
| - $.ajax({ |
| 238 | + }) |
| 239 | + ).then( |
| 240 | + function(){ |
| 241 | + return $.when( |
| 242 | + $.ajax({ |
212 | 243 | type: "GET",
|
213 | 244 | url: countlyCommon.API_PARTS.data.r,
|
214 | 245 | data: {
|
|
217 | 248 | "method" : "events",
|
218 | 249 | "action" : "refresh",
|
219 | 250 | "event": _activeEvent,
|
220 |
| - "segmentation": _activeSegmentation |
| 251 | + "segmentation": currentActiveSegmentation |
221 | 252 | },
|
222 | 253 | dataType: "jsonp",
|
223 | 254 | success: function(json) {
|
| 255 | + if(currentActiveEvent == _activeEvent && currentActiveSegmentation == _activeSegmentation) |
| 256 | + { |
| 257 | + _activeLoadedEvent=_activeEvent; |
| 258 | + _activeLoadedSegmentation = _activeSegmentation |
224 | 259 | countlyCommon.extendDbObj(_activeEventDb, json);
|
225 | 260 | extendMeta();
|
| 261 | + } |
226 | 262 | }
|
227 |
| - }) |
228 |
| - ).then(function(){ |
229 |
| - return true; |
| 263 | + })).then( |
| 264 | + function(){return true; |
| 265 | + }); |
230 | 266 | });
|
231 | 267 | } else {
|
232 | 268 | _activeEventDb = {"2012":{}};
|
|
243 | 279 | _activeSegmentationValues = [];
|
244 | 280 | _activeSegmentationObj = {};
|
245 | 281 | _activeAppKey = 0;
|
| 282 | + _activeLoadedEvent=""; |
| 283 | + _activeLoadedSegmentation="" |
246 | 284 | _initialized = false;
|
247 | 285 | };
|
248 | 286 |
|
|
281 | 319 | _activeSegmentationValues = [];
|
282 | 320 | _activeSegmentationObj = {};
|
283 | 321 | _activeEvent = activeEvent && activeEvent.toString();
|
284 |
| - |
| 322 | + _activeLoadedEvent=""; |
| 323 | + _activeLoadedSegmentation="" |
| 324 | + |
285 | 325 | $.when(countlyEvent.initialize(true)).then(callback);
|
286 | 326 | };
|
287 | 327 |
|
288 | 328 | countlyEvent.setActiveSegmentation = function (activeSegmentation, callback) {
|
289 | 329 | _activeEventDb = {};
|
290 | 330 | _activeSegmentation = activeSegmentation;
|
| 331 | + _activeLoadedEvent=""; |
| 332 | + _activeLoadedSegmentation="" |
291 | 333 |
|
292 | 334 | $.when(countlyEvent.initialize(true)).then(callback);
|
293 | 335 | };
|
|
0 commit comments