Skip to content

Commit

Permalink
Improve akademie + questionnaire
Browse files Browse the repository at this point in the history
  • Loading branch information
Rayvented committed Dec 8, 2023
1 parent 39c56b6 commit 602f40d
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 33 deletions.
21 changes: 21 additions & 0 deletions assets/controllers/questionnaire_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Controller } from '@hotwired/stimulus';

export default class extends Controller {
answer() {
const self = this;
let disabledButton = true;

Array.prototype.forEach.call(document.querySelectorAll('input[type=checkbox], input[type=radio]'), function (element) {
console.log(element.checked);
if (element.checked) {
disabledButton = false;
}
});

if (disabledButton) {
document.getElementById('dynamic_question_continue').setAttribute('disabled', 'disabled');
} else {
document.getElementById('dynamic_question_continue').removeAttribute('disabled');
}
}
}
11 changes: 10 additions & 1 deletion src/Controller/KursController.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function addKurs(
if (count($errors) == 0) {
$this->em->persist($daten);
$this->em->flush();
$this->addSuccessMessage($this->translator->trans(id: 'save.successful', domain: 'general'));

return $this->redirectToRoute('kurs_anmelden', ['id' => $daten->getId()]);
}
Expand Down Expand Up @@ -110,6 +111,7 @@ public function editKurs(
if (count($errors) == 0) {
$this->em->persist($daten);
$this->em->flush();
$this->addSuccessMessage($this->translator->trans(id: 'save.changesSuccessful', domain: 'general'));
return $this->redirectToRoute('kurs_anmelden', ['id' => $daten->getId()]);
}
}
Expand Down Expand Up @@ -146,6 +148,7 @@ public function kursAnmelden(
if ($form->isSubmitted() && $form->isValid()) {
$daten = $form->getData();
$akademieService->addUser($kurs, $daten);
$this->addSuccessMessage($this->translator->trans(id: 'save.successful', domain: 'general'));

return $this->redirectToRoute('akademie_admin');
}
Expand All @@ -172,7 +175,13 @@ public function kursDeaktivieren(
return $this->redirectToRoute('akademie_admin');
}

$akademieService->removeKurs($team, $kurs);
if (!$kurs->isDeletable()) {
return $this->redirectToRoute('akademie_admin');
}

if ($akademieService->removeKurs($team, $kurs)) {
$this->addSuccessMessage($this->translator->trans(id: 'deleted', domain: 'general'));
}

return $this->redirectToRoute('akademie_admin');
}
Expand Down
2 changes: 2 additions & 0 deletions src/Controller/QuestionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public function edit(Request $request, Question $question): Response
$question = $this->handleForm($form, $question);

if ($question !== null) {
$this->addSuccessMessage($this->translator->trans(id: 'save.successful', domain: 'general'));

return $this->redirectToRoute('question_details', ['id' => $question->getId()]);
}

Expand Down
4 changes: 3 additions & 1 deletion src/Controller/QuestionnaireController.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public function edit(
$success = $this->handleForm($form);

if($success){
return $this->redirectToRoute('akademie_admin');
$this->addSuccessMessage($this->translator->trans(id: 'save.changesSuccessful', domain: 'general'));
return $this->redirect($this->generateUrl('akademie_admin') . '#tab-questionnaire');
}
}

Expand Down Expand Up @@ -115,6 +116,7 @@ public function delete(Questionnaire $questionnaire): RedirectResponse

$this->em->remove($questionnaire);
$this->em->flush();
$this->addSuccessMessage($this->translator->trans(id: 'deleted', domain: 'general'));

return $this->redirectToRoute('akademie_admin');
}
Expand Down
7 changes: 5 additions & 2 deletions src/Controller/TeamMemberController.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ public function mitgliederAdd(
$em->persist($newUser);
}
$em->flush();
$this->addSuccessMessage($this->translator->trans(id: 'save.successful', domain: 'general'));
if ($teamId) {
return $this->redirectToRoute('team_mitglieder', ['id' => $teamId]);
}
Expand Down Expand Up @@ -277,7 +278,7 @@ public function mitgliederRemove(
switch ($request->get('type')) {
case 'academy':
$member->setAkademieUser(null);
$target = $this->generateUrl('akademie_admin') . '#user';
$target = $this->generateUrl('akademie_admin') . '#tab-user';
break;
default:
if ($member !== $user && $member->hasTeam($team)) {
Expand All @@ -294,6 +295,7 @@ public function mitgliederRemove(
$em->persist($member);
$em->persist($team);
$em->flush();
$this->addSuccessMessage($this->translator->trans(id: 'deleted', domain: 'general'));
return $this->redirect($target);
}

Expand Down Expand Up @@ -341,7 +343,7 @@ public function teamMemberCreate(
$user->setAkademieUser($team);
$em->persist($user);
}
$target = $this->generateUrl('akademie_admin') . '#user';
$target = $this->generateUrl('akademie_admin') . '#tab-user';
break;
default:
if (!$user->hasTeam($team)) {
Expand All @@ -354,6 +356,7 @@ public function teamMemberCreate(
}
}
}
$this->addSuccessMessage($this->translator->trans(id: 'save.successful', domain: 'general'));
$em->flush();
return $this->redirect($target);
}
Expand Down
5 changes: 5 additions & 0 deletions src/Entity/AkademieKurse.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public function __construct()
$this->buchungen = new ArrayCollection();
}

