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 // Shows the results of a poll
'/poll/:key': function(req, res) { '/poll/:key': function(req, res) {
var key = req.params.key.toLowerCase(); var key = req.params.key.toLowerCase();
if(_.has(dbot.db.polls, key)) { this.db.read('poll', key, function(err, poll) {
var totalVotes = _.reduce(dbot.db.polls[key].votes, if(!err) {
function(memo, option) { var totalVotes = _.reduce(poll.votes, function(memo, option) {
return memo += option; return memo += option;
}, 0); }, 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', { res.render('polls', {
'name': dbot.config.name, 'name': dbot.config.name,
'description': dbot.db.polls[key].description, 'description': poll.description,
'votees': Object.keys(dbot.db.polls[key].votees), 'votees': voterNicks,
'options': dbot.db.polls[key].votes, 'options': poll.votes,
locals: { locals: {
'totalVotes': totalVotes, 'totalVotes': totalVotes,
'url_regex': RegExp.prototype.url_regex() 'url_regex': RegExp.prototype.url_regex()
} }
}); });
});
} else { } else {
console.log(err);
console.log("the thing the thing");
res.render('error', { res.render('error', {
'name': dbot.config.name, 'name': dbot.config.name,
'message': 'No polls under that key.' 'message': 'No polls under that key.'
}); });
} }
});
}, },
// Lists all of the polls // Lists all of the polls

View File

@ -2,7 +2,7 @@ extends ../layout
block content block content
div#backlink div#backlink
a(href='/polls/') « Poll list a(href='/poll/') « Poll list
h2 #{description} h2 #{description}
p Voters (#{locals.totalVotes}): p Voters (#{locals.totalVotes}):
-each voter in votees -each voter in votees