|
| 1 | +/*global countlyCommon, countlyGlobal, _*/ |
1 | 2 | (function(countlyEvent, $, undefined) {
|
2 | 3 |
|
3 | 4 | //Private Properties
|
|
11 | 12 | _activeAppKey = 0,
|
12 | 13 | _initialized = false,
|
13 | 14 | _period = null;
|
14 |
| - _overviewList = []; |
15 | 15 | var _activeLoadedEvent = "";
|
16 | 16 | var _activeLoadedSegmentation = "";
|
17 | 17 |
|
18 | 18 | countlyEvent.hasLoadedData = function() {
|
19 |
| - if (_activeLoadedEvent && _activeLoadedEvent == _activeEvent && _activeLoadedSegmentation == _activeSegmentation) { |
| 19 | + if (_activeLoadedEvent && _activeLoadedEvent === _activeEvent && _activeLoadedSegmentation === _activeSegmentation) { |
20 | 20 | return true;
|
21 | 21 | }
|
22 | 22 | return false;
|
|
25 | 25 | //Public Methods
|
26 | 26 | countlyEvent.initialize = function(forceReload) {
|
27 | 27 |
|
28 |
| - if (!forceReload && _initialized && _period == countlyCommon.getPeriodForAjax() && _activeAppKey == countlyCommon.ACTIVE_APP_KEY) { |
| 28 | + if (!forceReload && _initialized && _period === countlyCommon.getPeriodForAjax() && _activeAppKey === countlyCommon.ACTIVE_APP_KEY) { |
29 | 29 | return countlyEvent.refresh();
|
30 | 30 | }
|
31 | 31 | if (forceReload && countlyEvent.hasLoadedData()) {
|
|
75 | 75 | },
|
76 | 76 | dataType: "jsonp",
|
77 | 77 | success: function(json) {
|
78 |
| - if (currentActiveEvent == _activeEvent && currentActiveSegmentation == _activeSegmentation) { |
| 78 | + if (currentActiveEvent === _activeEvent && currentActiveSegmentation === _activeSegmentation) { |
79 | 79 | _activeLoadedEvent = _activeEvent;
|
80 | 80 | _activeLoadedSegmentation = _activeSegmentation;
|
81 | 81 | _activeEventDb = json;
|
|
108 | 108 | var _overviewData = [];
|
109 | 109 |
|
110 | 110 | if (_activeEvents.overview) {
|
111 |
| - for (var i = 0; i < _activeEvents.overview.length; i++) { |
112 |
| - if (my_events.indexOf(_activeEvents.overview[i].eventKey) == -1) { |
113 |
| - my_events.push(_activeEvents.overview[i].eventKey); |
| 111 | + for (var z = 0; z < _activeEvents.overview.length; z++) { |
| 112 | + if (my_events.indexOf(_activeEvents.overview[z].eventKey) === -1) { |
| 113 | + my_events.push(_activeEvents.overview[z].eventKey); |
114 | 114 | }
|
115 | 115 | }
|
116 | 116 | }
|
|
178 | 178 | "event_overview": event_overview,
|
179 | 179 | "omitted_segments": omitted_segments
|
180 | 180 | },
|
181 |
| - success: function(result) { |
| 181 | + success: function() { |
182 | 182 | callback(true);
|
183 | 183 | },
|
184 |
| - error: function(xhr, status, error) { |
| 184 | + error: function() { |
185 | 185 | callback(false);
|
186 | 186 | }
|
187 | 187 | });
|
|
197 | 197 | "set_visibility": visibility,
|
198 | 198 | "events": JSON.stringify(my_events)
|
199 | 199 | },
|
200 |
| - success: function(result) { |
| 200 | + success: function() { |
201 | 201 | callback(true);
|
202 | 202 | },
|
203 |
| - error: function(xhr, status, error) { |
| 203 | + error: function() { |
204 | 204 | callback(false);
|
205 | 205 | }
|
206 | 206 | });
|
|
216 | 216 | "app_id": countlyCommon.ACTIVE_APP_ID,
|
217 | 217 | "events": JSON.stringify(my_events)
|
218 | 218 | },
|
219 |
| - success: function(result) { |
| 219 | + success: function() { |
220 | 220 | callback(true);
|
221 | 221 | },
|
222 |
| - error: function(xhr, status, error) { |
| 222 | + error: function() { |
223 | 223 | callback(false);
|
224 | 224 | }
|
225 | 225 | });
|
|
263 | 263 | },
|
264 | 264 | dataType: "jsonp",
|
265 | 265 | success: function(json) {
|
266 |
| - if (currentActiveEvent == _activeEvent && currentActiveSegmentation == _activeSegmentation) { |
| 266 | + if (currentActiveEvent === _activeEvent && currentActiveSegmentation === _activeSegmentation) { |
267 | 267 | _activeLoadedEvent = _activeEvent;
|
268 | 268 | _activeLoadedSegmentation = _activeSegmentation;
|
269 | 269 | countlyCommon.extendDbObj(_activeEventDb, json);
|
|
358 | 358 | countlyEvent.getEventData = function() {
|
359 | 359 |
|
360 | 360 | var eventData = {},
|
361 |
| - mapKey = _activeEvent.replace("\\", "\\\\").replace("\$", "\\u0024").replace(".", "\\u002e"), |
| 361 | + mapKey = _activeEvent.replace("\\", "\\\\").replace("$", "\\u0024").replace(".", "\\u002e"), |
362 | 362 | eventMap = (_activeEvents) ? ((_activeEvents.map) ? _activeEvents.map : {}) : {},
|
363 | 363 | countString = (eventMap[mapKey] && eventMap[mapKey].count) ? eventMap[mapKey].count : jQuery.i18n.map["events.table.count"],
|
364 | 364 | sumString = (eventMap[mapKey] && eventMap[mapKey].sum) ? eventMap[mapKey].sum : jQuery.i18n.map["events.table.sum"],
|
|
370 | 370 | var tmpEventData = countlyCommon.extractTwoLevelData(_activeEventDb, _activeSegmentationValues, countlyEvent.clearEventsObject, [
|
371 | 371 | {
|
372 | 372 | name: "curr_segment",
|
373 |
| - func: function(rangeArr, dataObj) { |
| 373 | + func: function(rangeArr) { |
374 | 374 | return rangeArr.replace(/:/g, ".").replace(/\[CLY\]/g, "").replace(/.\/\//g, "://");
|
375 | 375 | }
|
376 | 376 | },
|
|
391 | 391 |
|
392 | 392 | if (_.reduce(segmentsSum, function(memo, num) {
|
393 | 393 | return memo + num;
|
394 |
| - }, 0) == 0) { |
| 394 | + }, 0) === 0) { |
395 | 395 | segmentsSum = [];
|
396 | 396 | }
|
397 | 397 |
|
398 | 398 | if (_.reduce(segmentsDur, function(memo, num) {
|
399 | 399 | return memo + num;
|
400 |
| - }, 0) == 0) { |
| 400 | + }, 0) === 0) { |
401 | 401 | segmentsDur = [];
|
402 | 402 | }
|
403 | 403 |
|
|
475 | 475 | return memo + num;
|
476 | 476 | }, 0);
|
477 | 477 |
|
478 |
| - if (reducedSum != 0 || reducedDur != 0) { |
479 |
| - if (reducedSum != 0) { |
| 478 | + if (reducedSum !== 0 || reducedDur !== 0) { |
| 479 | + if (reducedSum !== 0) { |
480 | 480 | eventData.tableColumns[eventData.tableColumns.length] = sumString;
|
481 | 481 | }
|
482 |
| - if (reducedDur != 0) { |
| 482 | + if (reducedDur !== 0) { |
483 | 483 | eventData.tableColumns[eventData.tableColumns.length] = durString;
|
484 | 484 | }
|
485 | 485 | }
|
|
528 | 528 | eventsWithoutOrder = [];
|
529 | 529 | for (var i = 0; i < events.length; i++) {
|
530 | 530 | var arrayToUse = eventsWithoutOrder;
|
531 |
| - var mapKey = events[i].replace("\\", "\\\\").replace("\$", "\\u0024").replace(".", "\\u002e"); |
| 531 | + var mapKey = events[i].replace("\\", "\\\\").replace("$", "\\u0024").replace(".", "\\u002e"); |
532 | 532 | if (eventOrder.indexOf(events[i]) !== -1) {
|
533 | 533 | arrayToUse = eventsWithOrder;
|
534 | 534 | }
|
|
549 | 549 | "sum": eventMap[mapKey].sum || "",
|
550 | 550 | "dur": eventMap[mapKey].dur || "",
|
551 | 551 | "is_visible": eventMap[mapKey].is_visible,
|
552 |
| - "is_active": (_activeEvent == events[i]), |
| 552 | + "is_active": (_activeEvent === events[i]), |
553 | 553 | "segments": eventSegments[mapKey] || [],
|
554 | 554 | "omittedSegments": _activeEvents.omitted_segments[mapKey] || []
|
555 | 555 | });
|
|
564 | 564 | "sum": "",
|
565 | 565 | "dur": "",
|
566 | 566 | "is_visible": true,
|
567 |
| - "is_active": (_activeEvent == events[i]), |
| 567 | + "is_active": (_activeEvent === events[i]), |
568 | 568 | "segments": eventSegments[mapKey] || [],
|
569 | 569 | "omittedSegments": _activeEvents.omitted_segments[mapKey] || []
|
570 | 570 | });
|
|
587 | 587 | eventNames = [];
|
588 | 588 |
|
589 | 589 | for (var event in eventSegmentations) {
|
590 |
| - var mapKey = event.replace("\\", "\\\\").replace("\$", "\\u0024").replace(".", "\\u002e"); |
| 590 | + var mapKey = event.replace("\\", "\\\\").replace("$", "\\u0024").replace(".", "\\u002e"); |
591 | 591 | if (eventMap[mapKey] && eventMap[mapKey].name) {
|
592 | 592 | eventNames.push({
|
593 | 593 | "key": event,
|
|
633 | 633 |
|
634 | 634 | countlyEvent.getEventLongName = function(eventKey) {
|
635 | 635 | var eventMap = (_activeEvents) ? ((_activeEvents.map) ? _activeEvents.map : {}) : {};
|
636 |
| - var mapKey = eventKey.replace("\\", "\\\\").replace("\$", "\\u0024").replace(".", "\\u002e"); |
| 636 | + var mapKey = eventKey.replace("\\", "\\\\").replace("$", "\\u0024").replace(".", "\\u002e"); |
637 | 637 | if (eventMap[mapKey] && eventMap[mapKey].name) {
|
638 | 638 | return eventMap[mapKey].name;
|
639 | 639 | }
|
|
667 | 667 |
|
668 | 668 | countlyEvent.getEventSummary = function() {
|
669 | 669 | //Update the current period object in case selected date is changed
|
670 |
| - _periodObj = countlyCommon.periodObj; |
| 670 | + var _periodObj = countlyCommon.periodObj; |
671 | 671 |
|
672 | 672 | var dataArr = {},
|
673 | 673 | tmp_x,
|
|
678 | 678 | previousSum = 0,
|
679 | 679 | currentDur = 0,
|
680 | 680 | previousDur = 0;
|
681 |
| - |
| 681 | + var segment = ""; |
| 682 | + var tmpCurrCount = 0, |
| 683 | + tmpCurrSum = 0, |
| 684 | + tmpCurrDur = 0, |
| 685 | + tmpPrevCount = 0, |
| 686 | + tmpPrevSum = 0, |
| 687 | + tmpPrevDur = 0; |
682 | 688 | if (_periodObj.isSpecialPeriod) {
|
683 | 689 | for (var i = 0; i < (_periodObj.currentPeriodArr.length); i++) {
|
684 | 690 | tmp_x = countlyCommon.getDescendantProp(_activeEventDb, _periodObj.currentPeriodArr[i]);
|
|
687 | 693 | tmp_y = countlyEvent.clearEventsObject(tmp_y);
|
688 | 694 |
|
689 | 695 | if (_activeSegmentation) {
|
690 |
| - var tmpCurrCount = 0, |
691 |
| - tmpCurrSum = 0, |
692 |
| - tmpCurrDur = 0, |
693 |
| - tmpPrevCount = 0, |
694 |
| - tmpPrevSum = 0, |
695 |
| - tmpPrevDur = 0; |
696 |
| - for (var segment in tmp_x) { |
| 696 | + |
| 697 | + for (segment in tmp_x) { |
697 | 698 | tmpCurrCount += tmp_x[segment].c || 0;
|
698 | 699 | tmpCurrSum += tmp_x[segment].s || 0;
|
699 | 700 | tmpCurrDur += tmp_x[segment].dur || 0;
|
|
733 | 734 | tmp_y = countlyEvent.clearEventsObject(tmp_y);
|
734 | 735 |
|
735 | 736 | if (_activeSegmentation) {
|
736 |
| - var tmpCurrCount = 0, |
737 |
| - tmpCurrSum = 0, |
738 |
| - tmpCurrDur = 0, |
739 |
| - tmpPrevCount = 0, |
740 |
| - tmpPrevSum = 0, |
741 |
| - tmpPrevDur = 0; |
742 |
| - for (var segment in tmp_x) { |
| 737 | + for (segment in tmp_x) { |
743 | 738 | tmpCurrCount += tmp_x[segment].c || 0;
|
744 | 739 | tmpCurrSum += tmp_x[segment].s || 0;
|
745 | 740 | tmpCurrDur += tmp_x[segment].dur || 0;
|
|
798 | 793 | };
|
799 | 794 |
|
800 | 795 | var eventMap = (_activeEvents) ? ((_activeEvents.map) ? _activeEvents.map : {}) : {},
|
801 |
| - mapKey = _activeEvent.replace("\\", "\\\\").replace("\$", "\\u0024").replace(".", "\\u002e"), |
| 796 | + mapKey = _activeEvent.replace("\\", "\\\\").replace("$", "\\u0024").replace(".", "\\u002e"), |
802 | 797 | countString = (eventMap[mapKey] && eventMap[mapKey].count) ? eventMap[mapKey].count.toUpperCase() : jQuery.i18n.map["events.count"],
|
803 | 798 | sumString = (eventMap[mapKey] && eventMap[mapKey].sum) ? eventMap[mapKey].sum.toUpperCase() : jQuery.i18n.map["events.sum"],
|
804 | 799 | durString = (eventMap[mapKey] && eventMap[mapKey].dur) ? eventMap[mapKey].dur.toUpperCase() : jQuery.i18n.map["events.dur"];
|
|
815 | 810 | ]
|
816 | 811 | };
|
817 | 812 |
|
818 |
| - if (currentSum != 0 && currentDur == 0) { |
| 813 | + if (currentSum !== 0 && currentDur === 0) { |
819 | 814 | bigNumbers.class = "two-column";
|
820 | 815 | bigNumbers.items[bigNumbers.items.length] = {
|
821 | 816 | "title": sumString,
|
|
824 | 819 | "trend": dataArr.usage["event-sum"].trend
|
825 | 820 | };
|
826 | 821 | }
|
827 |
| - else if (currentSum == 0 && currentDur != 0) { |
| 822 | + else if (currentSum === 0 && currentDur !== 0) { |
828 | 823 | bigNumbers.class = "two-column";
|
829 | 824 | bigNumbers.items[bigNumbers.items.length] = {
|
830 | 825 | "title": durString,
|
|
833 | 828 | "trend": dataArr.usage["event-dur"].trend
|
834 | 829 | };
|
835 | 830 | }
|
836 |
| - else if (currentSum != 0 && currentDur != 0) { |
| 831 | + else if (currentSum !== 0 && currentDur !== 0) { |
837 | 832 | bigNumbers.class = "threes-column";
|
838 | 833 | bigNumbers.items[bigNumbers.items.length] = {
|
839 | 834 | "title": sumString,
|
|
868 | 863 | }
|
869 | 864 | });
|
870 | 865 |
|
871 |
| - |
| 866 | + /** function extracts data for graph and chart |
| 867 | + * @param {object} dataFromDb - extracted data from db |
| 868 | + * @returns {object} graph and chart data |
| 869 | + */ |
872 | 870 | function extractDataForGraphAndChart(dataFromDb) {
|
873 | 871 | var eventData = {},
|
874 | 872 | eventMap = (_activeEvents) ? ((_activeEvents.map) ? _activeEvents.map : {}) : {},
|
875 |
| - mapKey = _activeEvent.replace("\\", "\\\\").replace("\$", "\\u0024").replace(".", "\\u002e"), |
| 873 | + mapKey = _activeEvent.replace("\\", "\\\\").replace("$", "\\u0024").replace(".", "\\u002e"), |
876 | 874 | countString = (eventMap[mapKey] && eventMap[mapKey].count) ? eventMap[mapKey].count : jQuery.i18n.map["events.table.count"],
|
877 | 875 | sumString = (eventMap[mapKey] && eventMap[mapKey].sum) ? eventMap[mapKey].sum : jQuery.i18n.map["events.table.sum"],
|
878 | 876 | durString = (eventMap[mapKey] && eventMap[mapKey].dur) ? eventMap[mapKey].dur : jQuery.i18n.map["events.table.dur"];
|
|
904 | 902 | return memo + num;
|
905 | 903 | }, 0);
|
906 | 904 |
|
907 |
| - if (reducedSum != 0 || reducedDur != 0) { |
908 |
| - if (reducedSum != 0) { |
| 905 | + if (reducedSum !== 0 || reducedDur !== 0) { |
| 906 | + if (reducedSum !== 0) { |
909 | 907 | eventData.tableColumns[eventData.tableColumns.length] = sumString;
|
910 | 908 | }
|
911 |
| - if (reducedDur != 0) { |
| 909 | + if (reducedDur !== 0) { |
912 | 910 | eventData.tableColumns[eventData.tableColumns.length] = durString;
|
913 | 911 | }
|
914 | 912 | }
|
|
947 | 945 | return eventData;
|
948 | 946 | }
|
949 | 947 | };
|
950 |
| - |
| 948 | + /** function set meta */ |
951 | 949 | function setMeta() {
|
952 | 950 | _activeSegmentationObj = _activeEventDb.meta || {};
|
953 | 951 | _activeSegmentations = _activeSegmentationObj.segments || [];
|
|
956 | 954 | }
|
957 | 955 | _activeSegmentationValues = (_activeSegmentationObj[_activeSegmentation]) ? _activeSegmentationObj[_activeSegmentation] : [];
|
958 | 956 | }
|
959 |
| - |
| 957 | + /** function extend meta */ |
960 | 958 | function extendMeta() {
|
961 | 959 | for (var metaObj in _activeEventDb.meta) {
|
962 |
| - if (_activeSegmentationObj[metaObj] && _activeEventDb.meta[metaObj] && _activeSegmentationObj[metaObj].length != _activeEventDb.meta[metaObj].length) { |
| 960 | + if (_activeSegmentationObj[metaObj] && _activeEventDb.meta[metaObj] && _activeSegmentationObj[metaObj].length !== _activeEventDb.meta[metaObj].length) { |
963 | 961 | _activeSegmentationObj[metaObj] = countlyCommon.union(_activeSegmentationObj[metaObj], _activeEventDb.meta[metaObj]);
|
964 | 962 | }
|
965 | 963 | }
|
|
0 commit comments