-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.coffee
78 lines (72 loc) · 2.49 KB
/
routes.coffee
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
# ██████╗ ██████╗ ██╗ ██╗████████╗███████╗███████╗
# ██╔══██╗██╔═══██╗██║ ██║╚══██╔══╝██╔════╝██╔════╝
# ██████╔╝██║ ██║██║ ██║ ██║ █████╗ ███████╗
# ██╔══██╗██║ ██║██║ ██║ ██║ ██╔══╝ ╚════██║
# ██║ ██║╚██████╔╝╚██████╔╝ ██║ ███████╗███████║
#
# Configure routes in iron-router.
#
# This is file #3 created at 1:24AM, the first day of MHacks.
# -> Some kids are playing mario-kart, and are very loud. At 1:30Am.
# Global configuration.
Router.configure
layoutTemplate: 'ApplicationLayout'
waitOn: ->
return [Meteor.subscribe("events")]
Router.onBeforeAction ->
if Meteor.isClient
unless currentEventValid()
return @render "events"
@next()
Router.onBeforeAction ->
return @next() if Meteor.isServer
unless Meteor.userId()?
@render 'login'
else
@next()
# Check if the event still exists and if not redirect
# usage: return if eventRedirect @
currentEventValid = ->
events = Events.find().fetch()
return true if events.length is 0
selEvent = Session.get "selectedEvent"
if selEvent?
now = new Date().getTime()
eve = Events.findOne {_id: selEvent}
if eve? and eve.start.getTime() < now and eve.end.getTime() > now
return true
if events.length is 1
Session.set "selectedEvent", events[0]._id
Meteor.call "setCurrentEvent", events[0]._id, ->
console.log "Changed current event to #{events[0]._id}"
return true
Session.set "selectedEvent", null
false
Router.route '/',
action: ->
req = getActiveRequest()
if req?
@redirect "/request/#{req._id}"
else
@render "requests"
waitOn: ->
if Meteor.isClient
Meteor.subscribe "requests", Session.get("selectedEvent")
else
Meteor.subscribe "requests", null
fastRender: true
Router.route '/request/:reqid',
fastRender: true
waitOn: ->
if Meteor.isClient
Meteor.subscribe "requests", Session.get("selectedEvent")
else
Meteor.subscribe "requests", null
action: ->
req = getActiveRequest()
unless req?
@redirect "/"
else
@render "activeRequest",
data: ->
req