Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/priority voting visualization #76

Merged
merged 7 commits into from
Dec 19, 2023
12 changes: 11 additions & 1 deletion decide/booth/static/booth/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,14 @@ textarea {

.input-group i {
font-size: 1.5em;
}
}

.select {
padding: 6px;
margin-right: 5px;
margin-bottom: 5px;
border-radius: 0.25em;
box-shadow: 0 0 2px rgba(0, 0, 0, 0.5);
color: var(--input-text);
font-family: var(--fuente2);
}
56 changes: 46 additions & 10 deletions decide/booth/templates/booth/booth.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,34 @@
<div class="card-voting" v-if="!signup">
<h1 class="voting-title">[[ voting.name ]]</h1>
<h2 class="voting-desc">[[ voting.question.desc ]]</h2>
<form v-for="opt in voting.question.options" :key="opt.number">
<form>
<div class="form-options">
<input type="radio" v-model="selected" v-if="questionType == 'S' || questionType == 'B'"
:id="'q' + opt.number"
name="question"
:value="opt.number">
<input type="checkbox" v-model="selected" v-if="questionType == 'M'"
:id="'q' + opt.number"
name="question"
:value="opt.number">
[[ opt.option ]]
<div v-if="questionType == 'S' || questionType == 'B' || questionType == 'M'" v-for="opt in voting.question.options" :key="opt.number">
<input type="radio" v-model="selected" v-if="questionType == 'S' || questionType == 'B'"
:id="'q' + opt.number"
name="question"
:value="opt.number">
<input type="checkbox" v-model="selected" v-if="questionType == 'M'"
:id="'q' + opt.number"
name="question"
:value="opt.number">

[[ opt.option ]]
</div>
<div v-if="questionType == 'P'">
<br>
<p> Remember that 1 is the highest priority and [[voting.question.options.length]] is the lowest priority</p>
<br>
<div v-for="(opt, index) in voting.question.options">
<select class="select" v-model="selected[index]">
<option v-for="opt in voting.question.options">
[[ opt.number ]]
</option>
</select> [[opt.option]]
<div>Selected priority of [[ selected[index] ]] for [[opt.option]]</div>
<br>
</div>
</div>
</div>
</form>
<button class="btn btn-vote mt-3" v-on:click="decideSend">
Expand Down Expand Up @@ -255,6 +272,25 @@ <h2 class="voting-desc">[[ voting.question.desc ]]</h2>
token: this.token
}
}
else if (this.questionType === 'P') {
var selectedOptions = this.voting.question.options.map((opt, index) => [opt.number, this.selected[index]]);
var vote = []
var priorities = selectedOptions.map((opt) => opt[1]);
var prioritiesSet = new Set(priorities);
if (priorities.length > prioritiesSet.size){
return
}
for (i=0; i < selectedOptions.length; i++){
var v = this.decideEncrypt(selectedOptions[i][0].toString())
vote.push({a: v.alpha.toString(), b: v.beta.toString(), p: selectedOptions[i][1].toString()})
}
var data = {
vote: vote,
voting: this.voting.id,
voter: this.user.id,
token: this.token
}
}

this.postData("{% url "gateway" "store" "/" %}", data)
.then(data => {
Expand Down