forked from nate-strauser/wework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.js
222 lines (206 loc) · 5.79 KB
/
router.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
Router.configure({
layoutTemplate: 'layout',
loadingTemplate: 'loading',
yieldTemplates: {
header: {
to: 'header'
},
footer: {
to: 'footer'
}
},
progressSpinner: false,
progressDelay: 250,
title: "Tiny Gigs - Job board and developer listing just for Tiny Gigs"
});
Router.map(function() {
this.route('home', {
path: '/',
layoutTemplate: 'layoutNoContainer',
data: function() {
return {
jobs: Jobs.find({
featuredThrough: {
$exists: false
},
status: "active"
}, {
sort: {
createdAt: -1
},
limit: 10
}),
featuredJobs: Jobs.find({
featuredThrough: {
$gte: new Date()
},
status: "active"
}, {
sort: {
featuredThrough: -1
}
}),
profiles: Profiles.find({}, {
sort: {
availableForHire: -1,
randomSorter: 1
},
limit: 8
}),
profile: Profiles.findOne({
userId: Meteor.userId()
})
};
},
subscriptions: function() {
return [subs.subscribe('homeJobs'), subs.subscribe('featuredJobs'), subs.subscribe('homeDevelopers')];
}
});
this.route('jobs', {
path: '/jobs',
title: "Tiny Gigs - All Jobs"
});
this.route('myJobs', {
path: '/myjobs',
title: "Tiny Gigs - My Jobs",
data: function() {
return {
jobs: Jobs.find({
userId: Meteor.userId()
}, {
sort: {
createdAt: -1
}
})
};
},
waitOn: function() {
return subs.subscribe('my_jobs');
}
});
this.route('job', {
path: '/jobs/:_id/:slug?',
title: function() {
if (this.data())
return "Tiny Gigs - " + this.data().title;
},
data: function() {
return Jobs.findOne({
_id: this.params._id
});
},
waitOn: function() {
return subs.subscribe("job", this.params._id);
},
onBeforeAction: function() {
var expectedSlug = this.data().slug();
if (this.params.slug !== expectedSlug) {
this.redirect("job", {
_id: this.params._id,
slug: expectedSlug
});
} else {
this.next();
}
}
});
this.route('jobNew', {
path: '/job',
title: "Tiny Gigs - Post a Job"
});
this.route('jobEdit', {
path: '/jobs/:_id/:slug/edit',
title: "Tiny Gigs - Edit Job Post",
data: function() {
return {
job: Jobs.findOne({
_id: this.params._id
})
};
},
waitOn: function() {
return subs.subscribe("job", this.params._id);
}
});
this.route('profiles', {
path: '/profiles',
title: "Tiny Gigs - All Developers",
subscriptions: function() {
return subs.subscribe('developerUsers');
}
});
this.route('profile', {
path: '/profiles/:_id/:slug?',
title: function() {
if (this.data())
return "Tiny Gigs - " + this.data().displayName() + " - " + this.data().title;
},
data: function() {
return Profiles.findOne({
_id: this.params._id
});
},
waitOn: function() {
return subs.subscribe('profile', this.params._id);
},
onBeforeAction: function() {
var expectedSlug = this.data().slug();
if (this.params.slug !== expectedSlug) {
this.redirect("profile", {
_id: this.params._id,
slug: expectedSlug
});
} else {
this.next();
}
}
});
this.route('profileNew', {
path: '/profile',
title: "Tiny Gigs - Create Developer Profile",
onBeforeAction: function() {
if (Meteor.user().isDeveloper) {
Router.go('profile', Profiles.findOne({
userId: Meteor.userId()
}));
} else {
this.next();
}
}
});
this.route('profileEdit', {
path: '/profiles/:_id/:slug/edit',
title: "Tiny Gigs - Edit My Developer Profile",
data: function() {
return {
profile: Profiles.findOne({
_id: this.params._id
})
};
},
waitOn: function() {
return subs.subscribe('profile', this.params._id);
}
});
//legacy url redirects
this.route('experts', function() {
this.redirect("profiles");
});
this.route('experts/:_id', function() {
this.redirect("profile", {
_id: this.params._id
});
});
});
Router.plugin('ensureSignedIn', {
only: ['profileEdit', 'profileNew', 'jobEdit', 'jobNew']
});
Router.onBeforeAction(function() {
loadUploadcare();
this.next();
}, {
only: ['profileEdit', 'profileNew', 'jobEdit', 'jobNew']
});
Router.plugin('dataNotFound', {
notFoundTemplate: 'notFound'
});