From 623aa9187270136c920ff9c2dd5a20dcf8200750 Mon Sep 17 00:00:00 2001 From: krzysiej Date: Tue, 31 May 2022 14:39:32 +0200 Subject: [PATCH] Styled book form and added an ux dropzone component. --- assets/js/pages/book.vue | 15 ++++-- config/bundles.php | 1 + src/Controller/BookController.php | 7 +-- src/Form/BookType.php | 5 +- templates/book/_delete_form.html.twig | 17 ++++-- templates/book/_form.html.twig | 78 ++++++++++++++++++++++++++- 6 files changed, 107 insertions(+), 16 deletions(-) diff --git a/assets/js/pages/book.vue b/assets/js/pages/book.vue index 13e60f7..2083623 100644 --- a/assets/js/pages/book.vue +++ b/assets/js/pages/book.vue @@ -12,7 +12,7 @@
-
+
@@ -21,8 +21,12 @@
- - +

Oh no 😢

+ +
+ + +
@@ -37,7 +41,8 @@ export default { return { searchTerm: null, books: [], - selectedBook: null + selectedBook: null, + manualMode: false } }, methods: { @@ -48,7 +53,7 @@ export default { }); }, getBookDetails: function (url) { - console.info(url); + this.manualMode = true; axios.get('/book/info/' + btoa(url)).then(response => { const book = this.selectedBook = response.data; this.$el.querySelector('#book_title').value = book.title; diff --git a/config/bundles.php b/config/bundles.php index c1e923b..f1ed3df 100644 --- a/config/bundles.php +++ b/config/bundles.php @@ -13,4 +13,5 @@ return [ Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true], Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true], Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true], + Symfony\UX\Dropzone\DropzoneBundle::class => ['all' => true], ]; diff --git a/src/Controller/BookController.php b/src/Controller/BookController.php index 2f873e3..2a8823d 100644 --- a/src/Controller/BookController.php +++ b/src/Controller/BookController.php @@ -7,14 +7,13 @@ use App\Entity\File; use App\Form\BookType; use App\Repository\BookRepository; use App\Repository\FileRepository; +use App\Service\FileService; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; -use Symfony\Component\HttpFoundation\BinaryFileResponse; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; use Techtube\Bookinfo\BookFinder; -use Techtube\Bookinfo\DataParser; #[Route('/book')] class BookController extends AbstractController @@ -143,10 +142,12 @@ class BookController extends AbstractController } #[Route('/{id}', name: 'app_book_delete', methods: ['POST'])] - public function delete(Request $request, Book $book, BookRepository $bookRepository): Response + public function delete(Request $request, Book $book, BookRepository $bookRepository, FileService $fileService): Response { if ($this->isCsrfTokenValid('delete' . $book->getId(), $request->request->get('_token'))) { + $fileService->removeFiles($book->getFiles()); $bookRepository->remove($book, true); + } return $this->redirectToRoute('app_book_index', [], Response::HTTP_SEE_OTHER); diff --git a/src/Form/BookType.php b/src/Form/BookType.php index 7e2917b..0ab09ad 100644 --- a/src/Form/BookType.php +++ b/src/Form/BookType.php @@ -11,6 +11,7 @@ use Symfony\Component\Form\Extension\Core\Type\IntegerType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; +use Symfony\UX\Dropzone\Form\DropzoneType; class BookType extends AbstractType { @@ -52,9 +53,9 @@ class BookType extends AbstractType 'required' => false, 'attr' => ['accept' => ".pdf, .epub, .mobi"] ]) - ->add('cover', FileType::class, ['mapped' => false, 'data_class' => null, 'required' => false]) +// ->add('cover', FileType::class, ['mapped' => false, 'data_class' => null, 'required' => false]) ->add('cover_url', TextType::class, ['mapped' => false, 'help' => 'Fill in the field with a link to a cover image to use it as a cover for the book.', 'label'=> 'Cover url', 'required' => false]) - + ->add('cover', DropzoneType::class, ['mapped' => false, 'data_class' => null, 'required' => false, 'attr' => ['data-controller' => 'mydropzone', 'accept' => "image/*", 'placeholder' => 'Drag and drop or browse']]) ; } diff --git a/templates/book/_delete_form.html.twig b/templates/book/_delete_form.html.twig index 9dcce07..fec1945 100644 --- a/templates/book/_delete_form.html.twig +++ b/templates/book/_delete_form.html.twig @@ -1,4 +1,13 @@ -
- - -
+
+
Danger zone
+
+
Delete book with all the information and files
+

Some quick example text to build on the card title and make up the bulk of the card's content.

+
+ + +
+
+
+ + diff --git a/templates/book/_form.html.twig b/templates/book/_form.html.twig index 9328bd5..421a674 100644 --- a/templates/book/_form.html.twig +++ b/templates/book/_form.html.twig @@ -1,4 +1,78 @@ {{ form_start(form) }} - {{ form_widget(form) }} - +
+ {{ form_errors(form) }} +
+
+ {# #} +
+ {{ form_row(form.title) }} +
+
+ {{ form_row(form.subtitle) }} +
+ +
+ {{ form_row(form.author) }} +
+
+ {{ form_row(form.category) }} +
+ +
+ {{ form_row(form.isbn) }} +
+
+ {{ form_row(form.pages) }} +
+
+ {{ form_row(form.tags) }} +
+ +
+ {{ form_row(form.publish_date) }} +
+
+ {{ form_row(form.publisher) }} +
+
+ {{ form_row(form.language) }} +
+ +
+ {{ form_row(form.series) }} +
+
+ {{ form_row(form.volume) }} +
+
+ {{ form_row(form.rating) }} +
+ +
+ {{ form_row(form.description) }} +
+ +
+ {{ form_row(form.ebook) }} +
+ {% if file_exists(asset('book_covers/cover_' ~ book.id ~ '.jpg')) %} +
+ +
+ {% endif %} +
+ {{ form_row(form.cover) }} +
+
+ {{ form_row(form.cover_url) }} +
+ +
+ + + +Back to list + {{ form_end(form) }}