forked from GitHub/dbot
Web display for poll module
This commit is contained in:
parent
7124798398
commit
f70c92c16d
@ -1,4 +1,7 @@
|
||||
var poll = function(dbot) {
|
||||
if(!dbot.db.hasOwnProperty('polls')) {
|
||||
dbot.db.polls = {};
|
||||
}
|
||||
var polls = dbot.db.polls;
|
||||
var commands = {
|
||||
'~newpoll': function(event) {
|
||||
|
@ -33,6 +33,29 @@ var webInterface = function(dbot) {
|
||||
var rCategory = Object.keys(dbot.db.quoteArrs).random();
|
||||
res.render('quotes', { 'name': dbot.name, 'quotes': dbot.db.quoteArrs[rCategory], locals: { 'url_regex': RegExp.prototype.url_regex() } });
|
||||
});
|
||||
|
||||
// Lists all of the polls
|
||||
app.get('/polls', function(req, res) {
|
||||
res.render('polllist', { 'name': dbot.name, 'polllist': Object.keys(dbot.db.polls) });
|
||||
});
|
||||
|
||||
// Shows the results of a poll
|
||||
app.get('/polls/:key', function(req, res) {
|
||||
var key = req.params.key.toLowerCase();
|
||||
if(dbot.db.polls.hasOwnProperty(key)) {
|
||||
// tally the votes
|
||||
var totalVotes = 0;
|
||||
for( var v in dbot.db.polls[key].votes ) {
|
||||
var N = Number(dbot.db.polls[key].votes[v]);
|
||||
if( !isNaN(N) ) {
|
||||
totalVotes += N;
|
||||
}
|
||||
}
|
||||
res.render('polls', { 'name': dbot.name, 'description': dbot.db.polls[key].description, 'votees': 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.name, 'message': 'No polls under that key.' });
|
||||
}
|
||||
});
|
||||
|
||||
app.listen(dbot.webPort);
|
||||
|
||||
|
@ -21,6 +21,15 @@ body {
|
||||
text-shadow: 1px 1px 2px #2B2B2B;
|
||||
}
|
||||
|
||||
h1,h2 {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 15px 5px;
|
||||
}
|
||||
|
||||
div#page {
|
||||
width: 90%;
|
||||
margin: 0 auto 0 auto;
|
||||
@ -105,3 +114,34 @@ li.quote {
|
||||
img {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
/* Polls */
|
||||
#votelist {
|
||||
margin: 10px 0;
|
||||
padding: 0 40px;
|
||||
}
|
||||
|
||||
li.option {
|
||||
list-style: none;
|
||||
text-align: left;
|
||||
font-size: 1.2em;
|
||||
}
|
||||
|
||||
li.option-votes {
|
||||
list-style: none;
|
||||
text-align: left;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.vote-percentage {
|
||||
height: 20px;
|
||||
background: #444;
|
||||
}
|
||||
.vote-track {
|
||||
height: 20px;
|
||||
width: 100%;
|
||||
background: #EEE;
|
||||
margin: 2px 0;
|
||||
|
||||
box-shadow: inset 0px 0px 3px #444;
|
||||
}
|
||||
|
2
run.js
2
run.js
@ -53,7 +53,7 @@ var DBot = function(timers) {
|
||||
// Populate bot properties with config data
|
||||
this.name = this.config.name || 'dbox';
|
||||
this.admin = this.config.admin || [ 'reality' ];
|
||||
this.moduleNames = this.config.modules || [ 'ignore', 'admin', 'command', 'dice', 'js', 'kick', 'puns', 'quotes', 'spelling', 'youare' ];
|
||||
this.moduleNames = this.config.modules || [ 'ignore', 'admin', 'command', 'dice', 'js', 'kick', 'puns', 'quotes', 'spelling', 'youare', 'web', 'poll' ];
|
||||
this.language = this.config.language || 'english';
|
||||
this.webPort = this.config.webPort || 80;
|
||||
|
||||
|
7
views/polllist.jade
Normal file
7
views/polllist.jade
Normal file
@ -0,0 +1,7 @@
|
||||
div#controls
|
||||
input(type="text", name="search", id="search-text", oninput="search(this.value)")
|
||||
ul#quotelist
|
||||
-each poll in polllist
|
||||
a(href='/polls/'+poll)
|
||||
li.quotes #{poll}
|
||||
|
35
views/polls.jade
Normal file
35
views/polls.jade
Normal file
@ -0,0 +1,35 @@
|
||||
h2 #{description}
|
||||
p Voters (#{locals.totalVotes}):
|
||||
-each voter in votees
|
||||
| #{voter}
|
||||
ul#votelist
|
||||
-var hasYouTubeVids=false
|
||||
-each votes,option in options
|
||||
-var percentage = votes/locals.totalVotes*100
|
||||
-if(options.hasOwnProperty(option))
|
||||
-if(option.match(locals.url_regex))
|
||||
li.option
|
||||
-if(option.match(/(jpg|png|gif|jpeg|tiff)$/))
|
||||
a(href=option)
|
||||
img(src=option)
|
||||
-else if(option.match(/youtube.com\/watch/))
|
||||
-hasYouTubeVids = true
|
||||
span(class='ytplaceholder')
|
||||
=option
|
||||
-else
|
||||
a(href=option)
|
||||
=option
|
||||
-else
|
||||
li.option #{option}
|
||||
li.option-votes
|
||||
.vote-track
|
||||
-if(!isNaN(percentage))
|
||||
.vote-percentage(style="width: #{percentage}%")
|
||||
-if(votes == 1)
|
||||
|#{votes} vote
|
||||
-else
|
||||
|#{votes} votes
|
||||
-if(!isNaN(percentage))
|
||||
|(#{percentage.toFixed(2)}%)
|
||||
-if(hasYouTubeVids)
|
||||
script(src='/ytembed.js')
|
Loading…
Reference in New Issue
Block a user