forked from PeWu/osm-history
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
79 lines (70 loc) · 1.74 KB
/
app.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
var app = angular.module('osmHistory', ['ngRoute', 'leaflet-directive']);
/**
* Directive for displaying one table row with a diff between 2 versions
* of a tag.
*/
DiffRowDirective = function() {
return {
templateUrl: 'diff-row.html',
replace: true,
scope: {
key: '@',
prev: '=',
next: '=',
additional: '=',
url: '@',
context: '@',
},
};
};
/**
* Directive for displaying the OSM login/logout links.
*/
LoginDirective = function() {
return {
templateUrl: 'osm-login.html',
controller: 'LoginCtrl',
controllerAs: 'ctrl',
replace: true,
};
};
// Configure routes.
app.config(function($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'home.html',
controller: 'HomeCtrl',
controllerAs: 'ctrl',
})
.when('/:type/:id', {
templateUrl: 'history.html',
controller: 'HistoryCtrl',
controllerAs: 'ctrl',
});
});
// Disable debug logs.
app.config(function($logProvider) {
$logProvider.debugEnabled(false);
});
// Configure Analytics.
app.run(function($rootScope, $location, $window) {
$rootScope.$on('$routeChangeSuccess', event => {
if (!$window.ga) {
return;
}
// Replace numeric object ID in path with a placeholder.
var path = $location.path().replace(/\d+/, ':id');
$window.ga('send', 'pageview', { page: path });
});
});
// Services.
app.service('osmService', OsmService);
// Controllers.
app.controller('HomeCtrl', HomeCtrl);
app.controller('HistoryCtrl', HistoryCtrl);
app.controller('LoginCtrl', LoginCtrl);
// Directives.
app.directive('diffRow', DiffRowDirective);
app.directive('osmLogin', LoginDirective);
// Filters.
app.filter('capitalize', () => s => s.charAt(0).toUpperCase() + s.slice(1));