Browse files

Changing voting room data structures.

  • Loading branch information...
1 parent b9f53d8 commit eff73d3ace0c2fe66e0e8157768d4bd5f287f589 Jonas Galvez committed Aug 29, 2010
Showing with 18 additions and 10 deletions.
  1. +11 −8 pagetalk.js
  2. +7 −2 static/js/voting-room.js
View
19 pagetalk.js
@@ -49,7 +49,13 @@ http_server.post('/voting-room', function(req, res) {
var voting_room_id = create_random_id(10);
while(poorsman_mongodb.voting_rooms[voting_room_id])
voting_room_id = create_random_id(10);
- var vr = poorsman_mongodb.voting_rooms[voting_room_id] = voting_room_data;
+ var vr = poorsman_mongodb.voting_rooms[voting_room_id] = {
+ 'voting_room_id': voting_room_id,
+ 'options': {}
+ };
+ for(var i = 0, len = voting_room_data.options.length; i < len; i++) {
+ vr.options[voting_room_data.options[i].title] = {'votes': 0};
+ }
vr.voting_room_id = voting_room_id;
res.redirect('/voting-room/' + voting_room_id);
});
@@ -62,18 +68,15 @@ socket_server.on('connection', function(client) {
var voting_room_id = message.voting_room_id;
poorsman_mongodb.connected_clients[client.sessionId] = message;
if(message.pick) {
- if(poorsman_mongodb.voting_rooms[voting_room_id][message.pick] == undefined) {
- poorsman_mongodb.voting_rooms[voting_room_id][message.pick] = 0;
- }
- poorsman_mongodb.voting_rooms[voting_room_id][message.pick]++;
+ poorsman_mongodb.voting_rooms[voting_room_id].options[message.pick].votes++;
}
client.broadcast({'options': poorsman_mongodb.voting_rooms[voting_room_id]});
});
client.on('disconnect', function() {
var message = poorsman_mongodb.connected_clients[client.sessionId];
var voting_room_id = message.voting_room_id;
if(message.pick) {
- poorsman_mongodb.voting_rooms[voting_room_id][message.pick]--;
+ poorsman_mongodb.voting_rooms[voting_room_id].options[message.pick].votes--;
}
client.broadcast(poorsman_mongodb.voting_rooms[voting_room_id]);
});
@@ -84,8 +87,8 @@ socket_server.on('connection', function(client) {
setInterval(function() {
for(var voting_room_id in poorsman_mongodb.voting_rooms) {
- socket_server.broadcast({'options': poorsman_mongodb.voting_rooms[voting_room_id]});
+ socket_server.broadcast(poorsman_mongodb.voting_rooms[voting_room_id]);
}
-}, 10000)
+}, 10000);
http_server.listen(80);
View
9 static/js/voting-room.js
@@ -12,8 +12,13 @@ nodevote.ui.create_bar = function(height, color) {
$(document).ready(function() {
socket_client = new io.Socket(null, {port: 80});
socket_client.connect();
- on_message = function(options) {
-
+ var on_message = function(options) {
+ var total_height = $(window).height();
+ var bar;
+ for(var i = 0, len = options.options.length; i < len; i++) {
+ bar = nodevote.ui.create_bar(60, options.options.fore);
+ bar
+ }
}
socket_client.on('message', on_message);
nodevote.ui.handlers['freeze'] = {

0 comments on commit eff73d3

Please sign in to comment.