diff --git a/assets/controllers.json b/assets/controllers.json index a1c6e90..5070c63 100644 --- a/assets/controllers.json +++ b/assets/controllers.json @@ -1,4 +1,14 @@ { - "controllers": [], + "controllers": { + "@symfony/ux-dropzone": { + "dropzone": { + "enabled": true, + "fetch": "eager", + "autoimport": { + "@symfony/ux-dropzone/src/style.css": true + } + } + } + }, "entrypoints": [] } diff --git a/assets/controllers/mydropzone_controller.js b/assets/controllers/mydropzone_controller.js new file mode 100644 index 0000000..5df055e --- /dev/null +++ b/assets/controllers/mydropzone_controller.js @@ -0,0 +1,36 @@ +// mydropzone_controller.js + +import { Controller } from '@hotwired/stimulus'; + +export default class extends Controller { + connect() { + this.element.addEventListener('dropzone:connect', this._onConnect); + this.element.addEventListener('dropzone:change', this._onChange); + this.element.addEventListener('dropzone:clear', this._onClear); + } + + disconnect() { + // You should always remove listeners when the controller is disconnected to avoid side-effects + this.element.removeEventListener('dropzone:connect', this._onConnect); + this.element.removeEventListener('dropzone:change', this._onChange); + this.element.removeEventListener('dropzone:clear', this._onClear); + } + + _onConnect(event) { + // The dropzone was just created + console.info(event); + console.info('onconnect'); + } + + _onChange(event) { + // The dropzone just changed + console.info(event); + console.info('onchange'); + } + + _onClear(event) { + // The dropzone has just been cleared + console.info(event); + console.info('onclear'); + } +} \ No newline at end of file diff --git a/composer.json b/composer.json index 7f2d052..8386df8 100644 --- a/composer.json +++ b/composer.json @@ -39,6 +39,7 @@ "symfony/string": "6.0.*", "symfony/translation": "6.0.*", "symfony/twig-bundle": "6.0.*", + "symfony/ux-dropzone": "^2.1", "symfony/validator": "6.0.*", "symfony/web-link": "6.0.*", "symfony/webapp-meta": "^1.0", diff --git a/composer.lock b/composer.lock index f18c8c9..894fbcc 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "2eef8acf0a01cf89e1edb8087c4d2ac3", + "content-hash": "38958ff5221180c36bc97324f82755b6", "packages": [ { "name": "doctrine/annotations", @@ -7460,6 +7460,86 @@ ], "time": "2022-04-03T13:04:20+00:00" }, + { + "name": "symfony/ux-dropzone", + "version": "v2.1.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/ux-dropzone.git", + "reference": "e5115ed7fc894248b77bffebb7f57bc2f584d219" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/ux-dropzone/zipball/e5115ed7fc894248b77bffebb7f57bc2f584d219", + "reference": "e5115ed7fc894248b77bffebb7f57bc2f584d219", + "shasum": "" + }, + "require": { + "php": ">=7.2.5", + "symfony/config": "^4.4.17|^5.0|^6.0", + "symfony/dependency-injection": "^4.4.17|^5.0|^6.0", + "symfony/form": "^4.4.17|^5.0|^6.0", + "symfony/http-kernel": "^4.4.17|^5.0|^6.0" + }, + "require-dev": { + "symfony/framework-bundle": "^4.4.17|^5.0|^6.0", + "symfony/phpunit-bridge": "^5.2|^6.0", + "symfony/twig-bundle": "^4.4.17|^5.0|^6.0", + "symfony/var-dumper": "^4.4.17|^5.0|^6.0" + }, + "type": "symfony-bundle", + "extra": { + "thanks": { + "name": "symfony/ux", + "url": "https://github.com/symfony/ux" + } + }, + "autoload": { + "psr-4": { + "Symfony\\UX\\Dropzone\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Titouan Galopin", + "email": "galopintitouan@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "File input dropzones for Symfony Forms", + "homepage": "https://symfony.com", + "keywords": [ + "symfony-ux" + ], + "support": { + "source": "https://github.com/symfony/ux-dropzone/tree/v2.1.1" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-02-01T04:57:29+00:00" + }, { "name": "symfony/validator", "version": "v6.0.8", diff --git a/config/services.yaml b/config/services.yaml index 06bf8e4..9d2e30e 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -6,6 +6,9 @@ parameters: book_covers: '%kernel.project_dir%/public/book_covers/' book_files: '%kernel.project_dir%/public/book_files/' + api_pass: 'secret_password' + api_user: 'my_name' + bankAccount: '1093849023/2013' services: # default configuration for services in *this* file @@ -13,6 +16,8 @@ services: autowire: true # Automatically injects dependencies in your services. autoconfigure: true # Automatically registers your services as commands, event subscribers, etc. + + # makes classes in src/ available to be used as services # this creates a service per class whose id is the fully-qualified class name App\: @@ -22,5 +27,9 @@ services: - '../src/Entity/' - '../src/Kernel.php' + App\Service\FileService: + arguments: + $bookFiles: '%book_files%' + # add more service definitions when explicit configuration is needed # please note that last definitions always *replace* previous ones diff --git a/package.json b/package.json index ea9f322..addfcba 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "devDependencies": { "@hotwired/stimulus": "^3.0.0", "@symfony/stimulus-bridge": "^3.0.0", + "@symfony/ux-dropzone": "file:vendor/symfony/ux-dropzone/Resources/assets", "@symfony/webpack-encore": "^2.0.0", "axios": "^0.27.2", "core-js": "^3.0.0", diff --git a/src/Controller/FileController.php b/src/Controller/FileController.php index dd835fd..863dcd9 100644 --- a/src/Controller/FileController.php +++ b/src/Controller/FileController.php @@ -44,9 +44,9 @@ class FileController extends AbstractController public function get(File $file) { return $this->file( - $filePath = $this->getParameter('book_files') . '/' . 'ebook_' . $file->getBook()->getId() . '_' . - md5($file->getFileName()) . '.' . - $file->getExtension(), + $this->getParameter('book_files') . '/' . 'ebook_' . $file->getBook()->getId() . '_' . + md5($file->getFileName()) . '.' . + $file->getExtension(), $file->getFileName() ); } diff --git a/src/Service/FileService.php b/src/Service/FileService.php new file mode 100644 index 0000000..ac042ba --- /dev/null +++ b/src/Service/FileService.php @@ -0,0 +1,36 @@ +bookFiles = $bookFiles; + $this->fileSystem = $filesystem; + } + + /** + * @param File[] $files + * @return void + */ + public function removeFiles(Collection $files) + { + foreach ($files as $file) { + $filePath = $this->bookFiles . '/' . 'ebook_' . $file->getBook()->getId() . '_' . + md5($file->getFileName()) . '.' . + $file->getExtension(); + + $this->fileSystem->remove($filePath); + } + } + +} \ No newline at end of file diff --git a/symfony.lock b/symfony.lock index 3f3df32..9d8402a 100644 --- a/symfony.lock +++ b/symfony.lock @@ -462,6 +462,9 @@ "./templates/base.html.twig" ] }, + "symfony/ux-dropzone": { + "version": "v2.1.1" + }, "symfony/validator": { "version": "6.0", "recipe": { diff --git a/templates/book/edit.html.twig b/templates/book/edit.html.twig index fdfe499..e9ddd4b 100644 --- a/templates/book/edit.html.twig +++ b/templates/book/edit.html.twig @@ -7,7 +7,6 @@ {{ include('book/_form.html.twig', {'button_label': 'Update'}) }} - back to list {{ include('book/_delete_form.html.twig') }} {% endblock %} diff --git a/templates/book/index.html.twig b/templates/book/index.html.twig index 66617a0..5aba8bf 100644 --- a/templates/book/index.html.twig +++ b/templates/book/index.html.twig @@ -3,29 +3,40 @@ {% block title %}Book index{% endblock %} {% block body %} -

