Skip to content

Commit a6a2a8d

Browse files
committed
[SERVER-823] [events] [bugfix] Data issue while navigating between events
-requests are made one after another(to don't run wrong data if switched) -checking if data is loaded before refreshig
1 parent 95243e4 commit a6a2a8d

File tree

2 files changed

+92
-44
lines changed

2 files changed

+92
-44
lines changed

frontend/express/public/javascripts/countly/countly.event.js

+72-30
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,30 @@
1212
_initialized = false,
1313
_period = null;
1414
_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+
1627
//Public Methods
1728
countlyEvent.initialize = function(forceReload) {
29+
1830
if (!forceReload && _initialized && _period == countlyCommon.getPeriodForAjax() && _activeAppKey == countlyCommon.ACTIVE_APP_KEY) {
1931
return countlyEvent.refresh();
2032
}
21-
33+
if(forceReload && countlyEvent.hasLoadedData())
34+
{
35+
return true;
36+
}
37+
var currentActiveEvent = _activeEvent;
38+
var currentActiveSegmentation = _activeSegmentation
2239
_period = countlyCommon.getPeriodForAjax();
2340

2441
if (!countlyCommon.DEBUG) {
@@ -41,31 +58,39 @@
4158
_activeEvents = json;
4259
if (!_activeEvent && countlyEvent.getEvents()[0]) {
4360
_activeEvent = countlyEvent.getEvents()[0].key;
61+
currentActiveEvent = _activeEvent;
4462
}
4563
}
4664
}))
4765
.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+
)
6994
} else {
7095
_activeEventDb = {"2012":{}};
7196
return true;
@@ -190,6 +215,9 @@
190215
};
191216

192217
countlyEvent.refresh = function() {
218+
219+
var currentActiveEvent = _activeEvent;
220+
var currentActiveSegmentation = _activeSegmentation
193221
if (!countlyCommon.DEBUG) {
194222
return $.when(
195223
$.ajax({
@@ -207,8 +235,11 @@
207235
_activeEvent = countlyEvent.getEvents()[0].key;
208236
}
209237
}
210-
}),
211-
$.ajax({
238+
})
239+
).then(
240+
function(){
241+
return $.when(
242+
$.ajax({
212243
type: "GET",
213244
url: countlyCommon.API_PARTS.data.r,
214245
data: {
@@ -217,16 +248,21 @@
217248
"method" : "events",
218249
"action" : "refresh",
219250
"event": _activeEvent,
220-
"segmentation": _activeSegmentation
251+
"segmentation": currentActiveSegmentation
221252
},
222253
dataType: "jsonp",
223254
success: function(json) {
255+
if(currentActiveEvent == _activeEvent && currentActiveSegmentation == _activeSegmentation)
256+
{
257+
_activeLoadedEvent=_activeEvent;
258+
_activeLoadedSegmentation = _activeSegmentation
224259
countlyCommon.extendDbObj(_activeEventDb, json);
225260
extendMeta();
261+
}
226262
}
227-
})
228-
).then(function(){
229-
return true;
263+
})).then(
264+
function(){return true;
265+
});
230266
});
231267
} else {
232268
_activeEventDb = {"2012":{}};
@@ -243,6 +279,8 @@
243279
_activeSegmentationValues = [];
244280
_activeSegmentationObj = {};
245281
_activeAppKey = 0;
282+
_activeLoadedEvent="";
283+
_activeLoadedSegmentation=""
246284
_initialized = false;
247285
};
248286

@@ -281,13 +319,17 @@
281319
_activeSegmentationValues = [];
282320
_activeSegmentationObj = {};
283321
_activeEvent = activeEvent && activeEvent.toString();
284-
322+
_activeLoadedEvent="";
323+
_activeLoadedSegmentation=""
324+
285325
$.when(countlyEvent.initialize(true)).then(callback);
286326
};
287327

288328
countlyEvent.setActiveSegmentation = function (activeSegmentation, callback) {
289329
_activeEventDb = {};
290330
_activeSegmentation = activeSegmentation;
331+
_activeLoadedEvent="";
332+
_activeLoadedSegmentation=""
291333

292334
$.when(countlyEvent.initialize(true)).then(callback);
293335
};

frontend/express/public/javascripts/countly/countly.views.js

+20-14
Original file line numberDiff line numberDiff line change
@@ -3408,22 +3408,25 @@ window.EventsView = countlyView.extend({
34083408
$(".segmentation-option").on("click", function () {
34093409
var tmpCurrSegmentation = $(this).data("value");
34103410
countlyEvent.setActiveSegmentation(tmpCurrSegmentation, function() {
3411-
self.renderCommon(true);
3412-
newPage = $("<div>" + self.template(self.templateData) + "</div>");
3411+
if(countlyEvent.hasLoadedData())
3412+
{
3413+
self.renderCommon(true);
3414+
newPage = $("<div>" + self.template(self.templateData) + "</div>");
34133415

3414-
$(self.el).find("#event-nav .scrollable").html(function () {
3415-
return newPage.find("#event-nav .scrollable").html();
3416-
});
3416+
$(self.el).find("#event-nav .scrollable").html(function () {
3417+
return newPage.find("#event-nav .scrollable").html();
3418+
});
34173419

3418-
$(self.el).find(".widget-footer").html(newPage.find(".widget-footer").html());
3419-
$(self.el).find("#edit-event-container").replaceWith(newPage.find("#edit-event-container"));
3420+
$(self.el).find(".widget-footer").html(newPage.find(".widget-footer").html());
3421+
$(self.el).find("#edit-event-container").replaceWith(newPage.find("#edit-event-container"));
34203422

3421-
var eventData = countlyEvent.getEventData();
3422-
self.drawGraph(eventData);
3423-
self.pageScript();
3423+
var eventData = countlyEvent.getEventData();
3424+
self.drawGraph(eventData);
3425+
self.pageScript();
34243426

3425-
self.drawTable(eventData);
3426-
app.localize();
3427+
self.drawTable(eventData);
3428+
app.localize();
3429+
}
34273430
});
34283431
});
34293432

@@ -3575,16 +3578,18 @@ window.EventsView = countlyView.extend({
35753578
this.drawTable(eventData);
35763579
this.pageScript();
35773580
}
3578-
35793581
}
35803582
},
35813583
refresh:function (eventChanged, segmentationChanged) {
35823584
var self = this;
3585+
35833586
$.when(countlyEvent.initialize(eventChanged)).then(function () {
35843587

35853588
if (app.activeView != self) {
35863589
return false;
35873590
}
3591+
if(countlyEvent.hasLoadedData())
3592+
{
35883593
self.renderCommon(true);
35893594

35903595
newPage = $("<div>" + self.template(self.templateData) + "</div>");
@@ -3654,8 +3659,9 @@ window.EventsView = countlyView.extend({
36543659
}
36553660
app.localize();
36563661
$('.nav-search').find("input").trigger("input");
3662+
}
36573663
});
3658-
}
3664+
}
36593665
});
36603666

36613667
window.DashboardView = countlyView.extend({

0 commit comments

Comments
 (0)