forked from likeastore/dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreport.js
More file actions
44 lines (39 loc) · 1.09 KB
/
Copy pathreport.js
File metadata and controls
44 lines (39 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'use strict';
angular.module('dashboardApp').directive('report', function (analytics, filterEvents) {
var dates = {
today: moment(),
yesterday: moment().subtract('days', 1),
lastWeek: moment().startOf('week').subtract('weeks', 1),
lastMonth: moment().startOf('month').subtract('month', 1)
};
return {
restrict: 'E',
templateUrl: 'views/report.html',
scope: true,
link: function ($scope, elem, attrs) {
$scope.heading = attrs.periodHeading;
$scope.datePeriod = dates[attrs.date].format('DD/MM/YYYY');
function updateEvents() {
$scope.events = [];
var neededEvents = filterEvents.getEvents();
if(neededEvents) {
getData(neededEvents);
} else {
analytics.events(function(events) {
getData(events);
});
}
}
function getData(events) {
for(var i = 0; i < events.length; i++) {
var name = events[i];
analytics.report(attrs.report, dates[attrs.date], name, function (data) {
$scope.events.push({key: data.id, value: data});
});
}
}
updateEvents();
$scope.$on('eventsUpdated', updateEvents);
}
};
});