fix the poll views

This commit is contained in:
reality 2014-01-29 22:42:16 +00:00
parent faaee59116
commit 68e13e7bcd
2 changed files with 10 additions and 10 deletions

View File

@ -1,4 +1,5 @@
var _ = require('underscore')._;
var _ = require('underscore')._,
async = require('async');
var pages = function(dbot) {
var pages = {
@ -7,30 +8,29 @@ var pages = function(dbot) {
var key = req.params.key.toLowerCase();
this.db.read('poll', key, function(err, poll) {
if(!err) {
console.log(poll);
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) {
async.each(_.keys(poll.votees), function(id, done) {
dbot.api.users.getUser(id, function(user) {
return user.primaryNick;
voterNicks.push(user.primaryNick);
done();
});
});*/
process.nextTick(function() {
console.log(voterNicks);
}, function() {
res.render('polls', {
'name': dbot.config.name,
'description': poll.description,
'votees': voterNicks,
'options': poll.votes,
locals: {
'totalVotes': totalVotes,
locals: {
'url_regex': RegExp.prototype.url_regex()
}
});
});
} else {
res.render('error', {

View File

@ -4,7 +4,7 @@ block content
div#backlink
a(href='/poll/') « Poll list
h2 #{description}
p Voters (#{locals.totalVotes}):
p Voters (#{votees.length}):
-each voter in votees
| #{voter}
ul#votelist