-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrum.js
executable file
·111 lines (92 loc) · 3 KB
/
scrum.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
/**
* Copyright (C) 2012 Marco Jahn and Remko Plantenga
*/
var http = require('http'),
express = require('express'),
channels = require('./channels'),
app = express();
app.set('view engine', 'coffee');
app.engine('coffee', require('coffeecup').__express);
// TODO:https://groups.google.com/group/express-js/browse_thread/thread/e94bcd01cd454c7d/f4ff4f37a111a1ea
app.use('/statics/scripts', express.static(__dirname + '/statics/scripts'));
app.use('/statics/styles', express.static(__dirname + '/statics/styles'));
app.use(express.logger());
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser('steffi'));
app.use(express.session());
app.get('/', function (req, res) {
res.render('index');
});
app.post('/login', function (req, res) {
req.session.username = req.body.username;
res.redirect('/channel');
});
app.get('/channel', function (req, res) {
res.render('channels', {
locals: {
channels: channels.list()
}
});
});
app.post('/channel', function (req, res) {
channels.create(req.body.name);
res.redirect('/channel');
});
app.get('/channel/:name?', function (req, res) {
var channelname = req.params.name;
if (channelname) {
channels.join(channelname, req.session.username);
res.redirect('/channel/' + channelname + '/story');
} else {
res.send('error 1');
}
});
app.get('/channel/:name?/story', function (req, res) {
var channelname = req.params.name;
if (channelname) {
res.render('stories', {
locals: {
channel: channels.list()[channelname]
}
});
} else {
res.send('error 3');
}
});
app.post('/channel/:name/story', function (req, res) {
var channelname = req.params.name;
if (channelname) {
channels.createStory(channelname, req.body.task, req.body.description);
res.redirect('/channel/' + channelname + '/story');
} else {
res.send('error 2');
}
});
app.get('/channel/:name/story/:id', function (req, res) {
var channelname = req.params.name,
storyid = req.params.id;
res.render('votes', {
locals: {
votes: channels.listVotes(channelname, storyid)
}
});
});
app.put('/channel/:name/story/:id', function (req, res) {
var voteResult,
channelname = req.params.name,
storyid = req.params.id,
points = req.body.points;
console.log('voting to channel {'+channelname+'}, story {'+storyid+'} with points {'+points+'}');
if (channelname) {
voteResult = channels.vote(channelname, storyid, points, req.session.username);
if (voteResult) {
res.redirect('/channel/' + channelname + '/story');
} else {
res.send('error 4');
}
} else {
res.send('error 5');
}
});
http.createServer(app).listen(8080);