feat: treat all uploads of type 'document' as global

This commit is contained in:
Björn Fromme
2024-01-31 18:05:56 +01:00
parent 5ad7bfe769
commit 4be039e482
12 changed files with 15 additions and 130 deletions
@@ -39,10 +39,6 @@ class EditController extends AbstractController
'placeholder' => $upload->getOriginalFilename(), 'placeholder' => $upload->getOriginalFilename(),
], ],
]) ])
->add('global', CheckboxType::class, [
'label' => 'globales Dokument',
'required' => false,
])
->getForm() ->getForm()
; ;
$form->handleRequest($request); $form->handleRequest($request);
@@ -61,7 +57,7 @@ class EditController extends AbstractController
$response->setCloseAndRedirect($this->generateUrl('app_admin_system_document_index')); $response->setCloseAndRedirect($this->generateUrl('app_admin_system_document_index'));
} else { } else {
$response->setContent($this->renderView('admin/system/document/edit.html.twig', [ $response->setContent($this->renderView('admin/system/document/edit.html.twig', [
'form' => $form, 'form' => $form->createView(),
])); ]));
} }
@@ -22,7 +22,7 @@ class IndexController extends AbstractController
#[IsGranted('ROLE_ADMINISTRATIVE')] #[IsGranted('ROLE_ADMINISTRATIVE')]
public function index(Request $request): Response public function index(Request $request): Response
{ {
$query = $this->uploadRepository->getDocumentListQuery(); $query = $this->uploadRepository->getGlobalListQuery();
$pagination = $this->paginator->paginate( $pagination = $this->paginator->paginate(
$query, $query,
@@ -60,7 +60,7 @@ class ReplaceController extends AbstractController
$response->setCloseAndRedirect($this->generateUrl('app_admin_system_document_index')); $response->setCloseAndRedirect($this->generateUrl('app_admin_system_document_index'));
} else { } else {
$response->setContent($this->renderView('admin/system/document/replace.html.twig', [ $response->setContent($this->renderView('admin/system/document/replace.html.twig', [
'form' => $form, 'form' => $form->createView(),
])); ]));
} }
@@ -9,7 +9,6 @@ use App\Service\Upload\UploadHandler;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Routing\Attribute\Route;
@@ -33,10 +32,6 @@ class UploadController extends AbstractController
$form = $this $form = $this
->createFormBuilder(null, ['action' => $formAction, 'ajax_submit' => true]) ->createFormBuilder(null, ['action' => $formAction, 'ajax_submit' => true])
->add('global', CheckboxType::class, [
'label' => 'globale(s) Dokument(e)',
'required' => false,
])
->getForm() ->getForm()
; ;
$form->handleRequest($request); $form->handleRequest($request);
@@ -49,7 +44,6 @@ class UploadController extends AbstractController
$user = $this->getUser(); $user = $this->getUser();
foreach ($uploadSession->getUploads() as $upload) { foreach ($uploadSession->getUploads() as $upload) {
$document = Upload::fromUploadDto($upload, $user, Upload::TYPE_DOCUMENT); $document = Upload::fromUploadDto($upload, $user, Upload::TYPE_DOCUMENT);
$document->setGlobal($form->get('global')->getData());
$uploadedDocuments[] = $document; $uploadedDocuments[] = $document;
$this->entityManager->persist($document); $this->entityManager->persist($document);
} }
@@ -72,7 +66,7 @@ class UploadController extends AbstractController
$response->setCloseAndRedirect($this->generateUrl('app_admin_system_document_index')); $response->setCloseAndRedirect($this->generateUrl('app_admin_system_document_index'));
} else { } else {
$response->setContent($this->renderView('admin/system/document/upload.html.twig', [ $response->setContent($this->renderView('admin/system/document/upload.html.twig', [
'form' => $form, 'form' => $form->createView(),
])); ]));
} }
-28
View File
@@ -81,9 +81,6 @@ class Assignment implements BlameableEntityInterface, TimestampableEntityInterfa
#[ORM\ManyToMany(targetEntity: Teamer::class, mappedBy: 'bookmarks')] #[ORM\ManyToMany(targetEntity: Teamer::class, mappedBy: 'bookmarks')]
private Collection $teamers; private Collection $teamers;
#[ORM\ManyToMany(targetEntity: Upload::class)]
private Collection $documents;
#[ORM\ManyToOne] #[ORM\ManyToOne]
private ?User $owner = null; private ?User $owner = null;
@@ -99,7 +96,6 @@ class Assignment implements BlameableEntityInterface, TimestampableEntityInterfa
$this->dispositions = new ArrayCollection(); $this->dispositions = new ArrayCollection();
$this->teamers = new ArrayCollection(); $this->teamers = new ArrayCollection();
$this->benefits = "Anreise im E&P Reisebus\nUnterkunft\nVerpflegung\nSkipass\n"; $this->benefits = "Anreise im E&P Reisebus\nUnterkunft\nVerpflegung\nSkipass\n";
$this->documents = new ArrayCollection();
} }
public static function duplicate(Assignment $assignment): static public static function duplicate(Assignment $assignment): static
@@ -432,30 +428,6 @@ class Assignment implements BlameableEntityInterface, TimestampableEntityInterfa
return $this; return $this;
} }
/**
* @return Collection<int, Upload>
*/
public function getDocuments(): Collection
{
return $this->documents;
}
public function addDocument(Upload $document): static
{
if (!$this->documents->contains($document)) {
$this->documents->add($document);
}
return $this;
}
public function removeDocument(Upload $document): static
{
$this->documents->removeElement($document);
return $this;
}
public function getOwner(): ?User public function getOwner(): ?User
{ {
return $this->owner; return $this->owner;
-15
View File
@@ -63,9 +63,6 @@ class Upload implements BlameableEntityInterface, TimestampableEntityInterface
#[ORM\ManyToOne(inversedBy: 'documents')] #[ORM\ManyToOne(inversedBy: 'documents')]
private ?Disposition $disposition = null; private ?Disposition $disposition = null;
#[ORM\Column]
private bool $global = false;
#[ORM\Column(type: Types::TEXT, nullable: true)] #[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $comment = null; private ?string $comment = null;
@@ -222,18 +219,6 @@ class Upload implements BlameableEntityInterface, TimestampableEntityInterface
return $this; return $this;
} }
public function isGlobal(): bool
{
return $this->global;
}
public function setGlobal(bool $global): static
{
$this->global = $global;
return $this;
}
public function getComment(): ?string public function getComment(): ?string
{ {
return $this->comment; return $this->comment;
-23
View File
@@ -108,29 +108,6 @@ class AssignmentType extends AbstractType
; ;
}, },
]) ])
->add('documents', CollectionType::class, [
'label' => 'Dokumente',
'entry_type' => EntityType::class,
'entry_options' => [
'class' => Upload::class,
'choice_label' => function (Upload $document) {
return $document->getDisplayName() ?? $document->getOriginalFilename();
},
'placeholder' => 'Dokument...',
'query_builder' => function (EntityRepository $repository) {
return $repository
->createQueryBuilder('upload')
->where('upload.type = :type')
->setParameter('type', Upload::TYPE_DOCUMENT)
->orderBy('upload.displayName')
->addOrderBy('upload.originalFilename')
;
},
],
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
])
->add('remarks', TextareaType::class, [ ->add('remarks', TextareaType::class, [
'label' => 'Anmerkungen', 'label' => 'Anmerkungen',
'required' => false, 'required' => false,
+10 -14
View File
@@ -25,7 +25,7 @@ class UploadRepository extends ServiceEntityRepository
parent::__construct($registry, Upload::class); parent::__construct($registry, Upload::class);
} }
public function getDocumentListQuery(): Query public function getGlobalListQuery(): Query
{ {
$qb = $this->createQueryBuilder('upload'); $qb = $this->createQueryBuilder('upload');
@@ -36,6 +36,15 @@ class UploadRepository extends ServiceEntityRepository
; ;
} }
public function getGlobal(): array
{
return $this
->getGlobalListQuery()
->getResult()
;
}
public function getAutocompletionData(string $search): array public function getAutocompletionData(string $search): array
{ {
$qb = $this->createQueryBuilder('upload'); $qb = $this->createQueryBuilder('upload');
@@ -123,17 +132,4 @@ class UploadRepository extends ServiceEntityRepository
->getSingleScalarResult() ->getSingleScalarResult()
; ;
} }
public function getGlobal(): array
{
$qb = $this->createQueryBuilder('upload');
return $qb
->where($qb->expr()->eq('upload.global', ':global'))
->setParameter('global', true)
->orderBy('upload.createdAt', 'DESC')
->getQuery()
->getResult()
;
}
} }
@@ -25,10 +25,6 @@
{{ form_widget(form.showAvailableDispositions) }} {{ form_widget(form.showAvailableDispositions) }}
</div> </div>
</div> </div>
{# <div class="grid lg:grid-cols-2 gap-x-8 gap-y-4">#}
{# {{ form_row(form.dateFrom) }}#}
{# {{ form_row(form.dateTo) }}#}
{# </div>#}
<div class="grid lg:grid-cols-2 gap-x-8 gap-y-4"> <div class="grid lg:grid-cols-2 gap-x-8 gap-y-4">
{{ form_row(form.jobProfile) }} {{ form_row(form.jobProfile) }}
{{ form_row(form.contact) }} {{ form_row(form.contact) }}
@@ -44,25 +40,7 @@
<div class="grid lg:grid-cols-2 gap-x-8 gap-y-4"> <div class="grid lg:grid-cols-2 gap-x-8 gap-y-4">
{{ form_row(form.benefits) }} {{ form_row(form.benefits) }}
{{ form_row(form.fees) }} {{ form_row(form.fees) }}
</div>
<div class="grid lg:grid-cols-2 gap-x-8 gap-y-4">
{{ form_row(form.remarks) }} {{ form_row(form.remarks) }}
<div {{ stimulus_controller('form-collection', { 'prototype': _self.collectionRow(form.documents.vars.prototype)|json_encode }) }}>
<h4 class="font-bold pb-2">
Dokumente
</h4>
<div {{ stimulus_target('form-collection', 'fields')}} class="flex flex-col space-y-4 mb-4">
{% do form.documents.setRendered %}
{%- for document in form.documents -%}{{- _self.collectionRow(document) -}}{%- endfor -%}
</div>
<div class="flex justify-end">
<button type="button"
{{ stimulus_action('form-collection', 'addItem') }}
title="Dokument hinzufügen">
{{ icon('plus', 'w-4 h-4 pointer-events-none') }}
</button>
</div>
</div>
</div> </div>
</div> </div>
<div class="flex items-center space-x-2"> <div class="flex items-center space-x-2">
@@ -2,9 +2,6 @@
<div class="pb-4"> <div class="pb-4">
{{ form_row(form.displayName) }} {{ form_row(form.displayName) }}
</div> </div>
<div class="pb-4">
{{ form_row(form.global) }}
</div>
<button type="submit" class="btn"> <button type="submit" class="btn">
aktualisieren aktualisieren
</button> </button>
@@ -17,9 +17,6 @@
<th> <th>
Dateigröße Dateigröße
</th> </th>
<th>
global
</th>
<th> <th>
Upload am Upload am
</th> </th>
@@ -38,10 +35,6 @@
<td> <td>
{{ document.size|file_size }} {{ document.size|file_size }}
</td> </td>
<td>
{% set icon = document.global ? 'check' : 'minus' %}
{{ icon(icon, 'w-4 h-4') }}
</td>
<td> <td>
{{ document.createdAt|date('d.m.Y') }} {{ document.createdAt|date('d.m.Y') }}
</td> </td>
@@ -85,7 +78,7 @@
</tr> </tr>
{% else %} {% else %}
<tr> <tr>
<td colspan="7"> <td colspan="5">
Keine Daten... Keine Daten...
</td> </td>
</tr> </tr>
@@ -6,9 +6,6 @@
'accepted_files': 'application/pdf', 'accepted_files': 'application/pdf',
} %} } %}
</div> </div>
<div class="pb-4">
{{ form_row(form.global) }}
</div>
<button type="submit" class="btn"> <button type="submit" class="btn">
Uploads speichern Uploads speichern
</button> </button>