From eefb60007f7750696a36d86eec34450602b1ae9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Thu, 12 Oct 2023 14:43:00 +0200 Subject: [PATCH] Feat: Add funtion to rename uploaded documents --- .../Admin/Document/RenameController.php | 54 +++++++++++++++++++ templates/admin/document/index.html.twig | 10 +++- templates/admin/document/rename.html.twig | 9 ++++ 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 src/Controller/Admin/Document/RenameController.php create mode 100644 templates/admin/document/rename.html.twig diff --git a/src/Controller/Admin/Document/RenameController.php b/src/Controller/Admin/Document/RenameController.php new file mode 100644 index 0000000..149b953 --- /dev/null +++ b/src/Controller/Admin/Document/RenameController.php @@ -0,0 +1,54 @@ +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); + } +} \ No newline at end of file diff --git a/templates/admin/document/index.html.twig b/templates/admin/document/index.html.twig index 3f45171..dbdab1a 100644 --- a/templates/admin/document/index.html.twig +++ b/templates/admin/document/index.html.twig @@ -30,7 +30,7 @@ {% for document in pagination %} - {{ document.originalFilename }} + {{ document.displayName ? document.displayName : document.originalFilename }} {{ document.size|file_size }} @@ -61,6 +61,14 @@ }) }}> {{ icon('refresh') }} + {{ icon('download') }} diff --git a/templates/admin/document/rename.html.twig b/templates/admin/document/rename.html.twig new file mode 100644 index 0000000..f12e21b --- /dev/null +++ b/templates/admin/document/rename.html.twig @@ -0,0 +1,9 @@ +{{ form_start(form) }} +
+ {{ form_row(form.displayName) }} +
+ +{{ form_rest(form) }} +{{ form_end(form) }}