diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4d56b58..5eccf8b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,9 +33,9 @@ jobs: *.cache-from=type=gha,scope=refs/heads/main *.cache-to=type=gha,scope=${{github.ref}},mode=max - name: Start services - run: docker compose up php --wait --no-build + run: docker compose up php database --wait --no-build - name: Lint Twig templates - run: php bin/console lint:twig --format=github templates + run: docker compose exec -T php bin/console lint:twig --format=github templates - name: Coding Style run: docker compose exec -T php vendor/bin/php-cs-fixer check --diff --show-progress=none - name: Twig Coding Style diff --git a/.idea/php.xml b/.idea/php.xml index f2c155a..84b5fd3 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -41,164 +41,164 @@ - - - - - - - - - - - - - - - - - - - - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - + + + + - - - - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - + + + + + + + + + + + + + + + + + + + + diff --git a/Justfile b/Justfile index 619a258..3da51c2 100644 --- a/Justfile +++ b/Justfile @@ -34,3 +34,8 @@ rector *args: phpstan *args: docker compose exec php vendor/bin/phpstan analyse {{ args }} + +[confirm] +clean: + docker compose down -v --remove-orphans + rm -rf vendor var assets/vendor public/assets public/bundles .php-cs-fixer.cache .twig-cs-fixer.cache diff --git a/assets/quiz.js b/assets/quiz.js new file mode 100644 index 0000000..3ed5286 --- /dev/null +++ b/assets/quiz.js @@ -0,0 +1,4 @@ +import 'bootstrap/dist/css/bootstrap.min.css' +import * as bootstrap from 'bootstrap' + +import './styles/quiz.scss' diff --git a/assets/styles/app.scss b/assets/styles/app.scss new file mode 100644 index 0000000..e69de29 diff --git a/config/packages/asset_mapper.yaml b/config/packages/asset_mapper.yaml new file mode 100644 index 0000000..1c08eb8 --- /dev/null +++ b/config/packages/asset_mapper.yaml @@ -0,0 +1,15 @@ +framework: + asset_mapper: + # The paths to make available to the asset mapper. + paths: + - assets/ + excluded_patterns: + - '*/assets/styles/_*.scss' + - '*/assets/styles/**/_*.scss' + missing_import_mode: strict + + +when@prod: + framework: + asset_mapper: + missing_import_mode: warn diff --git a/importmap.php b/importmap.php new file mode 100644 index 0000000..1f71f6d --- /dev/null +++ b/importmap.php @@ -0,0 +1,35 @@ + [ + 'path' => './assets/quiz.js', + 'entrypoint' => true, + ], + 'backoffice' => [ + 'path' => './assets/backoffice.js', + 'entrypoint' => true, + ], + 'bootstrap' => [ + 'version' => '5.3.6', + ], + '@popperjs/core' => [ + 'version' => '2.11.8', + ], + 'bootstrap/dist/css/bootstrap.min.css' => [ + 'version' => '5.3.6', + 'type' => 'css', + ], +]; diff --git a/migrations/Version20250521192752.php b/migrations/Version20250521192752.php new file mode 100644 index 0000000..3cc06b4 --- /dev/null +++ b/migrations/Version20250521192752.php @@ -0,0 +1,54 @@ +addSql(<<<'SQL' + ALTER TABLE elimination ADD quiz_id UUID NOT NULL + SQL); + $this->addSql(<<<'SQL' + ALTER TABLE elimination ADD CONSTRAINT FK_5947284F853CD175 FOREIGN KEY (quiz_id) REFERENCES quiz (id) NOT DEFERRABLE INITIALLY IMMEDIATE + SQL); + $this->addSql(<<<'SQL' + CREATE INDEX IDX_5947284F853CD175 ON elimination (quiz_id) + SQL); + $this->addSql(<<<'SQL' + ALTER TABLE quiz ALTER dropouts SET DEFAULT 1 + SQL); + $this->addSql(<<<'SQL' + ALTER TABLE quiz ALTER dropouts SET NOT NULL + SQL); + } + + public function down(Schema $schema): void + { + $this->addSql(<<<'SQL' + ALTER TABLE quiz ALTER dropouts DROP DEFAULT + SQL); + $this->addSql(<<<'SQL' + ALTER TABLE quiz ALTER dropouts DROP NOT NULL + SQL); + $this->addSql(<<<'SQL' + ALTER TABLE elimination DROP CONSTRAINT FK_5947284F853CD175 + SQL); + $this->addSql(<<<'SQL' + DROP INDEX IDX_5947284F853CD175 + SQL); + $this->addSql(<<<'SQL' + ALTER TABLE elimination DROP quiz_id + SQL); + } +} diff --git a/migrations/Version20250521194035.php b/migrations/Version20250521194035.php new file mode 100644 index 0000000..e11083d --- /dev/null +++ b/migrations/Version20250521194035.php @@ -0,0 +1,38 @@ +addSql(<<<'SQL' + ALTER TABLE elimination ADD created TIMESTAMP(0) WITHOUT TIME ZONE + SQL); + $this->addSql(<<<'SQL' + UPDATE elimination SET created = NOW() + SQL + ); + $this->addSql(<<<'SQL' + ALTER TABLE elimination ALTER created SET NOT NULL + SQL + ); + } + + public function down(Schema $schema): void + { + $this->addSql(<<<'SQL' + ALTER TABLE elimination DROP created + SQL); + } +} diff --git a/src/Controller/PrepareEliminationController.php b/src/Controller/PrepareEliminationController.php index 1286a70..5e4875c 100644 --- a/src/Controller/PrepareEliminationController.php +++ b/src/Controller/PrepareEliminationController.php @@ -8,7 +8,9 @@ use App\Entity\Elimination; use App\Entity\Quiz; use App\Entity\Season; use App\Factory\EliminationFactory; +use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; @@ -23,8 +25,15 @@ final class PrepareEliminationController extends AbstractController } #[Route('/backoffice/elimination/{elimination}', name: 'app_prepare_elimination_view')] - public function viewElimination(Elimination $elimination): Response + public function viewElimination(Elimination $elimination, Request $request, EntityManagerInterface $em): Response { + if ('POST' === $request->getMethod()) { + $elimination->updateFromInputBag($request->request); + $em->flush(); + + $this->addFlash('success', 'Elimination updated'); + } + return $this->render('backoffice/prepare_elimination/index.html.twig', [ 'controller_name' => 'PrepareEliminationController', 'elimination' => $elimination, diff --git a/src/Entity/Elimination.php b/src/Entity/Elimination.php index 34bdf81..1bd4ec0 100644 --- a/src/Entity/Elimination.php +++ b/src/Entity/Elimination.php @@ -10,6 +10,7 @@ use Doctrine\ORM\Mapping as ORM; use Safe\DateTimeImmutable; use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator; use Symfony\Bridge\Doctrine\Types\UuidType; +use Symfony\Component\HttpFoundation\InputBag; use Symfony\Component\Uid\Uuid; #[ORM\Entity(repositoryClass: EliminationRepository::class)] @@ -62,6 +63,19 @@ class Elimination return $this->quiz; } + /** @param InputBag $inputBag */ + public function updateFromInputBag(InputBag $inputBag): self + { + foreach ($this->data as $name => $screenColour) { + $newColour = $inputBag->get('colour-'.mb_strtolower($name)); + if (\is_string($newColour)) { + $this->data[$name] = $inputBag->get('colour-'.mb_strtolower($name)); + } + } + + return $this; + } + #[ORM\PrePersist] public function setCreatedAtValue(): void { diff --git a/templates/backoffice/prepare_elimination/index.html.twig b/templates/backoffice/prepare_elimination/index.html.twig index 16e47ff..d4b3ab1 100644 --- a/templates/backoffice/prepare_elimination/index.html.twig +++ b/templates/backoffice/prepare_elimination/index.html.twig @@ -17,7 +17,7 @@
-
+ {%~ for candidate, colour in elimination.data %}
@@ -30,7 +30,13 @@
{% endfor %} - +
+ + + {{ 'Back'|trans }} +
diff --git a/templates/backoffice/quiz.html.twig b/templates/backoffice/quiz.html.twig index 33b54fe..9bd1f54 100644 --- a/templates/backoffice/quiz.html.twig +++ b/templates/backoffice/quiz.html.twig @@ -62,7 +62,7 @@ diff --git a/templates/backoffice/quiz_add.html.twig b/templates/backoffice/quiz_add.html.twig index 064db96..e816e15 100644 --- a/templates/backoffice/quiz_add.html.twig +++ b/templates/backoffice/quiz_add.html.twig @@ -3,7 +3,7 @@ {% block body %}
-

