feat: mark documents global
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<?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 Version20240128125138 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 upload ADD global TINYINT(1) NOT NULL');
|
||||
}
|
||||
|
||||
public function postUp(Schema $schema): void
|
||||
{
|
||||
$this->connection->executeQuery('UPDATE upload SET global=0');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE upload DROP global');
|
||||
}
|
||||
}
|
||||
+12
-4
@@ -7,13 +7,14 @@ use App\Model\AjaxModalResponseDto;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class RenameController extends AbstractController
|
||||
class EditController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
@@ -21,12 +22,12 @@ class RenameController extends AbstractController
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/admin/system/document/rename/{uuid}', name: 'app_admin_system_document_rename')]
|
||||
#[Route('/admin/system/document/edit/{uuid}', name: 'app_admin_system_document_edit')]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(Upload $upload, Request $request): JsonResponse
|
||||
{
|
||||
$response = new AjaxModalResponseDto();
|
||||
$formAction = $this->generateUrl('app_admin_system_document_rename', ['uuid' => $upload->getUuid()]);
|
||||
$formAction = $this->generateUrl('app_admin_system_document_edit', ['uuid' => $upload->getUuid()]);
|
||||
|
||||
$nameBefore = $upload->getDisplayName();
|
||||
|
||||
@@ -34,6 +35,13 @@ class RenameController extends AbstractController
|
||||
->createFormBuilder($upload, ['action' => $formAction, 'ajax_submit' => true])
|
||||
->add('displayName', TextType::class, [
|
||||
'label' => 'angezeigter Name',
|
||||
'attr' => [
|
||||
'placeholder' => $upload->getOriginalFilename(),
|
||||
],
|
||||
])
|
||||
->add('global', CheckboxType::class, [
|
||||
'label' => 'globales Dokument',
|
||||
'required' => false,
|
||||
])
|
||||
->getForm()
|
||||
;
|
||||
@@ -52,7 +60,7 @@ class RenameController extends AbstractController
|
||||
|
||||
$response->setCloseAndRedirect($this->generateUrl('app_admin_system_document_index'));
|
||||
} else {
|
||||
$response->setContent($this->renderView('admin/system/document/rename.html.twig', [
|
||||
$response->setContent($this->renderView('admin/system/document/edit.html.twig', [
|
||||
'form' => $form,
|
||||
]));
|
||||
}
|
||||
@@ -9,6 +9,7 @@ use App\Service\Upload\UploadHandler;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
@@ -27,6 +28,19 @@ class UploadController extends AbstractController
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$response = new AjaxModalResponseDto();
|
||||
$formAction = $this->generateUrl('app_admin_system_document_upload');
|
||||
|
||||
$form = $this
|
||||
->createFormBuilder(null, ['action' => $formAction, 'ajax_submit' => true])
|
||||
->add('global', CheckboxType::class, [
|
||||
'label' => 'globale(s) Dokument(e)',
|
||||
'required' => false,
|
||||
])
|
||||
->getForm()
|
||||
;
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Handle upload independently from form submission to avoid issues with failing validation
|
||||
$uploadSession = $this->uploadHandler->getUploadSession();
|
||||
$uploadedDocuments = [];
|
||||
@@ -35,6 +49,7 @@ class UploadController extends AbstractController
|
||||
$user = $this->getUser();
|
||||
foreach ($uploadSession->getUploads() as $upload) {
|
||||
$document = Upload::fromUploadDto($upload, $user, Upload::TYPE_DOCUMENT);
|
||||
$document->setGlobal($form->get('global')->getData());
|
||||
$uploadedDocuments[] = $document;
|
||||
$this->entityManager->persist($document);
|
||||
}
|
||||
@@ -43,15 +58,6 @@ class UploadController extends AbstractController
|
||||
$this->uploadHandler->destroyUploadSession();
|
||||
}
|
||||
|
||||
$response = new AjaxModalResponseDto();
|
||||
$formAction = $this->generateUrl('app_admin_system_document_upload');
|
||||
|
||||
$form = $this
|
||||
->createFormBuilder(null, ['action' => $formAction, 'ajax_submit' => true])
|
||||
->getForm()
|
||||
;
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->addFlash('success', 'Das/die Dokument/e wurden hochgeladen');
|
||||
$loggerContext = [];
|
||||
|
||||
@@ -63,6 +63,9 @@ class Upload implements BlameableEntityInterface, TimestampableEntityInterface
|
||||
#[ORM\ManyToOne(inversedBy: 'documents')]
|
||||
private ?Disposition $disposition = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private bool $global = false;
|
||||
|
||||
#[ORM\Column(type: Types::TEXT, nullable: true)]
|
||||
private ?string $comment = null;
|
||||
|
||||
@@ -219,6 +222,18 @@ class Upload implements BlameableEntityInterface, TimestampableEntityInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isGlobal(): bool
|
||||
{
|
||||
return $this->global;
|
||||
}
|
||||
|
||||
public function setGlobal(bool $global): static
|
||||
{
|
||||
$this->global = $global;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getComment(): ?string
|
||||
{
|
||||
return $this->comment;
|
||||
|
||||
@@ -6,7 +6,6 @@ use App\Entity\Upload;
|
||||
use App\Repository\Traits\QueryHelperTrait;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\ORM\Query\Expr\Join;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
@@ -124,4 +123,17 @@ class UploadRepository extends ServiceEntityRepository
|
||||
->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()
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
+3
@@ -2,6 +2,9 @@
|
||||
<div class="pb-4">
|
||||
{{ form_row(form.displayName) }}
|
||||
</div>
|
||||
<div class="pb-4">
|
||||
{{ form_row(form.global) }}
|
||||
</div>
|
||||
<button type="submit" class="btn">
|
||||
aktualisieren
|
||||
</button>
|
||||
@@ -17,6 +17,9 @@
|
||||
<th>
|
||||
Dateigröße
|
||||
</th>
|
||||
<th>
|
||||
global
|
||||
</th>
|
||||
<th>
|
||||
Upload am
|
||||
</th>
|
||||
@@ -35,6 +38,10 @@
|
||||
<td>
|
||||
{{ document.size|file_size }}
|
||||
</td>
|
||||
<td>
|
||||
{% set icon = document.global ? 'check' : 'minus' %}
|
||||
{{ icon(icon, 'w-4 h-4') }}
|
||||
</td>
|
||||
<td>
|
||||
{{ document.createdAt|date('d.m.Y') }}
|
||||
</td>
|
||||
@@ -65,7 +72,7 @@
|
||||
{{ stimulus_controller('modal-button', [], [], {'ajax-modal': '#ajax-modal'}) }}
|
||||
{{ stimulus_action('modal-button', 'ajax', null, {
|
||||
'title': 'Dokument umbenennen',
|
||||
'url': path('app_admin_system_document_rename', { 'uuid': document.uuid })
|
||||
'url': path('app_admin_system_document_edit', { 'uuid': document.uuid })
|
||||
}) }}>
|
||||
{{ icon('edit') }}
|
||||
</button>
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
'accepted_files': 'application/pdf',
|
||||
} %}
|
||||
</div>
|
||||
<div class="pb-4">
|
||||
{{ form_row(form.global) }}
|
||||
</div>
|
||||
<button type="submit" class="btn">
|
||||
Uploads speichern
|
||||
</button>
|
||||
|
||||
Reference in New Issue
Block a user