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

Merge branch '56-display-results-in-results-part' into 'master'

Feat : display round results in results section

Closes #56

See merge request apoyen/elections!53
parents 1a49b451 4366f362
No related branches found
No related tags found
1 merge request!53Feat : display round results in results section
Pipeline #6228 passed
......@@ -99,8 +99,8 @@ class ResultComponent {
</button>
</header>
<div class="card-content">
<div id="round-list" class="content">
Résultats détaillés du tour
<div id="detailed-results" class="content">
<h5 class="title is-5">Résultats détaillés du tour</h5>
</div>
</div>
</div>
......@@ -121,12 +121,11 @@ class ResultComponent {
</div>`;
}
async progressBarTemplate(candidateList) {
let party = await this.PartyModel.getParty(candidateList.PartyID);
progressBarTemplate(candidateList, color) {
return /* HTML */ `<div class="progressBar">
<div
class="progressBarValue"
style="background-color : ${party.Color}; width : ${candidateList.Percentage}%"
style="background-color : ${color}; width : ${candidateList.Percentage}%"
>
${candidateList.Name +
" (" +
......@@ -236,33 +235,37 @@ class ResultComponent {
}
displayResults() {
console.log(this.results);
document.getElementById("news-flow").innerHTML = "";
if (this.zone === "areas") {
this.displayFlowAreas();
} else if (this.zone === "sections") {
this.displayFlowSections();
}
let scroller = Scroller.scrollInit("news-flow");
this.displayRoundResults();
Scroller.scrollInit("news-flow");
}
async displayFlowAreas() {
let resultHandler = this;
this.results.areasResults.sort(function (a, b) {
return b.DateCompletion - a.DateCompletion;
});
for (let j in this.results.areasResults) {
let area = this.results.areasResults[j];
if (area.status === resultHandler.filter) {
if (area.status === this.filter) {
document.getElementById(
"news-flow"
).innerHTML += this.resultFlowTemplate(area);
for (let i in area.candidateLists) {
let party = await this.PartyModel.getParty(
area.candidateLists[i].PartyID
);
document.getElementById(
"flow-content-" + area.ID
).innerHTML += await resultHandler.progressBarTemplate(
area.candidateLists[i]
).innerHTML += await this.progressBarTemplate(
area.candidateLists[i],
party.Color
);
}
}
......@@ -270,7 +273,6 @@ class ResultComponent {
}
async displayFlowSections() {
let resultHandler = this;
let sections = [];
this.results.areasResults.forEach((area) => {
sections = sections.concat(area.Sections);
......@@ -281,19 +283,36 @@ class ResultComponent {
for (let j in sections) {
let section = sections[j];
if (section.status === resultHandler.filter) {
if (section.status === this.filter) {
document.getElementById(
"news-flow"
).innerHTML += this.resultFlowTemplate(section);
for (let i in section.candidateLists) {
let party = await this.PartyModel.getParty(
section.candidateLists[i].PartyID
);
document.getElementById(
"flow-content-" + section.ID
).innerHTML += await resultHandler.progressBarTemplate(
section.candidateLists[i]
).innerHTML += await this.progressBarTemplate(
section.candidateLists[i],
party.Color
);
}
}
}
}
displayRoundResults() {
document.getElementById("detailed-results").innerHTML = `<h5 class="title is-5">Résultats détaillés du tour</h5>`;
for (let i in this.results.roundResults) {
document.getElementById(
"detailed-results"
).innerHTML += this.progressBarTemplate(
this.results.roundResults[i],
this.results.roundResults[i].Color
);
}
}
}
......@@ -123,6 +123,9 @@ class DirectMetropolitanCalculator {
},
currentParty.VoiceNumber
);
currentParty.Percentage = Number(
(currentParty.VoiceNumber / this.stats.VotesExpressed) * 100
).toFixed(2);
}
});
party = currentParty;
......@@ -226,8 +229,9 @@ class DirectMetropolitanCalculator {
},
0
);
candidateList.Percentage =
Number((candidateList.VoiceNumber / area.stats.VotesExpressed) * 100).toFixed(2);
candidateList.Percentage = Number(
(candidateList.VoiceNumber / area.stats.VotesExpressed) * 100
).toFixed(2);
});
area.candidateLists = candidateListToKeep;
area.candidateLists.sort((a, b) => {
......@@ -291,7 +295,7 @@ class DirectMetropolitanCalculator {
section.status = "validated";
} else {
section.status = "not validated";
return section ;
return section;
}
}
......@@ -307,8 +311,9 @@ class DirectMetropolitanCalculator {
},
0
);
candidateList.Percentage =
Number((candidateList.VoiceNumber / section.stats.VotesExpressed) * 100).toFixed(2);
candidateList.Percentage = Number(
(candidateList.VoiceNumber / section.stats.VotesExpressed) * 100
).toFixed(2);
});
section.candidateLists = candidateLists;
section.candidateLists.sort((a, b) => {
......
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