Fix initial load

This commit is contained in:
Elton Stoneman 2018-09-26 11:58:32 +01:00
parent 97d0ae2170
commit 6356ddc7c6
3 changed files with 7 additions and 6 deletions

View File

@ -26,11 +26,11 @@ namespace Result.Data
var results = connection.Query("SELECT vote, COUNT(id) AS count FROM votes GROUP BY vote ORDER BY vote"); var results = connection.Query("SELECT vote, COUNT(id) AS count FROM votes GROUP BY vote ORDER BY vote");
if (results.Any(x => x.vote == "a")) if (results.Any(x => x.vote == "a"))
{ {
model.OptionA = results.First(x => x.vote == "a").count; model.OptionA = (int) results.First(x => x.vote == "a").count;
} }
if (results.Any(x => x.vote == "b")) if (results.Any(x => x.vote == "b"))
{ {
model.OptionB = results.First(x => x.vote == "b").count; model.OptionB = (int) results.First(x => x.vote == "b").count;
} }
model.VoteCount = model.OptionA + model.OptionB; model.VoteCount = model.OptionA + model.OptionB;
} }

View File

@ -26,12 +26,12 @@
<div id="choice"> <div id="choice">
<div class="choice resulta"> <div class="choice resulta">
<div class="label">@Model.OptionA</div> <div class="label">@Model.OptionA</div>
<div class="stat" id="optionA"></div> <div class="stat" id="optionA">50%</div>
</div> </div>
<div class="divider"></div> <div class="divider"></div>
<div class="choice resultb"> <div class="choice resultb">
<div class="label">@Model.OptionB</div> <div class="label">@Model.OptionB</div>
<div class="stat" id="optionB"></div> <div class="stat" id="optionB">50%</div>
</div> </div>
</div> </div>
</div> </div>

View File

@ -11,10 +11,11 @@ connection.on("UpdateResults", function (results) {
document.getElementById("optionA").innerText = percentages.a + "%"; document.getElementById("optionA").innerText = percentages.a + "%";
document.getElementById("optionB").innerText = percentages.b + "%"; document.getElementById("optionB").innerText = percentages.b + "%";
var totalVotes = 'No votes yet';
if (results.voteCount > 0) { if (results.voteCount > 0) {
var totalVotes = results.voteCount + (results.voteCount > 1 ? " votes" : " vote"); totalVotes = results.voteCount + (results.voteCount > 1 ? " votes" : " vote");
document.getElementById("totalVotes").innerText = totalVotes;
} }
document.getElementById("totalVotes").innerText = totalVotes;
var bg1 = document.getElementById('background-stats-1'); var bg1 = document.getElementById('background-stats-1');
var bg2 = document.getElementById('background-stats-2'); var bg2 = document.getElementById('background-stats-2');