public function isDeletable(): bool
{
return $this->getBuchungen()->isEmpty();
}

public function getId(): ?int
{
return $this->id;
Expand Down
40 changes: 25 additions & 15 deletions templates/akademie/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<th scope="col">{% trans %}assigned{% endtrans %}</th>
<th scope="col">{% trans %}startDate{% endtrans %}</th>
<th scope="col">{% trans from 'general' %}state{% endtrans %}</th>
<th scope="col">{% trans from 'questionnaire' %}passed{% endtrans %}</th>
<th scope="col">{% trans from 'general' %}action.words{% endtrans %}</th>
</tr>
</thead>
Expand All @@ -32,35 +33,44 @@
</td>
<td>{{ b.zugewiesen|date('d.m.Y') }}</td>
<td>{{ b.start|date('d.m.Y') }}</td>
<td>
{% if b.participations[0].state == 'finished' %}
{% trans from 'general' %}finished{% endtrans %}
{% else %}
{{ b.participations[0].state|trans }}
{% endif %}
</td>
<td>
{% if b.participations[0].state == 'finished' and b.participations[0].passed %}
<svg viewBox="0 0 24 24" class="text-green-600 w-5 h-5">
<path fill="currentColor"
d="M12,0A12,12,0,1,0,24,12,12.014,12.014,0,0,0,12,0Zm6.927,8.2-6.845,9.289a1.011,1.011,0,0,1-1.43.188L5.764,13.769a1,1,0,1,1,1.25-1.562l4.076,3.261,6.227-8.451A1,1,0,1,1,18.927,8.2Z">
</path>
</svg>
{% endif %}
</td>
<td>
{% if b.participations[0].state == 'finished' %}
{% if b.participations[0].passed %}
<a href="{{ path('akademie_kurs_zertifikat', {'id':b.id}) }}"
>
{% trans from 'questionnaire' %}passed{% endtrans %}
<a href="{{ path('akademie_kurs_zertifikat', {'id':b.id}) }}">
{{ 'result.success.button_cert'|trans }}
</a>
{% else %}
<a href="{{ path('participation_reset', {'id': b.participations[0].id }) }}"
>
<a href="{{ path('participation_reset', {'id': b.participations[0].id }) }}">
{% trans from 'questionnaire' %}retry{% endtrans %}
</a>
{% endif %}
{% else %}
{{ b.participations[0].state }}
{% endif %}
</td>
<td>

{% if b.participations[0].state == 'ongoing' %}
<a href="{{ path('participation_continue', {'id': b.participations[0].id}) }}"
>{% trans from 'general' %}continue{% endtrans %}</a>
<a href="{{ path('participation_continue', {'id': b.participations[0].id}) }}">
{% trans from 'general' %}continue{% endtrans %}
</a>
{% else %}
{% if b.zugewiesen < today and b.user.akademieUser in b.kurs.team and b.participations[0].state == 'assigned' %}
<a href="{{ path('akademie_kurs',{'kurs':b.id}) }}"
>
<a href="{{ path('akademie_kurs',{'kurs':b.id}) }}">
{% trans from 'general' %}start{% endtrans %}
</a>
{% else %}
{% trans from 'general' %}finished{% endtrans %}
{% endif %}
{% endif %}
</td>
Expand Down
20 changes: 12 additions & 8 deletions templates/kurs/__indexTable.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,26 @@
<tr>
<th scope="col">#</th>
<th scope="col">{% trans from 'general' %}title{% endtrans %}</th>
<th scope="col">{% trans %}buchungen{% endtrans %}</th>
<th scope="col">{% trans %}createdUpdatedAt{% endtrans %}</th>
<th scope="col">{% trans from 'general'%}action.words{% endtrans %}</th>
</tr>
</thead>
<tbody>
{% for t in kurse %}
{% for kurs in kurse %}
<tr>
<td>{{ t.id }}</td>
<td>{{ t.title }}</td>
<td>{{ t.createdAt|date('d.m.Y') }}</td>
<td>{{ kurs.id }}</td>
<td>{{ kurs.title }}</td>
<td>{{ kurs.buchungen|length }}</td>
<td>{{ kurs.createdAt|date('d.m.Y') }}</td>
<td>
<a href="{{ path('kurs_anmelden',{'id':t.id}) }}">{% trans from 'general' %}login{% endtrans %}</a>
{% if app.user == t.user %}
<a href="{{ path('akademie_kurs_edit',{'id':t.id}) }}"> {% trans from 'general' %}edit{% endtrans %}</a>
<a href="{{ path('kurs_anmelden',{'id':kurs.id}) }}">{% trans from 'general' %}login{% endtrans %}</a>
{% if app.user == kurs.user %}
<a href="{{ path('akademie_kurs_edit',{'id':kurs.id}) }}"> {% trans from 'general' %}edit{% endtrans %}</a>
{% endif %}
{% if kurs.isDeletable %}
<a class="text-danger" href="{{ path('kurs_deaktivieren',{'id':kurs.id}) }}">{% trans from 'general' %}delete{% endtrans %}</a>
{% endif %}
<a class="text-danger" href="{{ path('kurs_deaktivieren',{'id':t.id}) }}">{% trans from 'general' %}delete{% endtrans %}</a>
</td>
</tr>
{% endfor %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@

{% block body %}
{{ form_start(form) }}
<fieldset>
<fieldset data-controller="questionnaire">
<h3 class="mb-5">{{ question.label }}</h3>
{% for answer in attribute(form, question.id).children %}
<div class="form-row-checkbox">
<div class="form-check">
{{ form_widget(answer) }}
{{ form_widget(answer, {attr: {'data-action': 'click->questionnaire#answer'}}) }}
{{ form_label(answer) }}
</div>
</div>
{% endfor %}
</fieldset>
{{ form_row(form.continue, {row_attr: {class: 'form-buttons'}}) }}
{{ form_row(form.continue, {row_attr: {class: 'form-buttons'}, attr: {disabled: 'disabled'}}) }}
{{ form_end(form) }}
{% endblock %}
2 changes: 1 addition & 1 deletion templates/questionnaire/questionnaire/create.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% trans_default_domain 'questionnaire' %}

{% block title %}
{% trans %}questionnaire.create{% endtrans %}
{{ title }}
{% endblock %}

{% block body %}
Expand Down
2 changes: 0 additions & 2 deletions templates/questionnaire/questionnaire/details.html.twig
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{% extends 'base.html.twig' %}
{% trans_default_domain 'questionnaire' %}

{% set fullWidthLayout = true %}

{% block title %}
{{ 'questionnaire.show'|trans }}
{% endblock %}
Expand Down
1 change: 1 addition & 0 deletions translations/kurs/kurs.de.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
addCourse: Kurs anlegen
createdUpdatedAt: Erstellt/Upgedatet am
buchungen: Anmeldungen
actions: Aktionen
confirmAction: Möchten Sie diese Aktion wirklich durchführen?
lesson:
Expand Down
1 change: 1 addition & 0 deletions translations/kurs/kurs.en.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
addCourse: Add new course
createdUpdatedAt: Erstellt/Upgedatet am
buchungen: Anmeldungen
actions: Aktionen
confirmAction: Do you really want to execute this action?
lesson:
Expand Down
1 change: 1 addition & 0 deletions translations/kurs/kurs.ev.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
addCourse: Kurs anlegen
createdUpdatedAt: Erstellt/Upgedatet am
buchungen: Anmeldungen
actions: Aktionen
confirmAction: Möchten Sie diese Aktion wirklich durchführen?
lesson:
Expand Down
1 change: 1 addition & 0 deletions translations/kurs/kurs.fr.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
addCourse: Kurs anlegen
createdUpdatedAt: Erstellt/Upgedatet am
buchungen: Anmeldungen
actions: Aktionen
confirmAction: Möchten Sie diese Aktion wirklich durchführen?
lesson:
Expand Down

0 comments on commit 602f40d

Please sign in to comment.