-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathPageViews.Controller.js
119 lines (96 loc) · 5.69 KB
/
PageViews.Controller.js
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
angular.module("umbraco").controller("Analytics.PageViewsController",
function ($scope, $location, $routeParams, statsResource, analyticsSettingsResource, dateRangeService, localizationService, navigationService) {
var profileID = "";
// items list array
$scope.items = [];
$scope.itemSources = [];
$scope.dateFilter = analyticsSettingsResource.getDateFilter();
$scope.$watch('dateFilter', function () {
analyticsSettingsResource.setDateFilter($scope.dateFilter.startDate, $scope.dateFilter.endDate);
//Get Profile
analyticsSettingsResource.getprofile().then(function (response) {
$scope.profile = response.data;
profileID = response.data.Id;
if (profileID == null || profileID == "") {
$location.path("/analytics/analyticsTree/edit/settings");
return;
}
//Get chart data for monthly visit chart
statsResource.getvisitcharts(profileID, $scope.dateFilter.startDate, $scope.dateFilter.endDate).then(function (response) {
var chartData = response.data;
var canvasId = "viewMonths";
var canvas = document.getElementById(canvasId),
canvasWidth = canvas.clientWidth,
canvasHeight = canvas.clientHeight;
// Replace the chart canvas element
$('#' + canvasId).replaceWith('<canvas id="' + canvasId + '" width="' + canvasWidth + '" height="' + canvasHeight + '"></canvas>');
var options = {
labelTemplate: "<ul class=\"<%=name.toLowerCase()%>-legend\">"
+ "<% for (var i=0; i<datasets.length; i++){%>"
+ "<li><span style=\"background-color:<%=datasets[i].fillColor%>;border-color:<%=datasets[i].strokeColor%>\"></span>"
+ "<%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%>"
+ "</ul>"
};
// Draw the chart / Create Line Chart
var ctx = $('#' + canvasId).get(0).getContext("2d");
var viewMonthsChart = new Chart(ctx).Line(chartData, options);
// Create legend
var legendHolder = document.createElement('div');
legendHolder.className = "chart-legend-holder";
legendHolder.innerHTML = viewMonthsChart.generateLegend();
var helpers = Chart.helpers;
helpers.each(legendHolder.firstChild.childNodes, function (legendNode, index) {
if (index == 0) {
localizationService.localize("analytics_visits").then(function (value) {
var text = value != null ? value : "Visits";
var t = document.createTextNode(text);
legendNode.appendChild(t);
legendNode.className = "first";
});
}
else if (index == 1) {
localizationService.localize("analytics_pageViews").then(function (value) {
var text = value != null ? value : "Page Views";
var t = document.createTextNode(text);
legendNode.appendChild(t);
legendNode.className = "second";
});
}
});
// ensure legend not gets added multiple times
$(".chart-legend-holder").remove();
viewMonthsChart.chart.canvas.parentNode.appendChild(legendHolder);
});
//Get Browser via statsResource - does WebAPI GET call
statsResource.getvisits(profileID, $scope.dateFilter.startDate, $scope.dateFilter.endDate).then(function (response) {
$scope.views = response.data;
$scope.loadingViews = false;
// clear existing items
$scope.items.length = 0;
// push objects to items array
angular.forEach($scope.views.Rows, function (item) {
$scope.items.push({
pagepath: item.Cells[0].Value,
visits: parseInt(item.Cells[1].Value),
pageviews: parseInt(item.Cells[2].Value)
});
});
});
//Get Browser specific via statsResource - does WebAPI GET call
statsResource.getsources(profileID, $scope.dateFilter.startDate, $scope.dateFilter.endDate).then(function (response) {
$scope.sources = response.data;
// clear existing items
$scope.itemSources.length = 0;
// push objects to items array
angular.forEach($scope.sources.Rows, function (item) {
$scope.itemSources.push({
s_source: item.Cells[0].Value,
s_visits: parseInt(item.Cells[1].Value),
s_pageviews: parseInt(item.Cells[2].Value)
});
});
});
});
});
navigationService.syncTree({ tree: 'analyticsTree', path: ["-1", $routeParams.id], forceReload: false });
});