3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-23 12:29:26 +01:00

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 = function(dbot) {
var pages = { var pages = {
@ -7,30 +8,29 @@ var pages = function(dbot) {
var key = req.params.key.toLowerCase(); var key = req.params.key.toLowerCase();
this.db.read('poll', key, function(err, poll) { this.db.read('poll', key, function(err, poll) {
if(!err) { if(!err) {
console.log(poll);
var totalVotes = _.reduce(poll.votes, function(memo, option) { var totalVotes = _.reduce(poll.votes, function(memo, option) {
return memo += option; return memo += option;
}, 0); }, 0);
var voterNicks = []; var voterNicks = [];
/* TODO: Fix stupid fucking async issue bullshit async.each(_.keys(poll.votees), function(id, done) {
var voterNicks = _.map(poll.votees, function(vote, id) {
dbot.api.users.getUser(id, function(user) { dbot.api.users.getUser(id, function(user) {
return user.primaryNick; voterNicks.push(user.primaryNick);
done();
}); });
});*/ }, function() {
process.nextTick(function() {
console.log(voterNicks);
res.render('polls', { res.render('polls', {
'name': dbot.config.name, 'name': dbot.config.name,
'description': poll.description, 'description': poll.description,
'votees': voterNicks, 'votees': voterNicks,
'options': poll.votes, 'options': poll.votes,
locals: {
'totalVotes': totalVotes, 'totalVotes': totalVotes,
locals: {
'url_regex': RegExp.prototype.url_regex() 'url_regex': RegExp.prototype.url_regex()
} }
}); });
}); });
} else { } else {
res.render('error', { res.render('error', {

View File

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