Skip to content

Commit 11a8a3a

Browse files
committed
Merge pull request #110 from ar2rsawseen/master
Added AllApps Dashboard and DataTables
2 parents ccaaa79 + 27f0f3b commit 11a8a3a

24 files changed

+17898
-1917
lines changed

bin/compile.js.bat

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ java -jar closure-compiler.jar ^
88
--js=../frontend/express/public/javascripts/dom/jqueryui/jquery-ui-i18n.js ^
99
--js=../frontend/express/public/javascripts/dom/slimScroll.min.js ^
1010
--js=../frontend/express/public/javascripts/dom/jquery.easing.1.3.js ^
11+
--js=../frontend/express/public/javascripts/dom/dataTables/js/jquery.dataTables.js ^
12+
--js=../frontend/express/public/javascripts/dom/dataTables/js/ZeroClipboard.js ^
13+
--js=../frontend/express/public/javascripts/dom/dataTables/js/TableTools.js ^
1114
--js_output_file=../frontend/express/public/javascripts/min/countly.dom.js
1215

1316
java -jar closure-compiler.jar ^
@@ -48,5 +51,6 @@ java -jar closure-compiler.jar ^
4851
--js=../frontend/express/public/javascripts/countly/countly.device.detail.js ^
4952
--js=../frontend/express/public/javascripts/countly/countly.app.version.js ^
5053
--js=../frontend/express/public/javascripts/countly/countly.carrier.js ^
54+
--js=../frontend/express/public/javascripts/countly/countly.allapps.js ^
5155
--js=../frontend/express/public/javascripts/countly/countly.template.js ^
5256
--js_output_file=../frontend/express/public/javascripts/min/countly.lib.js
Loading
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
(function (countlyAllApps, $, undefined) {
2+
3+
//Private Properties
4+
var _appData = {"all":{_id:"all", name:"All apps"}},
5+
_appIds = {},
6+
_sessions = {},
7+
_sessionData = {};
8+
var _tempApp;
9+
10+
//Public Methods
11+
countlyAllApps.initialize = function () {
12+
return countlyAllApps.refresh();
13+
};
14+
15+
countlyAllApps.refresh = function () {
16+
if (!countlyCommon.DEBUG) {
17+
this.reset();
18+
var deffereds = [];
19+
_tempApp = countlyCommon.ACTIVE_APP_ID;
20+
for(var i in countlyGlobal["apps"]){
21+
deffereds.push(loadApp(i));
22+
}
23+
return $.when.apply($, deffereds).then(function(){
24+
countlyCommon.setActiveApp(_tempApp);
25+
_appData["all"].sessions = {total:0, trend:0};
26+
_appData["all"].users = {total:0, trend:0};
27+
_appData["all"].newusers = {total:0, trend:0};
28+
_appData["all"].duration = {total:0, trend:0};
29+
_appData["all"].avgduration = {total:0, trend:0};
30+
_sessions["all"] = {};
31+
for(var appID in countlyGlobal["apps"]){
32+
var sessionData = _sessionData[appID];
33+
for(var i in _sessions[appID]){
34+
for(var j = 0, l = _sessions[appID][i].data.length; j < l; j++){
35+
if(!_sessions["all"][i]){
36+
_sessions["all"][i] = {};
37+
_sessions["all"][i].label = _sessions[appID][i].label;
38+
_sessions["all"][i].data = [];
39+
}
40+
if(!_sessions["all"][i].data[j]){
41+
_sessions["all"][i].data[j] = [0,0];
42+
}
43+
_sessions["all"][i].data[j][0] = _sessions[appID][i].data[j][0];
44+
_sessions["all"][i].data[j][1] += parseFloat(_sessions[appID][i].data[j][1]);
45+
if(i == "#draw-total-users")
46+
_appData["all"].users.total += _sessions[appID][i].data[j][1];
47+
else if(i == "#draw-new-users")
48+
_appData["all"].newusers.total += _sessions[appID][i].data[j][1];
49+
else if(i == "#draw-total-sessions")
50+
_appData["all"].sessions.total += _sessions[appID][i].data[j][1];
51+
else if(i == "#draw-total-time-spent")
52+
_appData["all"].duration.total += parseFloat(_sessions[appID][i].data[j][1]);
53+
}
54+
}
55+
_appData["all"].sessions.trend += fromShortNumber(sessionData.usage['total-sessions'].change);
56+
_appData["all"].users.trend += fromShortNumber(sessionData.usage['total-users'].change);
57+
_appData["all"].newusers.trend += fromShortNumber(sessionData.usage['new-users'].change);
58+
_appData["all"].duration.trend += fromShortNumber(sessionData.usage['total-duration'].change);
59+
_appData["all"].avgduration.trend += fromShortNumber(sessionData.usage['avg-duration-per-session'].change);
60+
}
61+
for(var i in _appData["all"]){
62+
if(_appData["all"][i].trend < 0)
63+
_appData["all"][i].trend = "d";
64+
else
65+
_appData["all"][i].trend = "u";
66+
}
67+
_appData["all"].avgduration.total = (_appData["all"].sessions.total == 0 ) ? 0 : _appData["all"].duration.total/_appData["all"].sessions.total;
68+
//transform total duration
69+
var timeSpentString = (_appData["all"].duration.total.toFixed(1)) + " " + jQuery.i18n.map["common.minute.abrv"];
70+
if (_appData["all"].duration.total >= 142560) {
71+
timeSpentString = (_appData["all"].duration.total / 525600).toFixed(1) + " " + jQuery.i18n.map["common.year.abrv"];
72+
} else if (_appData["all"].duration.total >= 1440) {
73+
timeSpentString = (_appData["all"].duration.total / 1440).toFixed(1) + " " + jQuery.i18n.map["common.day.abrv"];
74+
} else if (_appData["all"].duration.total >= 60) {
75+
timeSpentString = (_appData["all"].duration.total / 60).toFixed(1) + " " + jQuery.i18n.map["common.hour.abrv"];
76+
}
77+
_appData["all"].duration.total = timeSpentString;
78+
79+
//transform avg duration
80+
var timeSpentString = (_appData["all"].avgduration.total.toFixed(1)) + " " + jQuery.i18n.map["common.minute.abrv"];
81+
if (_appData["all"].avgduration.total >= 142560) {
82+
timeSpentString = (_appData["all"].avgduration.total / 525600).toFixed(1) + " " + jQuery.i18n.map["common.year.abrv"];
83+
} else if (_appData["all"].avgduration.total >= 1440) {
84+
timeSpentString = (_appData["all"].avgduration.total / 1440).toFixed(1) + " " + jQuery.i18n.map["common.day.abrv"];
85+
} else if (_appData["all"].avgduration.total >= 60) {
86+
timeSpentString = (_appData["all"].avgduration.total / 60).toFixed(1) + " " + jQuery.i18n.map["common.hour.abrv"];
87+
}
88+
_appData["all"].avgduration.total = timeSpentString;
89+
});
90+
} else {
91+
return true;
92+
}
93+
};
94+
95+
countlyAllApps.reset = function () {
96+
_appIds = {};
97+
};
98+
99+
countlyAllApps.getData = function () {
100+
var data = [];
101+
for(var i in _appData){
102+
data.push(_appData[i]);
103+
}
104+
return data;
105+
};
106+
107+
countlyAllApps.getSessionData = function () {
108+
return _sessions;
109+
};
110+
111+
countlyAllApps.setApp = function (app) {
112+
_tempApp = app;
113+
countlyCommon.setActiveApp(_tempApp);
114+
};
115+
116+
var loadApp = function(appID){
117+
countlyCommon.setActiveApp(appID);
118+
return $.when(countlySession.initialize()).done(function () {
119+
var sessionData = countlySession.getSessionData();
120+
if(!_appIds[appID]){
121+
_sessionData[appID] = sessionData;
122+
_sessions[appID] = {
123+
"#draw-total-users": countlySession.getUserDPActive().chartDP[1],
124+
"#draw-new-users": countlySession.getUserDPNew().chartDP[1],
125+
"#draw-total-sessions": countlySession.getSessionDPTotal().chartDP[1],
126+
"#draw-time-spent": countlySession.getDurationDPAvg().chartDP[1],
127+
"#draw-total-time-spent": countlySession.getDurationDP().chartDP[1],
128+
"#draw-avg-events-served": countlySession.getEventsDPAvg().chartDP[1]
129+
};
130+
_appData[appID] = {_id:appID, name:countlyGlobal["apps"][appID].name, sessions:sessionData.usage['total-sessions'], users:sessionData.usage['total-users'], newusers:sessionData.usage['new-users'], duration:sessionData.usage['total-duration'], avgduration:sessionData.usage['avg-duration-per-session']};
131+
_appIds[appID] = true;
132+
}
133+
});
134+
};
135+
136+
var fromShortNumber = function(str){
137+
if(str == "NA" || str == "∞"){
138+
return 0;
139+
}
140+
else{
141+
str = str.slice(0, -1);
142+
var rate = 1;
143+
if(str.slice(-1) == "K"){
144+
str = str.slice(0, -1);
145+
rate = 1000;
146+
}
147+
else if(str.slice(-1) == "M"){
148+
str = str.slice(0, -1);
149+
rate = 1000000;
150+
}
151+
return parseFloat(str)*rate;
152+
}
153+
};
154+
}(window.countlyAllApps = window.countlyAllApps || {}, jQuery));

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

