Refactor code for improved readability and consistency; add flash message handling and enhance quiz functionality
Some checks failed
CI / Tests (push) Failing after 9s
CI / Docker Lint (push) Successful in 4s

This commit is contained in:
2025-03-12 23:18:13 +01:00
parent 448daed6ea
commit acf5c06fcc
21 changed files with 309 additions and 80 deletions

View File

@@ -14,7 +14,7 @@
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link{% if 'backoffice_index' == app.current_route() %} active{% endif %}"
href="{{ path('backoffice_index') }}">{{ t('Seasons') }}</a>
href="{{ path('backoffice_index') }}">{{ 'Seasons'|trans }}</a>
</li>
</ul>
</div>

View File

@@ -2,11 +2,11 @@
{% block body %}
<p>
<h2>{{ t('Quiz') }}: {{ quiz.season.name }} - {{ quiz.name }}</h2>
<h2>{{ 'Quiz'|trans }}: {{ quiz.season.name }} - {{ quiz.name }}</h2>
</p>
<div id="questions">
<p>
<h4>{{ t('Questions') }}</h4>
<h4>{{ 'Questions'|trans }}</h4>
</p>
<div class="accordion">
{% for question in quiz.questions %}
@@ -17,24 +17,25 @@
data-bs-toggle="collapse"
data-bs-target="#question-{{ loop.index0 }}"
aria-controls="question-{{ loop.index0 }}">
{# {% with question_error = question.errors %} #}
{# {% if question_error %} #}
{# <span data-bs-toggle="tooltip" #}
{# title="{{ question_error }}" #}
{# class="badge text-bg-danger rounded-pill me-2">!</span> #}
{# {% endif %} #}
{# {% endwith %} #}
{% set questionErrors = question.getErrors %}
{% if questionErrors %}
<span data-bs-toggle="tooltip"
title="{{ questionErrors }}"
class="badge text-bg-danger rounded-pill me-2">!</span>
{% endif %}
{{ loop.index }}. {{ question.question }}
</button>
</h2>
<div id="question-{{ loop.index0 }}"
class="accordion-collapse collapse">
<div class="accordion-body">
{% for answer in question.answers %}
<li {% if answer.isRightAnswer %}class="text-decoration-underline"{% endif %}>{{ answer.text }}</li>
{% else %}
{{ t('There are no answers for this question') }}
{% endfor %}
<ul>
{% for answer in question.answers %}
<li {% if answer.isRightAnswer %}class="text-decoration-underline"{% endif %}>{{ answer.text }}</li>
{% else %}
{{ 'There are no answers for this question'|trans }}
{% endfor %}
</ul>
</div>
</div>
</div>
@@ -45,51 +46,54 @@
</div>
<div class="scores">
<p>
<h4>{{ t('Score') }}</h4>
<h4>{{ 'Score'|trans }}</h4>
</p>
<div class="btn-toolbar" role="toolbar">
<div class="btn-group btn-group-lg me-2">
<a class="btn btn-primary">{{ t('Start Elimination') }}</a>
<a class="btn btn-primary">{{ 'Start Elimination'|trans }}</a>
</div>
<div class="btn-group btn-group-lg">
<a class="btn btn-secondary">{{ t('Prepare Custom Elimination') }}</a>
<a class="btn btn-secondary">{{ t('Load Prepared Elimination') }}</a>
<a class="btn btn-secondary">{{ 'Prepare Custom Elimination'|trans }}</a>
<a class="btn btn-secondary">{{ 'Load Prepared Elimination'|trans }}</a>
</div>
</div>
<p>{{ t('Number of dropouts:') }} {{ quiz.dropouts }} </p>
<p>{{ 'Number of dropouts:'|trans }} {{ quiz.dropouts }} </p>
<table class="table table-hover">
<thead>
<tr>
<th scope="col">{{ t('Candidate') }}</th>
<th scope="col">{{ t('Correct Answers') }}</th>
<th scope="col">{{ t('Corrections') }}</th>
<th scope="col">{{ t('Score') }}</th>
<th scope="col">{{ t('Time') }}</th>
<th scope="col">{{ 'Candidate'|trans }}</th>
<th scope="col">{{ 'Correct Answers'|trans }}</th>
<th scope="col">{{ 'Corrections'|trans }}</th>
<th scope="col">{{ 'Score'|trans }}</th>
<th scope="col">{{ 'Time'|trans }}</th>
</tr>
</thead>
<tbody>
{# {% with result = quiz.get_score %} #}
{# {% for candidate in result %} #}
{# <tr class="table-{% if forloop.revcounter > quiz.dropouts %}success{% else %}danger{% endif %}"> #}
{# <td>{{ candidate.name }}</td> #}
{# <td>{{ candidate.correct }}</td> #}
{# <td>{{ candidate.corrections }}</td> #}
{# <td>{{ candidate.score }}</td> #}
{# <td>{{ candidate.time }}</td> #}
{# </tr> #}
{# {% empty %} #}
{# {% endfor %} #}
{% for candidate in result %}
<tr class="table-{% if loop.revindex > quiz.dropouts %}success{% else %}danger{% endif %}">
<td>{{ candidate.0.name }}</td>
<td>{{ candidate.correct|default('0') }}</td>
<td>{{ candidate.corrections|default('0') }}</td>
<td>{{ candidate.score|default('x') }}</td>
<td>{{ candidate.time }}</td>
</tr>
{% else %}
<tr>
<td colspan="5">{{ 'No results'|trans }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{# {% endwith %} #}
</div>
{% endblock %}
{% block script %}
{% block javascripts %}
<script>
const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]')
const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl))
document.addEventListener('DOMContentLoaded', function () {
const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]')
const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl))
});
</script>
{% endblock script %}
{% endblock javascripts %}
{% block title %}
{% endblock %}

View File

@@ -1,11 +1,11 @@
{% extends 'backoffice/base.html.twig' %}
{% block body %}
<p>
<h2>{{ t('Season') }}: {{ season.name }}</h2>
<h2>{{ 'Season'|trans }}: {{ season.name }}</h2>
</p>
<div class="row">
<div class="col-md-6 col-12">
<h4>{{ t('Quizzes') }}</h4>
<h4>{{ 'Quizzes'|trans }}</h4>
<div class="list-group">
{% for quiz in season.quizzes %}
<a class="list-group-item list-group-item-action{% if season.activeQuiz == quiz %} active{% endif %}"
@@ -16,7 +16,7 @@
</div>
</div>
<div class="col-md-6 col-12">
<h4>{{ t('Candidates') }}</h4>
<h4>{{ 'Candidates'|trans }}</h4>
<ul>
{% for candidate in season.candidates %}
<li>{{ candidate.name }}</li>{% endfor %}