Skip to content
Snippets Groups Projects
Commit e1ce07e2 authored by Alexis POYEN's avatar Alexis POYEN
Browse files

Feat : display votes captured

parent 13d401a1
No related branches found
No related tags found
1 merge request!42Resolve "Capture votes"
......@@ -6,6 +6,8 @@ import * as AreaModel from "/services/model/area-model.js";
import * as SectionModel from "/services/model/section-model.js";
import * as DeskModel from "/services/model/desk-model.js";
import * as DeskRoundModel from "/services/model/deskRound-model.js";
import * as VoteModel from "/services/model/vote-model.js";
import * as CandidateListModel from "/services/model/candidateList-model.js";
export async function mount(parent) {
const voteComponent = new Vote(parent);
......@@ -22,6 +24,8 @@ class Vote {
this.SectionModel = SectionModel.getSectionModel();
this.DeskModel = DeskModel.getDeskModel();
this.DeskRoundModel = DeskRoundModel.getDeskRoundModel();
this.VoteModel = VoteModel.getVoteModel();
this.CandidateListModel = CandidateListModel.getCandidateListModel();
}
async displayVotes(RoundID, AreaID, DeskRoundID) {
......@@ -31,6 +35,8 @@ class Vote {
this.SectionModel.current_user = await Auth.GetUser();
this.DeskModel.current_user = await Auth.GetUser();
this.DeskRoundModel.current_user = await Auth.GetUser();
this.VoteModel.current_user = await Auth.GetUser();
this.CandidateListModel.current_user = await Auth.GetUser();
this.RoundID = RoundID;
this.AreaID = AreaID;
......@@ -44,7 +50,7 @@ class Vote {
</nav>
</p>
</header>
<div id="votes-tables" class="card-content"></div>
<div id="votes-table" class="card-content"></div>
<nav class="level">
<div class="level-left"></div>
<div class="level-right">
......@@ -63,9 +69,28 @@ class Vote {
this.handleDom();
await this.refreshBreadCrumb();
await this.loadVotes();
}
voteTemplate(candidateList) {
return /* HTML */ `
<tr id="votes-vote-${candidateList.ID}">
<td>
${candidateList.Name}
</td>
<td>
<input
class="input"
type="number"
id="${candidateList.ID}-vote-voice"
/>
</td>
</tr>
`;
}
handleDom() {}
async refreshBreadCrumb() {
let round = await this.RoundModel.getRound(this.RoundID);
let election = await this.ElectionModel.getElection(round.ElectionID);
......@@ -96,4 +121,67 @@ class Vote {
el.innerHTML = "<a>" + desk.Name + "</a>";
breadcrumb.appendChild(el);
}
async loadVotes() {
document.getElementById("votes-table").innerHTML = /* HTML */ `<div
class="table-container"
>
<table class="table is-bordered is-narrow is-hoverable is-fullwidth">
<thead>
<tr class="is-selected">
<th>Liste</th>
<th>Nombre de voix</th>
</tr>
</thead>
<tbody id="votes-list"></tbody>
</table>
</div> `;
let voteHandler = this;
let votes = await this.VoteModel.getVotes();
votes = votes.filter((vote) => {
return vote.DeskRoundID == voteHandler.DeskRoundID;
});
console.log(votes);
let candidateLists = await this.CandidateListModel.getCandidateLists();
candidateLists = candidateLists.filter((candidateList) => {
return candidateList.AreaID == voteHandler.AreaID;
});
const markup = candidateLists
.map((vote) => this.voteTemplate(vote))
.join("");
document.getElementById("votes-list").innerHTML = markup;
document.getElementById("votes-list").innerHTML += /* HTML */ `
<tr">
<td>Votes blanc</td>
<td>
<input
class="input"
type="number"
id="blank-vote-voice"
/>
</td>
</tr>
`;
document.getElementById("votes-list").innerHTML += /* HTML */ `
<tr>
<td>Votes nul</td>
<td>
<input class="input" type="number" id="null-vote-voice" />
</td>
</tr>
`;
votes.forEach((vote) => {
if (vote.Blank) {
document.getElementById("blank-vote-voice").value = vote.VoiceNumber;
} else if (vote.NullVote) {
document.getElementById("null-vote-voice").value = vote.VoiceNumber;
} else {
document.getElementById(vote.CandidateListID + "-vote-voice").value =
vote.VoiceNumber;
}
});
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment