feat: special agreements for disposition

This commit is contained in:
Björn Fromme
2024-04-04 13:06:35 +02:00
parent 4d1ea7aad7
commit 26239488ba
19 changed files with 310 additions and 31 deletions
@@ -0,0 +1,12 @@
import { Controller } from '@hotwired/stimulus'
export default class extends Controller {
connect() {
this.element.style.height = 'auto'
this.resize()
}
resize() {
this.element.style.height = `${this.element.scrollHeight}px`
}
}
+31
View File
@@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240404091244 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE disposition ADD special_agreements LONGTEXT DEFAULT NULL');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE disposition DROP special_agreements');
}
}
@@ -5,6 +5,7 @@ namespace App\Controller\Admin\Application;
use App\Entity\Application;
use App\Entity\Disposition;
use App\Event\DispositionCreatedEvent;
use App\Form\SpecialAgreementsType;
use App\Htmx\HxRedirectResponse;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
@@ -29,9 +30,11 @@ class DisposeController extends AbstractController
#[IsGranted('DISPOSE', subject: 'application')]
public function index(Application $application, Request $request): Response
{
if (true === $request->isMethod('POST')) {
$disposition = new Disposition($application);
$form = $this->createForm(SpecialAgreementsType::class, $disposition, ['hx_post' => $request->getUri()]);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->entityManager->persist($disposition);
$this->entityManager->remove($application);
$this->entityManager->flush();
@@ -53,6 +56,7 @@ class DisposeController extends AbstractController
return $this->render('admin/application/modal_dispose.html.twig', [
'application' => $application,
'form' => $form->createView(),
]);
}
}
@@ -0,0 +1,49 @@
<?php
namespace App\Controller\Administrative\Disposition;
use App\Entity\Disposition;
use App\Form\SpecialAgreementsType;
use App\Htmx\HxRedirectResponse;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
class SpecialAgreementsController extends AbstractController
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly LoggerInterface $logger
) {
}
#[Route('/administrative/disposition/special-agreements/{uuid}', name: 'app_administrative_disposition_special_agreements')]
#[IsGranted('ROLE_ADMINISTRATIVE')]
public function index(Disposition $disposition, Request $request): Response
{
$form = $this->createForm(SpecialAgreementsType::class, $disposition, ['hx_post' => $request->getUri()]);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->entityManager->flush();
$this->logger->info('Edit special agreements', [
'disposition' => $disposition->getUuid(),
'special_agreements' => $disposition->getSpecialAgreements(),
]);
return new HxRedirectResponse($this->generateUrl('app_administrative_assignment_detail', [
'uuid' => $disposition->getAssignment()->getUuid(),
]));
}
return $this->render('administrative/disposition/modal_special_agreements.html.twig', [
'disposition' => $disposition,
'form' => $form->createView(),
]);
}
}
@@ -2,6 +2,7 @@
namespace App\Controller\Administrative\Document;
use App\Controller\Traits\ReturnUrlTrait;
use App\Entity\Upload;
use App\Event\DocumentRejectedEvent;
use App\Form\DocumentCheckType;
@@ -20,6 +21,8 @@ use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
class CheckController extends AbstractController
{
use ReturnUrlTrait;
public function __construct(
private readonly EntityManagerInterface $entityManager,
#[Target('disposition')]
@@ -42,14 +45,15 @@ class CheckController extends AbstractController
if ($form->isSubmitted() && $form->isValid()) {
switch ($formData->getStatus()) {
case Upload::STATUS_CHECKED:
$this->confirmDocument($document, 'confirm_contract', Upload::STATUS_CHECKED);
$this->confirmDocument($document, 'confirm_contract', Upload::STATUS_CHECKED, $formData);
break;
case Upload::STATUS_PAID:
$this->confirmDocument($document, 'confirm_invoice', Upload::STATUS_PAID);
$this->confirmDocument($document, 'confirm_invoice', Upload::STATUS_PAID, $formData);
break;
case Upload::STATUS_REJECTED:
$this->rejectDocument($document, $formData->getComment());
$this->eventDispatcher->dispatch(new DocumentRejectedEvent($formData), DocumentRejectedEvent::NAME);
break;
default:
$document
->setStatus($formData->getStatus())
@@ -65,7 +69,9 @@ class CheckController extends AbstractController
]);
}
return new HxRedirectResponse($this->generateUrl('app_administrative_document_index'));
$returnUrl = $this->getReturnUrl($request, 'app_administrative_document_index');
return new HxRedirectResponse($returnUrl);
}
return $this->render('administrative/document/modal_check.html.twig', [
@@ -94,7 +100,7 @@ class CheckController extends AbstractController
$this->entityManager->flush();
}
private function confirmDocument(Upload $document, string $transition, string $status): void
private function confirmDocument(Upload $document, string $transition, string $status, DocumentCheckDto $formData): void
{
$document->setStatus($status);
$this->addFlash('success', 'Das Dokument wurde bestätigt');
@@ -113,6 +119,10 @@ class CheckController extends AbstractController
}
}
if (Upload::TYPE_INVOICE === $document->getType()) {
$document->getDisposition()->setSpecialAgreements($formData->getSpecialAgreements());
}
$this->entityManager->flush();
}
}
+15
View File
@@ -50,6 +50,9 @@ class Disposition implements BlameableEntityInterface, TimestampableEntityInterf
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $remarks;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $specialAgreements;
#[ORM\OneToMany(mappedBy: 'disposition', targetEntity: Upload::class, cascade: ['persist', 'remove'])]
private Collection $documents;
@@ -137,6 +140,18 @@ class Disposition implements BlameableEntityInterface, TimestampableEntityInterf
return $this;
}
public function getSpecialAgreements(): ?string
{
return $this->specialAgreements;
}
public function setSpecialAgreements(?string $specialAgreements): static
{
$this->specialAgreements = $specialAgreements;
return $this;
}
/**
* @return Collection<int, Upload>
*/
+2 -1
View File
@@ -132,7 +132,8 @@ class AssignmentType extends AbstractType
'label' => 'Anmerkungen',
'required' => false,
'attr' => [
'rows' => 3,
'data-controller' => 'textarea-autosize',
'data-action' => 'textarea-autosize#resize'
],
])
->add('pickup', ChoiceType::class, [
+14
View File
@@ -8,6 +8,8 @@ use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;
class DocumentCheckType extends AbstractType
@@ -26,6 +28,18 @@ class DocumentCheckType extends AbstractType
'rows' => 3,
],
])
->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
/** @var DocumentCheckDto $data */
$data = $event->getData();
$upload = $data->getUpload();
if (Upload::TYPE_INVOICE === $upload->getType()) {
$event->getForm()->add('specialAgreements', TextareaType::class, [
'label' => 'zusätzliche Absprache',
'required' => false,
]);
}
})
;
}
@@ -0,0 +1,39 @@
<?php
namespace App\Form\Extension;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;
class ModalSubmitExtension extends AbstractTypeExtension
{
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'hx_post' => null,
'hx_target' => '#htmx-modal',
'hx_swap' => 'outerHTML',
]);
}
public function buildView(FormView $view, FormInterface $form, array $options): void
{
if (null !== $options['hx_post']) {
$attr = [
'hx-post' => $options['hx_post'],
'hx-target' => $options['hx_target'],
'hx-swap' => $options['hx_swap'],
'hx-indicator' => '#htmx-modal-indicator',
];
$view->vars['attr'] = array_merge($view->vars['attr'], $attr);
}
}
public static function getExtendedTypes(): iterable
{
return [FormType::class];
}
}
-1
View File
@@ -4,7 +4,6 @@ namespace App\Form;
use App\Entity\Faq;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
+31
View File
@@ -0,0 +1,31 @@
<?php
namespace App\Form;
use App\Entity\Disposition;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class SpecialAgreementsType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->add('specialAgreements', TextareaType::class, [
'label' => 'zusätzliche Absprache',
'required' => false,
'attr' => [
'data-controller' => 'textarea-autosize',
'data-action' => 'textarea-autosize#resize'
]
]);
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Disposition::class,
]);
}
}
+13
View File
@@ -0,0 +1,13 @@
<?php
namespace App\Htmx;
use Symfony\Component\HttpFoundation\Response;
class HxTriggerResponse extends Response
{
public function __construct(string $content, string $trigger)
{
return parent::__construct($content, Response::HTTP_OK, ['HX-Trigger' => $trigger]);
}
}
+14
View File
@@ -9,11 +9,13 @@ class DocumentCheckDto
private Upload $upload;
private ?string $status = null;
private ?string $comment;
private ?string $specialAgreements;
public function __construct(Upload $upload)
{
$this->upload = $upload;
$this->comment = $upload->getComment();
$this->specialAgreements = $upload->getDisposition()?->getSpecialAgreements();
}
public function getUpload(): Upload
@@ -44,4 +46,16 @@ class DocumentCheckDto
return $this;
}
public function getSpecialAgreements(): ?string
{
return $this->specialAgreements;
}
public function setSpecialAgreements(?string $specialAgreements): static
{
$this->specialAgreements = $specialAgreements;
return $this;
}
}
@@ -1,7 +1,21 @@
{% extends 'htmx_confirmation_modal.html.twig' %}
{% extends 'htmx_modal.html.twig' %}
{% block title %}Einteilung{% endblock %}
{% block content %}
<div>
Möchtest du {{ application.teamer }} wirklich einteilen?
<div class="pb-4">
Möchtest du <strong>{{ application.teamer }}</strong> wirklich für den Einsatz <strong>{{ application.assignment.destination}}</strong> einteilen?
</div>
{{ form_start(form) }}
{{ form_row(form.specialAgreements) }}
<div class="mt-6 flex items-center justify-between">
<button type="submit" class="btn">
Ja
</button>
<button type="button" class="btn btn--secondary" {{ stimulus_action('modal', 'close') }}>
Abbrechen
</button>
</div>
{{ form_rest(form) }}
{{ form_end(form) }}
{% endblock %}
+6 -7
View File
@@ -48,17 +48,16 @@
<ul class="divide-y divide-gray-200">
{% for document in documents %}
<li class="py-2 first:pt-0 last:pb-0">
{% if document.disposition %}
{% set url = path('app_administrative_assignment_detail', { 'uuid': document.disposition.assignment.uuid, 'r': return_url() }) %}
{% else %}
{% set url = path('app_administrative_teamer_profile', { 'uuid': document.owner.teamer.uuid, 'r': return_url() }) %}
{% endif %}
<a href="{{ url }}" class="flex items-center space-x-1 truncate">
<button type="button"
class="flex items-center space-x-1 truncate"
hx-get="{{ path('app_administrative_document_check', { 'uuid': document.uuid, 'r': return_url() }) }}"
hx-target="body"
hx-swap="beforeend">
{{ icon('download', 'w-4 h-4 shrink-0') }}
<span>{{ document.owner.teamer.fullName(true) }}</span>
{% include '_partials/_dot.html.twig' %}
<span>{{ document.originalFilename }}</span>
</a>
</button>
</li>
{% else %}
<li class="py-2 first:pt-0 last:pb-0">
@@ -22,14 +22,14 @@
<th class="w-1/4">
Name
</th>
<th class="w-1/4">
Zustieg
<th class="w-1/5">
Status
</th>
<th>
Wünsche
</th>
<th>
Status
Zustieg
</th>
<th></th>
</tr>
@@ -49,15 +49,15 @@
</button>
<twig:RatingStars rating="{{ application.teamer.averageRating }}" />
</td>
<td>
{{ ('label.application.status.' ~ application.status)|trans }}
</td>
<td>
{{ application.pickup|bpn_pickup_label|default('-') }}
</td>
<td>
{{ application.requests|nl2br|default('-') }}
</td>
<td>
{{ ('label.application.status.' ~ application.status)|trans }}
</td>
<td>
<div class="flex items-center justify-end space-x-2">
{% if is_granted('DISPOSE', application) %}
@@ -95,7 +95,7 @@
</tr>
{% else %}
<tr>
<td colspan="4">
<td colspan="5">
Es liegen keine Bewerbungen vor...
</td>
</tr>
@@ -116,11 +116,14 @@
<th class="w-1/4">
Name
</th>
<th class="w-1/4">
<th class="w-1/5">
Status
</th>
<th>
Anmerkungen
</th>
<th>
Status
Absprachen
</th>
<th></th>
</tr>
@@ -140,11 +143,20 @@
</button>
<twig:RatingStars rating="{{ disposition.teamer.averageRating }}" />
</td>
<td>
{{ ('label.disposition.status.' ~ disposition.status)|trans }}
</td>
<td>
{{ disposition.remarks|nl2br|default('-') }}
</td>
<td>
{{ ('label.disposition.status.' ~ disposition.status)|trans }}
<button type="button"
title="zusätzliche Apsprachen {{ disposition.teamer }}"
hx-get="{{ path('app_administrative_disposition_special_agreements', { 'uuid': disposition.uuid }) }}"
hx-target="body"
hx-swap="beforeend">
{{ icon('edit') }}
</button>
</td>
<td>
<div class="flex items-center justify-end space-x-2">
@@ -163,7 +175,7 @@
</tr>
{% else %}
<tr>
<td colspan="4">
<td colspan="5">
Es gibt noch keine Einteilungen...
</td>
</tr>
@@ -0,0 +1,18 @@
{% extends 'htmx_modal.html.twig' %}
{% block title %}Zusätzliche Abspsprachen{% endblock %}
{% block content %}
{{ form_start(form) }}
<h2 class="font-bold text-lg pb-4">
Teamer {{ disposition.teamer }}
</h2>
<div class="flex flex-col space-y-4 pb-4">
{{ form_row(form.specialAgreements) }}
</div>
<button type="submit" class="btn">
Aktualisieren
</button>
{{ form_rest(form) }}
{{ form_end(form) }}
{% endblock %}
@@ -9,6 +9,9 @@
</h2>
<div class="flex flex-col space-y-4 pb-4">
{{ form_row(form.status) }}
{% if form.specialAgreements is defined %}
{{ form_row(form.specialAgreements) }}
{% endif %}
{{ form_row(form.comment) }}
</div>
<button type="submit" class="btn">
+3 -2
View File
@@ -1,4 +1,4 @@
<div id="htmx-modal" class="fixed inset-0 w-full h-full z-50" {{ stimulus_controller('modal') }}>
<div id="htmx-modal" class="fixed inset-0 w-full h-full z-50" {{ stimulus_controller('modal') }} {{ stimulus_action('modal', 'close', 'modal-close@window') }}>
<div class="absolute inset-0 w-full h-full bg-black/80" {{ stimulus_action('modal', 'close', 'click') }}></div>
<div class="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 px-4 w-full max-w-2xl">
<div class="relative bg-white p-8 rounded-md">
@@ -13,7 +13,8 @@
</button>
</div>
{% block content %}{% endblock %}
<div class="htmx-indicator absolute top-0 left-0 inset-0 bg-white/90 flex items-center justify-center">
<div class="htmx-indicator absolute top-0 left-0 inset-0 bg-white/90 flex items-center justify-center"
id="htmx-modal-indicator">
{% include '_partials/_spinner.html.twig' with { 'class': 'w-8 h-8'} %}
</div>
</div>