mirror of
https://github.com/reality/dbot.git
synced 2024-11-23 20:39:25 +01:00
Poll web interface now working [#420]
This commit is contained in:
parent
33b9b8d1b0
commit
75a909df64
@ -5,28 +5,43 @@ var pages = function(dbot) {
|
||||
// Shows the results of a poll
|
||||
'/poll/:key': function(req, res) {
|
||||
var key = req.params.key.toLowerCase();
|
||||
if(_.has(dbot.db.polls, key)) {
|
||||
var totalVotes = _.reduce(dbot.db.polls[key].votes,
|
||||
function(memo, option) {
|
||||
this.db.read('poll', key, function(err, poll) {
|
||||
if(!err) {
|
||||
var totalVotes = _.reduce(poll.votes, function(memo, option) {
|
||||
return memo += option;
|
||||
}, 0);
|
||||
res.render('polls', {
|
||||
'name': dbot.config.name,
|
||||
'description': dbot.db.polls[key].description,
|
||||
'votees': Object.keys(dbot.db.polls[key].votees),
|
||||
'options': dbot.db.polls[key].votes,
|
||||
locals: {
|
||||
'totalVotes': totalVotes,
|
||||
'url_regex': RegExp.prototype.url_regex()
|
||||
}
|
||||
});
|
||||
} else {
|
||||
res.render('error', {
|
||||
'name': dbot.config.name,
|
||||
'message': 'No polls under that key.'
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
var voterNicks = [];
|
||||
/* TODO: Fix stupid fucking async issue bullshit
|
||||
var voterNicks = _.map(poll.votees, function(vote, id) {
|
||||
dbot.api.users.getUser(id, function(user) {
|
||||
return user.primaryNick;
|
||||
});
|
||||
});*/
|
||||
|
||||
process.nextTick(function() {
|
||||
console.log(voterNicks);
|
||||
res.render('polls', {
|
||||
'name': dbot.config.name,
|
||||
'description': poll.description,
|
||||
'votees': voterNicks,
|
||||
'options': poll.votes,
|
||||
locals: {
|
||||
'totalVotes': totalVotes,
|
||||
'url_regex': RegExp.prototype.url_regex()
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
console.log(err);
|
||||
console.log("the thing the thing");
|
||||
res.render('error', {
|
||||
'name': dbot.config.name,
|
||||
'message': 'No polls under that key.'
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// Lists all of the polls
|
||||
'/poll': function(req, res) {
|
||||
|
@ -2,7 +2,7 @@ extends ../layout
|
||||
|
||||
block content
|
||||
div#backlink
|
||||
a(href='/polls/') « Poll list
|
||||
a(href='/poll/') « Poll list
|
||||
h2 #{description}
|
||||
p Voters (#{locals.totalVotes}):
|
||||
-each voter in votees
|
||||
|
Loading…
Reference in New Issue
Block a user