mirror of
https://github.com/MarijnDoeve/TijdVoorDeTest.git
synced 2026-07-07 08:00:15 +02:00
feat: quiz page question rework (#181)
- Replace Bootstrap accordion with flat card list for questions - Add HTML5 drag-and-drop reordering with placeholder-between-cards UX and amber/green/red save status indicator next to the heading - Add edit button per question opening a Bootstrap modal (bo--modal-form Stimulus controller with X-Modal-Request header pattern) - Show read-only view button instead of edit for locked/finalized quizzes - Add BankQuestion edit modal in question bank tab using same infrastructure - Move modal action buttons into modal-footer via <template data-modal-footer> - Fix IS_AUTHENTICATED_FULLY 403: replace ROLE_USER with IS_AUTHENTICATED on all backoffice controllers and in security.yaml access_control
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
<p class="fw-semibold mb-3">{{ question.question }}</p>
|
||||
|
||||
<ul class="list-group">
|
||||
{% for answer in question.answers %}
|
||||
<li class="list-group-item d-flex justify-content-between align-items-center">
|
||||
<span{% if answer.isRightAnswer %} class="fw-semibold"{% endif %}>
|
||||
{% if answer.isRightAnswer %}<i class="bi bi-check-circle-fill text-success me-1"></i>{% endif %}
|
||||
{{ answer.text }}
|
||||
</span>
|
||||
{% if answer.candidates|length > 0 %}
|
||||
<span class="text-muted small">{{ answer.candidates|map(c => c.name)|join(', ') }}</span>
|
||||
{% endif %}
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="list-group-item text-muted">{{ 'There are no answers for this question'|trans }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
<template data-modal-footer>
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">{{ 'Close'|trans }}</button>
|
||||
</template>
|
||||
@@ -0,0 +1,35 @@
|
||||
{% import 'backoffice/partials/answer_row.html.twig' as macros %}
|
||||
|
||||
{{ form_start(form) }}
|
||||
{{ form_row(form.question) }}
|
||||
|
||||
<div data-controller="bo--form-collection"
|
||||
data-bo--form-collection-prototype-value="{{ macros.answer_row(form.answers.vars.prototype)|e('html_attr') }}">
|
||||
{{ form_label(form.answers) }}
|
||||
{{ form_errors(form.answers) }}
|
||||
<div data-bo--form-collection-target="collection">
|
||||
{% for answerForm in form.answers %}
|
||||
{{ macros.answer_row(answerForm) }}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% do form.answers.setRendered %}
|
||||
<div class="d-flex gap-2 mb-3">
|
||||
<button type="button" class="btn btn-sm btn-outline-primary"
|
||||
data-action="bo--form-collection#addItem">{{ 'Add answer'|trans }}</button>
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary"
|
||||
data-action="bo--form-collection#sortAlphabetically">{{ 'Sort A–Z'|trans }}</button>
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary"
|
||||
data-action="bo--form-collection#randomize">{{ 'Randomize'|trans }}</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if isModal ?? false %}
|
||||
{% do form.save.setRendered %}
|
||||
{% endif %}
|
||||
{{ form_end(form) }}
|
||||
{% if isModal ?? false %}
|
||||
<template data-modal-footer>
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">{{ 'Cancel'|trans }}</button>
|
||||
<button type="submit" form="{{ form.vars.id }}" class="btn btn-primary">{{ 'Save'|trans }}</button>
|
||||
</template>
|
||||
{% endif %}
|
||||
@@ -18,31 +18,7 @@
|
||||
<div class="row">
|
||||
<div class="col-md-6 col-12">
|
||||
<h2 class="mb-3">{{ 'Edit question'|trans }}</h2>
|
||||
|
||||
{{ form_start(form) }}
|
||||
{{ form_row(form.question) }}
|
||||
|
||||
<div data-controller="bo--form-collection"
|
||||
data-bo--form-collection-prototype-value="{{ macros.answer_row(form.answers.vars.prototype)|e('html_attr') }}">
|
||||
{{ form_label(form.answers) }}
|
||||
{{ form_errors(form.answers) }}
|
||||
<div data-bo--form-collection-target="collection">
|
||||
{% for answerForm in form.answers %}
|
||||
{{ macros.answer_row(answerForm) }}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% do form.answers.setRendered %}
|
||||
<div class="d-flex gap-2 mb-3">
|
||||
<button type="button" class="btn btn-sm btn-outline-primary"
|
||||
data-action="bo--form-collection#addItem">{{ 'Add answer'|trans }}</button>
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary"
|
||||
data-action="bo--form-collection#sortAlphabetically">{{ 'Sort A–Z'|trans }}</button>
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary"
|
||||
data-action="bo--form-collection#randomize">{{ 'Randomize'|trans }}</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{ form_end(form) }}
|
||||
{{ include('backoffice/quiz/_question_form_body.html.twig') }}
|
||||
</div>
|
||||
<div class="col-md-6 col-12">
|
||||
{{ include('backoffice/help/quiz_question_bank_form.html.twig') }}
|
||||
|
||||
@@ -85,51 +85,73 @@
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<h4 class="mb-3">{{ 'Questions'|trans }}</h4>
|
||||
<div class="accordion">
|
||||
{%~ for question in quiz.questions ~%}
|
||||
<div class="accordion-item">
|
||||
<h2 class="accordion-header">
|
||||
<button class="accordion-button collapsed"
|
||||
type="button"
|
||||
data-bs-toggle="collapse"
|
||||
data-bs-target="#question-{{ loop.index0 }}"
|
||||
aria-controls="question-{{ loop.index0 }}">
|
||||
{% set questionError = questionErrors[question.id.toString] ?? null %}
|
||||
<span
|
||||
class="badge rounded-pill me-2{% if questionError %} text-bg-danger{% else %} invisible{% endif %}"{% if questionError %} data-bs-toggle="tooltip" title="{{ questionError }}"{% endif %}>!</span>
|
||||
{{~ loop.index -}}. {{ question.question -}}
|
||||
</button>
|
||||
</h2>
|
||||
<div id="question-{{ loop.index0 }}"
|
||||
class="accordion-collapse collapse">
|
||||
<div class="accordion-body">
|
||||
{% if is_granted('QUIZ_MODIFY_CONTENT', question) %}
|
||||
<a class="btn btn-sm btn-outline-secondary mb-2"
|
||||
href="{{ path('tvdt_backoffice_quiz_question_edit', {seasonCode: season.seasonCode, quiz: quiz.id, question: question.id}) }}">
|
||||
<i class="bi bi-pencil"></i> {{ 'Edit'|trans }}
|
||||
</a>
|
||||
{% endif %}
|
||||
<ul>
|
||||
{%~ for answer in question.answers %}
|
||||
<li{% if answer.isRightAnswer %} class="text-decoration-underline"{% endif %}>
|
||||
{{ answer.text }}
|
||||
{% if answer.candidates|length > 0 %}
|
||||
<small class="text-muted">
|
||||
({{ answer.candidates|map(c => c.name)|join(', ') }})
|
||||
</small>
|
||||
{% endif %}
|
||||
</li>
|
||||
{%~ else %}
|
||||
{{ 'There are no answers for this question'|trans -}}
|
||||
{%~ endfor %}
|
||||
</ul>
|
||||
<div data-controller="bo--question-list bo--modal-form"
|
||||
data-bo--question-list-reorder-url-value="{{ path('tvdt_backoffice_quiz_questions_reorder', {seasonCode: season.seasonCode, quiz: quiz.id}) }}"
|
||||
data-bo--question-list-csrf-value="{{ csrf_token('question_reorder') }}"
|
||||
data-bo--question-list-can-modify-value="{{ is_granted('QUIZ_MODIFY_CONTENT', quiz) ? 'true' : 'false' }}"
|
||||
data-bo--question-list-saved-label-value="{{ 'Order saved'|trans }}"
|
||||
data-bo--question-list-error-label-value="{{ 'Error saving order'|trans }}">
|
||||
|
||||
<h4 class="mb-3 d-flex align-items-center gap-2">
|
||||
{{ 'Questions'|trans }}
|
||||
<span class="badge d-none fw-normal" style="font-size:.7rem;vertical-align:baseline" data-bo--question-list-target="status"></span>
|
||||
</h4>
|
||||
|
||||
<div data-bo--question-list-target="list">
|
||||
{%~ for question in quiz.questions ~%}
|
||||
<div class="card mb-2"
|
||||
data-bo--question-list-target="item"
|
||||
data-question-id="{{ question.id }}">
|
||||
<div class="card-body py-2">
|
||||
<div class="d-flex align-items-center gap-2">
|
||||
{% if is_granted('QUIZ_MODIFY_CONTENT', question) %}
|
||||
<span class="text-muted" style="cursor:grab" data-drag-handle>
|
||||
<i class="bi bi-grip-vertical"></i>
|
||||
</span>
|
||||
{% endif %}
|
||||
<div class="flex-grow-1">
|
||||
{% set questionError = questionErrors[question.id.toString] ?? null %}
|
||||
<span class="badge rounded-pill me-1{% if questionError %} text-bg-danger{% else %} invisible{% endif %}"
|
||||
{% if questionError %}data-bs-toggle="tooltip" title="{{ questionError }}"{% endif %}>!</span>
|
||||
<strong><span data-question-number>{{ loop.index }}</span>. {{ question.question }}</strong>
|
||||
</div>
|
||||
{% if is_granted('QUIZ_MODIFY_CONTENT', question) %}
|
||||
<button class="btn btn-sm btn-outline-secondary flex-shrink-0"
|
||||
data-action="click->bo--modal-form#open"
|
||||
data-url="{{ path('tvdt_backoffice_quiz_question_edit', {seasonCode: season.seasonCode, quiz: quiz.id, question: question.id}) }}"
|
||||
data-modal-title="{{ 'Edit question'|trans }}">
|
||||
<i class="bi bi-pencil"></i> {{ 'Edit'|trans }}
|
||||
</button>
|
||||
{% elseif quiz.isLocked %}
|
||||
<button class="btn btn-sm btn-outline-secondary flex-shrink-0"
|
||||
data-action="click->bo--modal-form#open"
|
||||
data-url="{{ path('tvdt_backoffice_quiz_question_view', {seasonCode: season.seasonCode, quiz: quiz.id, question: question.id}) }}"
|
||||
data-modal-title="{{ 'Question details'|trans }}">
|
||||
<i class="bi bi-eye"></i> {{ 'View'|trans }}
|
||||
</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
{{ 'EMPTY'|trans }}
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="modal fade" tabindex="-1"
|
||||
data-bo--modal-form-target="modal"
|
||||
aria-labelledby="questionEditModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="questionEditModalLabel">{{ 'Edit question'|trans }}</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body" data-bo--modal-form-target="modalBody"></div>
|
||||
<div class="modal-footer" data-bo--modal-form-target="modalFooter"></div>
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
{{ 'EMPTY'|trans }}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{ _self.confirm_modal(
|
||||
|
||||
Reference in New Issue
Block a user