mirror of
https://github.com/AleziaKurdis/Overte-community-apps.git
synced 2025-04-05 13:37:41 +02:00
Fixed votes counted not being counted.
This commit is contained in:
parent
3067deab63
commit
e00e78aa24
2 changed files with 37 additions and 53 deletions
|
@ -18,6 +18,7 @@
|
|||
// TODO: Voting results page
|
||||
// TODO: Joining poll sometimes causes to double stack on other clients poll_list?
|
||||
// TODO: Do active polls persist across domain leave? If so close them on session leave
|
||||
// FIXME: Empty arrays in responses don't count as valid votes anymore? Causes miscounts?
|
||||
|
||||
(() => {
|
||||
"use strict";
|
||||
|
@ -280,6 +281,10 @@
|
|||
function _debugDummyBallot() {
|
||||
if (!debug) return; // Just incase...
|
||||
let ballot = getRandomOrder(...poll.options);
|
||||
|
||||
const indexToRemove = Math.floor(Math.random() * ballot.length);
|
||||
ballot.splice(indexToRemove, 1);
|
||||
|
||||
const responsesKeyName = Object.keys(responses).length.toString();
|
||||
responses[responsesKeyName] = ballot;
|
||||
|
||||
|
@ -288,6 +293,7 @@
|
|||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[words[i], words[j]] = [words[j], words[i]];
|
||||
}
|
||||
|
||||
return words;
|
||||
}
|
||||
}
|
||||
|
@ -398,6 +404,10 @@
|
|||
poll.question = message.prompt.question;
|
||||
}
|
||||
|
||||
if (message.type == "vote_count") {
|
||||
_emitEvent({type: "received_vote", voteCount: message.voteCount});
|
||||
}
|
||||
|
||||
// Received a ballot
|
||||
if (message.type == "vote") {
|
||||
// Check if we are the host
|
||||
|
@ -409,12 +419,13 @@
|
|||
// Emit a echo so the voter knows we have received it
|
||||
// TODO:
|
||||
|
||||
// console.log(JSON.stringify(responses));
|
||||
// Broadcast the updated count to all clients
|
||||
Messages.sendMessage(poll.id, JSON.stringify({type: "vote_count", voteCount: Object.keys(responses).length}));
|
||||
}
|
||||
|
||||
// Winner was broadcasted
|
||||
if (message.type == "poll_winner") {
|
||||
_emitEvent({type: "poll_winner", winner: message.winner, rounds: message.rounds, votesCounted: message.votes});
|
||||
_emitEvent({type: "poll_winner", winner: message.winner, rounds: message.rounds, votesCounted: message.votesCounted});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -544,12 +544,30 @@ Rectangle {
|
|||
font.pointSize: 12
|
||||
}
|
||||
Text {
|
||||
id: tally_votes_received
|
||||
text: "0"
|
||||
color: "white"
|
||||
font.pointSize: 14
|
||||
}
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
width: parent.width
|
||||
|
||||
Text {
|
||||
text: "Votes counted:"
|
||||
color: "gray"
|
||||
Layout.fillWidth: true
|
||||
font.pointSize: 12
|
||||
}
|
||||
Text {
|
||||
id: tally_votes_counted
|
||||
text: "-"
|
||||
color: "white"
|
||||
font.pointSize: 14
|
||||
}
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
width: parent.width
|
||||
|
||||
|
@ -560,6 +578,7 @@ Rectangle {
|
|||
font.pointSize: 12
|
||||
}
|
||||
Text {
|
||||
id: tally_votes_itterations
|
||||
text: "-"
|
||||
color: "white"
|
||||
font.pointSize: 14
|
||||
|
@ -645,57 +664,6 @@ Rectangle {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: View a list of the ballots and the results of the election rounds
|
||||
// Item {
|
||||
// Layout.fillHeight: true
|
||||
// Layout.fillWidth: true
|
||||
|
||||
// // TODO: Allow scrolling
|
||||
// ScrollView {
|
||||
// // ScrollBar.horizontal.policy: ScrollBar.AlwaysOn
|
||||
// // ScrollBar.vertical.policy: ScrollBar.AlwaysOff
|
||||
// clip: true
|
||||
// width: parent.width
|
||||
// height: parent.height
|
||||
|
||||
// ColumnLayout {
|
||||
// Repeater {
|
||||
// model: 3
|
||||
// ColumnLayout {
|
||||
// Text {
|
||||
// text: "Round "+ index +": Eleminated XXX"
|
||||
// font.pointSize: 18
|
||||
// color: "white"
|
||||
// }
|
||||
|
||||
// Repeater {
|
||||
// model: 20
|
||||
|
||||
// RowLayout {
|
||||
// height: 30
|
||||
|
||||
// Repeater {
|
||||
// model: 4
|
||||
// Item {
|
||||
// width: 100
|
||||
// height: 30
|
||||
|
||||
// Text {
|
||||
// text: 'One ' + index
|
||||
// color: "white"
|
||||
// font.pointSize: 12
|
||||
// width: parent.width - 10
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
@ -966,6 +934,11 @@ Rectangle {
|
|||
break;
|
||||
case "poll_winner":
|
||||
poll_winner.text = message.winner
|
||||
tally_votes_itterations.text = message.rounds
|
||||
tally_votes_counted.text = message.votesCounted
|
||||
break;
|
||||
case "received_vote":
|
||||
tally_votes_received.text = message.voteCount
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue