forked from mystor/gh-release-watch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.js
88 lines (76 loc) · 2.58 KB
/
routes.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
Routes = {};
if (Meteor.isClient) {
// Load google analytics
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-54612644-1', 'auto');
ga('send', 'pageview'); // TODO: Better tracking
}
RouteCore.map(function () {
Routes.home = this.route('/', function (ctx) {
// Make sure that the user is sent down to the client
// This will cause fast-render to embed the user object
// into the request to the client
this.subscribe('user');
var user = this.user();
var loggingIn = Meteor.isClient ? Meteor.loggingIn() : false;
if (user) {
this.setDefault('repoHistory', user.profile.watching);
if (Meteor.isClient)
this.set('repoHistory',
_.union(this.get('repoHistory'),
user.profile.watching));
return Layout({
user: user,
loggingIn: loggingIn
}, WatchManager({
user: user,
watching: user.profile.watching,
history: this.get('repoHistory')
}));
}
return Layout({
user: user,
loggingIn: loggingIn
}, About({loggingIn: loggingIn}));
});
Routes.unsubscribe = this.route('/unsubscribe/:token', function (ctx) {
// We want to start unsubscribed when the page loads
if (Meteor.isServer)
Meteor.call('unsubscribe', ctx.params.token);
var user = this.user();
var loggingIn = Meteor.isClient ? Meteor.loggingIn() : false;
if (this.subscribe('unsubscribe', ctx.params.token).ready()) {
var theUser = Meteor.users.findOne({ unsubscribeToken: ctx.params.token });
if (theUser) {
return Layout({
user: user,
loggingIn: loggingIn
}, Unsubscribe({ user: theUser }));
} else {
return Layout({
user: user,
loggingIn: loggingIn
}, NotFound(null));
}
} else {
// This is weird, but it happens sometimes.
// Just display the notFound template while the subscription is created.
return Layout({
user: user,
loggingIn: loggingIn
}, NotFound(null));
}
});
if (Meteor.isClient)
this.route('*', function(ctx) {
var user = this.user();
var loggingIn = Meteor.isClient ? Meteor.loggingIn() : false;
return Layout({
user: user,
loggingIn: loggingIn
}, NotFound(null));
});
});