11'use strict' ;
22
3- angular . module ( 'dashboardApp' ) . directive ( 'report' , function ( analytics ) {
3+ angular . module ( 'dashboardApp' ) . directive ( 'report' , function ( analytics , filterEvents ) {
44 var dates = {
55 today : moment ( ) ,
66 yesterday : moment ( ) . subtract ( 'days' , 1 ) ,
@@ -16,57 +16,29 @@ angular.module('dashboardApp').directive('report', function (analytics) {
1616 $scope . heading = attrs . periodHeading ;
1717 $scope . datePeriod = dates [ attrs . date ] . format ( 'DD/MM/YYYY' ) ;
1818
19- analytics . report ( attrs . report , dates [ attrs . date ] , 'user-registered' , function ( data ) {
20- $scope . registered = data ;
21- } ) ;
22-
23- analytics . report ( attrs . report , dates [ attrs . date ] , 'user-verified' , function ( data ) {
24- $scope . verified = data ;
25- } ) ;
26-
27- analytics . report ( attrs . report , dates [ attrs . date ] , 'user-logged-on' , function ( data ) {
28- $scope . loggedOn = data ;
29- } ) ;
30-
31- analytics . report ( attrs . report , dates [ attrs . date ] , 'network-created' , function ( data ) {
32- $scope . networksCreated = data ;
33- } ) ;
34-
35- analytics . report ( attrs . report , dates [ attrs . date ] , 'search' , function ( data ) {
36- $scope . searches = data ;
37- } ) ;
38-
39- analytics . report ( attrs . report , dates [ attrs . date ] , 'share-like' , function ( data ) {
40- $scope . shares = data ;
41- } ) ;
42-
43- analytics . report ( attrs . report , dates [ attrs . date ] , 'share-with-friend' , function ( data ) {
44- $scope . sends = data ;
45- } ) ;
46-
47- analytics . report ( attrs . report , dates [ attrs . date ] , 'account-deactivated' , function ( data ) {
48- $scope . deactivated = data ;
49- } ) ;
50-
51- analytics . report ( attrs . report , dates [ attrs . date ] , 'collection-created' , function ( data ) {
52- $scope . collectionsCreated = data ;
53- } ) ;
54-
55- analytics . report ( attrs . report , dates [ attrs . date ] , 'collection-shared' , function ( data ) {
56- $scope . collectionsShared = data ;
57- } ) ;
58-
59- analytics . report ( attrs . report , dates [ attrs . date ] , 'collection-followed' , function ( data ) {
60- $scope . collectionsFollowed = data ;
61- } ) ;
62-
63- analytics . report ( attrs . report , dates [ attrs . date ] , 'collection-unfollowed' , function ( data ) {
64- $scope . collectionsUnfollowed = data ;
65- } ) ;
66-
67- analytics . report ( attrs . report , dates [ attrs . date ] , 'collection-item-added' , function ( data ) {
68- $scope . collectionsItemsAdded = data ;
69- } ) ;
19+ function updateEvents ( ) {
20+ $scope . events = [ ] ;
21+ var neededEvents = filterEvents . getEvents ( ) ;
22+ if ( neededEvents ) {
23+ getData ( neededEvents ) ;
24+ } else {
25+ analytics . events ( function ( events ) {
26+ getData ( events ) ;
27+ } ) ;
28+ }
29+ }
30+
31+ function getData ( events ) {
32+ for ( var i = 0 ; i < events . length ; i ++ ) {
33+ var name = events [ i ] ;
34+ analytics . report ( attrs . report , dates [ attrs . date ] , name , function ( data ) {
35+ $scope . events . push ( { key : data . id , value : data } ) ;
36+ } ) ;
37+ }
38+ }
39+
40+ updateEvents ( ) ;
41+ $scope . $on ( 'eventsUpdated' , updateEvents ) ;
7042 }
7143 } ;
7244} ) ;
0 commit comments