generic question type support

This commit is contained in:
Paul Zinselmeyer 2023-11-02 22:46:38 +01:00
parent 4bf6afaf4e
commit 70b0da40dc
Signed by: pfzetto
GPG key ID: 4EEF46A5B276E648
12 changed files with 385 additions and 251 deletions

View file

@ -0,0 +1,10 @@
<article>
<h1><%= name %></h1>
<% for (index, answer) in answers.iter().enumerate() { %>
<form method="POST" hx-post="" hx-target="closest main">
<input type="hidden" name="player_id" value="<%= player_id %>"></input>
<input type="hidden" name="value" value="<%= index %>"></input>
<button type="submit"><%= answer %></button>
</form>
<% } %>
</article>

View file

@ -0,0 +1,20 @@
<% if is_correct { %>
<article>
<center><img src="/static/check.svg" width="50%"/></center>
<center><h1>Correct</h1></center>
<center><p>Your answer is correct. The correct answer is <b><%= correct_answer %></b>.</p></center>
</article>
<% } else { %>
<article>
<center><img src="/static/xmark.svg" width="50%"/></center>
<center><h1>Wrong</h1></center>
<center><p>
Your answer is incorrect. The correct answer is <b><%= correct_answer %></b>.
<% if let Some(player_answer) = player_answer { %>
You answered <b><%= player_answer %></b>.
<% } else { %>
You didn't answer the question.
<% } %>
</p></center>
</article>
<% } %>

View file

@ -0,0 +1,54 @@
<h2><%= name %></h2>
<span>Total Participants: <b><%= total_submissions %></b></span>
<% if show_result { %>
<br/>
<span>The correct answer is: <b><%= correct_answer %></b></span>
<% } %>
<canvas id="myChart"></canvas>
<script>
var ctx = document.getElementById('myChart');
var chart = new Chart(ctx, {
type: 'bar',
data: {
labels: [
<% for answer in answers.iter() { %>
"<%= answer %>",
<% } %>
],
datasets: [{
label: "# der Stimmen",
data: [
<% for submissions in submissions.iter() { %>
<%= submissions %>,
<% } %>
],
borderWidth: 1
}]
},
options: {
legend: {
display: false
},
scales: {
x: {
ticks: {
font: {
size: 64
}
}
},
y: {
beginAtZero: true,
ticks: {
font: {
size:24
}
}
}
}
}
});
</script>