Book index

+
+
+

Book index

+
+
+ Create new +
+
+ - - - - - - - - - - + + + + + + + + + + {% for book in books %} - + - +
CoverIdTitleLanguageDescriptionPublisherPublish_dateactions
CoverIdTitleLanguageDescriptionPublisherPublish_dateactions
{% if file_exists(asset('book_covers/cover_' ~ book.id ~ '.jpg')) %} {% endif %}{% if file_exists(asset('book_covers/cover_' ~ book.id ~ '.jpg')) %} {% endif %} + {{ book.id }} {{ book.Title }} {{ book.language }}{{ book.description }}{{ book.description | slice(0, 200) }} {{ book.publisher }} {{ book.publishDate ? book.publishDate|date('Y-m-d') : '' }} @@ -40,6 +51,4 @@ {% endfor %}
- - Create new {% endblock %} diff --git a/templates/book/new.html.twig b/templates/book/new.html.twig index e08466d..dc7fda8 100644 --- a/templates/book/new.html.twig +++ b/templates/book/new.html.twig @@ -9,7 +9,6 @@ {{ include('book/_form.html.twig') }} - back to list {% endblock %} {% block javascripts %} diff --git a/templates/book/show.html.twig b/templates/book/show.html.twig index 896ee5c..27a63f5 100644 --- a/templates/book/show.html.twig +++ b/templates/book/show.html.twig @@ -21,7 +21,7 @@ Description - {{ book.description }} + {{ book.description | nl2br }} Publisher @@ -39,7 +39,7 @@ Id File name - File size + File size Extension Download Remove @@ -50,7 +50,7 @@ {{ file.id }} {{ file.fileName }} - {{ file.fileSize | bytes_format }} + {{ file.fileSize | bytes_format }} {{ file.extension }} download remove diff --git a/yarn.lock b/yarn.lock index 2cbf318..38a36a2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1008,6 +1008,9 @@ loader-utils "^2.0.0" schema-utils "^3.0.0" +"@symfony/ux-dropzone@file:vendor/symfony/ux-dropzone/Resources/assets": + version "1.1.0" + "@symfony/webpack-encore@^2.0.0": version "2.1.0" resolved "https://registry.yarnpkg.com/@symfony/webpack-encore/-/webpack-encore-2.1.0.tgz#353a1b8bc38022046cbbc3d627c4076aca2e28c3"