+7
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,13 @@
10511051
ticks: _.compact(ticks)
10521052
};
10531053
};
1054+
1055+
countlyCommon.formatNumber = function(x) {
1056+
x = parseFloat(parseFloat(x).toFixed(2));
1057+
var parts = x.toString().split(".");
1058+
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
1059+
return parts.join(".");
1060+
};
10541061

10551062
// Private Methods
10561063

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

+4
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@
193193
countlyEvent.getActiveSegmentation = function () {
194194
return (_activeSegmentation) ? _activeSegmentation : jQuery.i18n.map["events.no-segmentation"];
195195
};
196+
197+
countlyEvent.isSegmentedView = function() {
198+
return (_activeSegmentation) ? true : false;
199+
};
196200

197201
countlyEvent.getEventData = function () {
198202

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

+6
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@
148148
locationData.chartData = locationData.chartData.splice(0, options.maxCountries);
149149
}
150150
}
151+
152+
for (var i = 0; i < locationData.chartData.length; i++) {
153+
locationData.chartData[i]['country_flag'] =
154+
"<div class='flag' style='background-image:url(/images/flags/" + locationData.chartData[i]['code'] + ".png);'></div>" +
155+
locationData.chartData[i]['country'];
156+
}
151157

152158
return _.sortBy(locationData.chartData, function(obj) { return -obj.t; });
153159
};

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

+19
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,25 @@
514514

515515
return durationRange[index];
516516
};
517+
518+
countlySession.getDurationIndex = function (duration) {
519+
var sec = jQuery.i18n.map["common.seconds"],
520+
min = jQuery.i18n.map["common.minutes"],
521+
hr = jQuery.i18n.map["common.hour"];
522+
523+
var durationRange = [
524+
"0-10 " + sec,
525+
"11-30 " + sec,
526+
"31-60 " + sec,
527+
"1-3 " + min,
528+
"3-10 " + min,
529+
"10-30 " + min,
530+
"30-60 " + min,
531+
"> 1 " + hr
532+
];
533+
534+
return durationRange.indexOf(duration);
535+
};
517536

518537
countlySession.getTopUserBars = function () {
519538

0 commit comments

Comments
 (0)