Skip to content

Commit 15427a0

Browse files
committed
Merge pull request #2 from jincod/master
get event names from server
2 parents a3e90fc + 8a8cb28 commit 15427a0

8 files changed

Lines changed: 113 additions & 117 deletions

File tree

app/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<!-- endbuild -->
2222

2323
<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.3.0/pure-min.css">
24+
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css">
2425
</head>
2526
<body ng-app="dashboardApp">
2627
<!--[if lt IE 7]>
@@ -56,6 +57,7 @@ <h1>Likeastore. Analytics</h1>
5657

5758
<script src="scripts/services/api.js"></script>
5859
<script src="scripts/services/analytics.js"></script>
60+
<script src="scripts/services/filter-events.js"></script>
5961

6062
<script src="scripts/infrastructure/authorization.js"></script>
6163
<script src="scripts/infrastructure/config.js"></script>
Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
'use strict';
22

3-
angular.module('dashboardApp').controller('dashboard', function () {
4-
// do nothing
3+
angular.module('dashboardApp').controller('dashboard', function ($scope, analytics, filterEvents) {
4+
$scope.filtredEvents = [];
5+
analytics.events(function(events) {
6+
$scope.filtredEvents = filterEvents.filter(events);
7+
});
8+
9+
$scope.apply = function() {
10+
filterEvents.setEvents($scope.filtredEvents);
11+
$scope.$broadcast('eventsUpdated');
12+
};
13+
14+
$scope.checkAll = function() {
15+
angular.forEach($scope.filtredEvents, function(item) {
16+
item.value = true;
17+
});
18+
};
519
});

app/scripts/directives/report.js

Lines changed: 24 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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
});

app/scripts/services/analytics.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ angular.module('dashboardApp').factory('analytics', function ($http, config) {
88
report: function (report, date, id, callback) {
99
var query = url + '/api/reports/' + report + '/' + app + '?id=' + id + '&date=' + date.format('YYYY-MM-DD');
1010
return $http({method: 'GET', url: query}).success(callback);
11+
},
12+
events: function (callback) {
13+
var query = url + '/api/events/events/' + app;
14+
return $http({method: 'GET', url: query}).success(callback);
15+
},
16+
ids: function (callback) {
17+
var query = url + '/api/events/ids/' + app;
18+
return $http({method: 'GET', url: query}).success(callback);
1119
}
1220
};
1321
});
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict';
2+
3+
angular.module('dashboardApp').service('filterEvents', function() {
4+
this.getEvents = function() {
5+
return localStorage.neededEvents && JSON.parse(localStorage.neededEvents);
6+
};
7+
8+
this.filter = function(events) {
9+
var result = [],
10+
neededEvents = localStorage.neededEvents && JSON.parse(localStorage.neededEvents);
11+
if(!neededEvents) {
12+
result = events.map(function(event) {
13+
return {
14+
key: event,
15+
value: true
16+
}
17+
});
18+
} else {
19+
for(var i = 0; i < events.length; i++) {
20+
var value = neededEvents.indexOf(events[i]) != -1 || false;
21+
result.push({key: events[i], value: value});
22+
}
23+
}
24+
this.setEvents(result);
25+
return result;
26+
};
27+
28+
this.setEvents = function(events) {
29+
var result = events
30+
.filter(function(item) {
31+
return item.value;
32+
}).map(function(item) {
33+
return item.key;
34+
});
35+
localStorage.neededEvents = JSON.stringify(result);
36+
};
37+
});

app/styles/main.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,7 @@ input {
7474
.login-panel form {
7575
padding: 16px 0;
7676
}
77+
78+
.filter {
79+
padding: 10px 0 0 180px;
80+
}

app/views/dashboard.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
11
<div class="reports">
2+
<div class="filter">
3+
<button class="pure-button" ng-model="isShow" ng-click="isShow=!isShow">
4+
<i class="fa fa-filter"></i>
5+
Filter Events
6+
</button>
7+
<div ng-show="isShow">
8+
<form class="pure-form" ng-submit="apply()">
9+
<label for="option-one-{{event.key}}" class="pure-checkbox" ng-repeat="event in filtredEvents">
10+
<input id="option-one-{{event.key}}" type="checkbox" ng-model="event.value">
11+
{{event.key}}
12+
</label>
13+
<div class="pure-button" ng-click="checkAll()">
14+
All
15+
</div>
16+
<input type="submit" class="pure-button pure-button-primary" value="Apply">
17+
</form>
18+
</div>
19+
</div>
220
<report data-period-heading="Today" data-report="day" data-date="today"></report>
321
<report data-period-heading="Yesterday" data-report="day" data-date="yesterday"></report>
422
<report data-period-heading="Week" data-report="week" data-date="today"></report>

app/views/report.html

Lines changed: 4 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -5,68 +5,9 @@
55
</div>
66
</div>
77
<div class="pure-g-r">
8-
9-
<div class="pure-u-1-6 report">
10-
<span class="total">{{registered.total}}</span>
11-
<p>users registered</p>
12-
</div>
13-
14-
<div class="pure-u-1-6 report">
15-
<span class="total">{{verified.total}}</span>
16-
<p>users verified</p>
17-
</div>
18-
19-
<div class="pure-u-1-6 report">
20-
<span class="total">{{deactivated.total}}</span>
21-
<p>accounts deleted</p>
22-
</div>
23-
24-
<div class="pure-u-1-6 report">
25-
<span class="total">{{shares.total}}</span>
26-
<p>likes shared</p>
27-
</div>
28-
29-
<div class="pure-u-1-6 report">
30-
<span class="total">{{networksCreated.total}}</span>
31-
<p>networks enabled</p>
32-
</div>
33-
34-
<div class="pure-u-1-6 report">
35-
<span class="total">{{searches.total}}</span>
36-
<p>searches performed</p>
37-
</div>
38-
39-
</div>
40-
<div class="pure-g-r">
41-
42-
<div class="pure-u-1-6 report">
43-
<span class="total">{{collectionsCreated.total}}</span>
44-
<p>collections created</p>
45-
</div>
46-
47-
<div class="pure-u-1-6 report">
48-
<span class="total">{{collectionsShared.total}}</span>
49-
<p>collections shared</p>
50-
</div>
51-
52-
<div class="pure-u-1-6 report">
53-
<span class="total">{{collectionsFollowed.total}}</span>
54-
<p>collections followed</p>
55-
</div>
56-
57-
<div class="pure-u-1-6 report">
58-
<span class="total">{{collectionsUnfollowed.total}}</span>
59-
<p>collections unfollowed</p>
60-
</div>
61-
62-
<div class="pure-u-1-6 report">
63-
<span class="total">{{collectionsItemsAdded.total}}</span>
64-
<p>collections item added</p>
65-
</div>
66-
67-
<div class="pure-u-1-6 report">
68-
<span class="total">{{sends.total}}</span>
69-
<p>send to friends</p>
8+
<div class="pure-u-1-6 report" ng-repeat="event in events">
9+
<span class="total">{{event.value.total}}</span>
10+
<p>{{event.key}}</p>
7011
</div>
7112
</div>
72-
</div>
13+
</div>

0 commit comments

Comments
 (0)