{{ t('Add a quiz to %name%',{'%name%': season.name})|trans }}

+

{{ t('Add a quiz to %name%', {'%name%': season.name})|trans }}

{{ form_start(form) }} {{ form_row(form.name) }} {{ form_row(form.sheet) }} diff --git a/templates/flashes.html.twig b/templates/flashes.html.twig index 5bde08c..b033dd2 100644 --- a/templates/flashes.html.twig +++ b/templates/flashes.html.twig @@ -1,4 +1,4 @@ -{% set flashes=app.flashes() %} +{% set flashes = app.flashes() %} {% if flashes is not empty %}
{% for label, messages in flashes %} diff --git a/translations/messages+intl-icu.nl.yaml b/translations/messages+intl-icu.nl.yaml index 76bfc89..b1ca82f 100644 --- a/translations/messages+intl-icu.nl.yaml +++ b/translations/messages+intl-icu.nl.yaml @@ -5,6 +5,7 @@ Add: Toevoegen 'Add a quiz to %name%': 'Voeg een test toe aan %name%' 'All Seasons': 'Alle seizoenen' 'Already have an account? Log in': 'Heb je al een account? Log in' +Back: Terug Candidate: Kandidaat 'Candidate not found': 'Kandidaat niet gevonden' Candidates: Kandidaten @@ -44,6 +45,7 @@ Register: Registreren 'Remember me': 'Onthoud mij' 'Repeat Password': 'Herhaal wachtwoord' Save: Opslaan +'Save and start elimination': 'Opslaan en start eliminatie' Score: Score Season: Seizoen 'Season Code': Seizoencode