3
0
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:
reality 2013-05-06 19:43:14 +00:00
parent 33b9b8d1b0
commit 75a909df64
2 changed files with 36 additions and 21 deletions

View File

@ -5,27 +5,42 @@ 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);
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': dbot.db.polls[key].description,
'votees': Object.keys(dbot.db.polls[key].votees),
'options': dbot.db.polls[key].votes,
'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

View File

@ -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