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:
parent
33b9b8d1b0
commit
75a909df64
@ -5,28 +5,43 @@ 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);
|
||||||
res.render('polls', {
|
|
||||||
'name': dbot.config.name,
|
var voterNicks = [];
|
||||||
'description': dbot.db.polls[key].description,
|
/* TODO: Fix stupid fucking async issue bullshit
|
||||||
'votees': Object.keys(dbot.db.polls[key].votees),
|
var voterNicks = _.map(poll.votees, function(vote, id) {
|
||||||
'options': dbot.db.polls[key].votes,
|
dbot.api.users.getUser(id, function(user) {
|
||||||
locals: {
|
return user.primaryNick;
|
||||||
'totalVotes': totalVotes,
|
});
|
||||||
'url_regex': RegExp.prototype.url_regex()
|
});*/
|
||||||
}
|
|
||||||
});
|
process.nextTick(function() {
|
||||||
} else {
|
console.log(voterNicks);
|
||||||
res.render('error', {
|
res.render('polls', {
|
||||||
'name': dbot.config.name,
|
'name': dbot.config.name,
|
||||||
'message': 'No polls under that key.'
|
'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
|
// Lists all of the polls
|
||||||
'/poll': function(req, res) {
|
'/poll': function(req, res) {
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user