From 75a909df64a50fdbad0dcdd9d28510501550ee1c Mon Sep 17 00:00:00 2001 From: reality Date: Mon, 6 May 2013 19:43:14 +0000 Subject: [PATCH] Poll web interface now working [#420] --- modules/poll/pages.js | 55 +++++++++++++++++++++++++++---------------- views/poll/polls.jade | 2 +- 2 files changed, 36 insertions(+), 21 deletions(-) diff --git a/modules/poll/pages.js b/modules/poll/pages.js index 2f7d721..9fc08b8 100644 --- a/modules/poll/pages.js +++ b/modules/poll/pages.js @@ -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) { diff --git a/views/poll/polls.jade b/views/poll/polls.jade index 80e25f6..72f654e 100644 --- a/views/poll/polls.jade +++ b/views/poll/polls.jade @@ -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