mirror of
https://github.com/overte-org/community-apps.git
synced 2025-04-25 13:52:51 +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 appButton;
|
||||||
var active = false;
|
var active = false;
|
||||||
var poll = {id: '', title: '', description: '', host: '', question: '', options: []};
|
var poll = {id: '', title: '', description: '', host: '', question: '', options: []};
|
||||||
|
var responses = {};
|
||||||
const url = Script.resolvePath("./vote.qml");
|
const url = Script.resolvePath("./vote.qml");
|
||||||
const myUuid = generateUUID(MyAvatar.sessionUUID);
|
const myUuid = generateUUID(MyAvatar.sessionUUID);
|
||||||
Messages.messageReceived.connect(receivedMessage);
|
Messages.messageReceived.connect(receivedMessage);
|
||||||
|
@ -181,6 +182,14 @@
|
||||||
Messages.sendMessage(poll.id, JSON.stringify({type: "poll_prompt", prompt: {question: poll.question, options: poll.options}}));
|
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
|
// Create a UUID or turn an existing UUID into a string
|
||||||
function generateUUID(existingUuid){
|
function generateUUID(existingUuid){
|
||||||
if (!existingUuid) existingUuid = Uuid.generate(); // Generate standard UUID
|
if (!existingUuid) existingUuid = Uuid.generate(); // Generate standard UUID
|
||||||
|
|
|
@ -385,6 +385,7 @@ Rectangle {
|
||||||
delegate: Loader {
|
delegate: Loader {
|
||||||
property int delegateIndex: index
|
property int delegateIndex: index
|
||||||
property string delegateOption: model.option
|
property string delegateOption: model.option
|
||||||
|
property int delegateRank: model.rank
|
||||||
width: poll_options.width
|
width: poll_options.width
|
||||||
|
|
||||||
sourceComponent: poll_option_template
|
sourceComponent: poll_option_template
|
||||||
|
@ -393,7 +394,60 @@ Rectangle {
|
||||||
|
|
||||||
ListModel {
|
ListModel {
|
||||||
id: poll_option_model
|
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 {
|
Rectangle {
|
||||||
property int index: delegateIndex
|
property int index: delegateIndex
|
||||||
property string option: delegateOption
|
property string option: delegateOption
|
||||||
|
property int rank: delegateRank
|
||||||
property bool selected: (active_polls_list.index_selected == index)
|
height: 60
|
||||||
property bool vote_cast: false
|
|
||||||
property bool vote_confirmed: false
|
|
||||||
height: vote_confirmed ? 100 : 60
|
|
||||||
|
|
||||||
color: index % 2 === 0 ? "transparent" : Qt.rgba(0.15,0.15,0.15,1)
|
color: index % 2 === 0 ? "transparent" : Qt.rgba(0.15,0.15,0.15,1)
|
||||||
|
|
||||||
Behavior on height {
|
|
||||||
NumberAnimation {
|
|
||||||
duration: 100
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
width: parent.width - 10
|
width: parent.width - 10
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
@ -530,10 +575,18 @@ Rectangle {
|
||||||
TextField {
|
TextField {
|
||||||
width: 50
|
width: 50
|
||||||
height: 50
|
height: 50
|
||||||
|
font.pointSize: 20
|
||||||
|
horizontalAlignment: Text.AlignHCenter
|
||||||
|
verticalAlignment: Text.AlignVCenter
|
||||||
color: "black"
|
color: "black"
|
||||||
validator: RegExpValidator { regExp: /^[0-9]$/ }
|
validator: RegExpValidator { regExp: /^[0-9]$/ }
|
||||||
inputMethodHints: Qt.ImhDigitsOnly
|
inputMethodHints: Qt.ImhDigitsOnly
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
text: rank
|
||||||
|
|
||||||
|
onTextChanged: {
|
||||||
|
poll_option_model.setProperty(index, "rank", Number(text))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
|
@ -542,7 +595,6 @@ Rectangle {
|
||||||
color: "white"
|
color: "white"
|
||||||
font.pointSize: 14
|
font.pointSize: 14
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -621,7 +673,7 @@ Rectangle {
|
||||||
prompt_question.text = message.prompt.question
|
prompt_question.text = message.prompt.question
|
||||||
for (var option of message.prompt.options){
|
for (var option of message.prompt.options){
|
||||||
console.log("adding option "+ option);
|
console.log("adding option "+ option);
|
||||||
poll_option_model.append({option: option})
|
poll_option_model.append({option: option, rank: 0})
|
||||||
}
|
}
|
||||||
// Set the options
|
// Set the options
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue