mirror of
https://github.com/overte-org/community-apps.git
synced 2025-04-25 08:43:13 +02:00
Creating and sending ballot.
This commit is contained in:
parent
efc64c6cd7
commit
28ef700a6e
2 changed files with 74 additions and 13 deletions
|
@ -22,6 +22,7 @@
|
|||
var appButton;
|
||||
var active = false;
|
||||
var poll = {id: '', title: '', description: '', host: '', question: '', options: []};
|
||||
var responses = {};
|
||||
const url = Script.resolvePath("./vote.qml");
|
||||
const myUuid = generateUUID(MyAvatar.sessionUUID);
|
||||
Messages.messageReceived.connect(receivedMessage);
|
||||
|
@ -181,6 +182,14 @@
|
|||
Messages.sendMessage(poll.id, JSON.stringify({type: "poll_prompt", prompt: {question: poll.question, options: poll.options}}));
|
||||
}
|
||||
|
||||
// Take the gathered responses and preform the election
|
||||
function preformElection(){
|
||||
// Get the array of responses in a list
|
||||
let voteList = Object.values(responses);
|
||||
|
||||
console.log(voteList)
|
||||
}
|
||||
|
||||
// Create a UUID or turn an existing UUID into a string
|
||||
function generateUUID(existingUuid){
|
||||
if (!existingUuid) existingUuid = Uuid.generate(); // Generate standard UUID
|
||||
|
|
|
@ -385,6 +385,7 @@ Rectangle {
|
|||
delegate: Loader {
|
||||
property int delegateIndex: index
|
||||
property string delegateOption: model.option
|
||||
property int delegateRank: model.rank
|
||||
width: poll_options.width
|
||||
|
||||
sourceComponent: poll_option_template
|
||||
|
@ -393,7 +394,60 @@ Rectangle {
|
|||
|
||||
ListModel {
|
||||
id: poll_option_model
|
||||
}
|
||||
}
|
||||
|
||||
// Add Option Button
|
||||
Item {
|
||||
width: parent.width
|
||||
height: 40
|
||||
|
||||
RowLayout {
|
||||
anchors.centerIn: parent
|
||||
|
||||
Rectangle {
|
||||
width: 150
|
||||
height: 40
|
||||
color: "#c0bfbc"
|
||||
|
||||
Text {
|
||||
anchors.centerIn: parent
|
||||
text:"Cast ballot"
|
||||
color: "black"
|
||||
font.pointSize:18
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
|
||||
|
||||
// TODO: Turn into function and move to root
|
||||
onClicked: {
|
||||
var votes = {};
|
||||
var orderedArray = [];
|
||||
|
||||
// Find all options and order then from first to last
|
||||
// poll_option_model.get(i) gets them in order
|
||||
|
||||
for (var i = 0; i < poll_option_model.count; ++i) {
|
||||
var option = poll_option_model.get(i); //
|
||||
|
||||
// FIXME: Stringify this or make it JSON safe. Requires cross-verification
|
||||
votes[option.option] = option.rank
|
||||
}
|
||||
|
||||
// TODO: This is painful to look at.
|
||||
// Sort the object from lowest to heighest
|
||||
var entries = Object.entries(votes);
|
||||
entries.sort((a, b) => a[1] - b[1]);
|
||||
// Get names instead of numbers
|
||||
var onlyNames = entries.map((entry) => entry[0]);
|
||||
|
||||
// Send our ballot to the host (by sending it to everyone in the poll lol)
|
||||
toScript({type: "cast_vote", ballot: onlyNames});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -505,20 +559,11 @@ Rectangle {
|
|||
Rectangle {
|
||||
property int index: delegateIndex
|
||||
property string option: delegateOption
|
||||
|
||||
property bool selected: (active_polls_list.index_selected == index)
|
||||
property bool vote_cast: false
|
||||
property bool vote_confirmed: false
|
||||
height: vote_confirmed ? 100 : 60
|
||||
property int rank: delegateRank
|
||||
height: 60
|
||||
|
||||
color: index % 2 === 0 ? "transparent" : Qt.rgba(0.15,0.15,0.15,1)
|
||||
|
||||
Behavior on height {
|
||||
NumberAnimation {
|
||||
duration: 100
|
||||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
width: parent.width - 10
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
|
@ -530,10 +575,18 @@ Rectangle {
|
|||
TextField {
|
||||
width: 50
|
||||
height: 50
|
||||
font.pointSize: 20
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
color: "black"
|
||||
validator: RegExpValidator { regExp: /^[0-9]$/ }
|
||||
inputMethodHints: Qt.ImhDigitsOnly
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
text: rank
|
||||
|
||||
onTextChanged: {
|
||||
poll_option_model.setProperty(index, "rank", Number(text))
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
|
@ -542,7 +595,6 @@ Rectangle {
|
|||
color: "white"
|
||||
font.pointSize: 14
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -621,7 +673,7 @@ Rectangle {
|
|||
prompt_question.text = message.prompt.question
|
||||
for (var option of message.prompt.options){
|
||||
console.log("adding option "+ option);
|
||||
poll_option_model.append({option: option})
|
||||
poll_option_model.append({option: option, rank: 0})
|
||||
}
|
||||
// Set the options
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue