Feat: Add funtion to rename uploaded documents
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Admin\Document;
|
||||
|
||||
use App\Entity\Upload;
|
||||
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\TextType;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class RenameController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly LoggerInterface $logger
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/admin/document/rename/{uuid}', name: 'app_admin_document_rename')]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(Upload $upload, Request $request): JsonResponse
|
||||
{
|
||||
$response = new AjaxModalResponseDto();
|
||||
$formAction = $this->generateUrl('app_admin_document_rename', ['uuid' => $upload->getUuid()]);
|
||||
|
||||
$form = $this
|
||||
->createFormBuilder($upload, ['action' => $formAction, 'ajax_submit' => true])
|
||||
->add('displayName', TextType::class, [
|
||||
'label' => 'angezeigter Name',
|
||||
])
|
||||
->getForm()
|
||||
;
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->entityManager->flush();
|
||||
$this->addFlash('success', 'Das Dokument wurden umbenannt');
|
||||
$this->logger->info('Rename document');
|
||||
|
||||
$response->setCloseAndRedirect($this->generateUrl('app_admin_document_index'));
|
||||
} else {
|
||||
$response->setContent($this->renderView('admin/document/rename.html.twig', [
|
||||
'form' => $form,
|
||||
]));
|
||||
}
|
||||
|
||||
return $this->json($response);
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@
|
||||
{% for document in pagination %}
|
||||
<tr>
|
||||
<td>
|
||||
{{ document.originalFilename }}
|
||||
{{ document.displayName ? document.displayName : document.originalFilename }}
|
||||
</td>
|
||||
<td>
|
||||
{{ document.size|file_size }}
|
||||
@@ -61,6 +61,14 @@
|
||||
}) }}>
|
||||
{{ icon('refresh') }}
|
||||
</button>
|
||||
<button type="button"
|
||||
{{ stimulus_controller('modal-button', [], [], {'ajax-modal': '#ajax-modal'}) }}
|
||||
{{ stimulus_action('modal-button', 'ajax', null, {
|
||||
'title': 'Dokument umbenennen',
|
||||
'url': path('app_admin_document_rename', { 'uuid': document.uuid })
|
||||
}) }}>
|
||||
{{ icon('edit') }}
|
||||
</button>
|
||||
<a href="{{ path('app_common_download', { 'uuid': document.uuid }) }}"
|
||||
title="Download">
|
||||
{{ icon('download') }}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{{ form_start(form) }}
|
||||
<div class="pb-4">
|
||||
{{ form_row(form.displayName) }}
|
||||
</div>
|
||||
<button type="submit" class="btn">
|
||||
aktualisieren
|
||||
</button>
|
||||
{{ form_rest(form) }}
|
||||
{{ form_end(form) }}
|
||||
Reference in New Issue
Block a user