From 7dc501cbda9e97dede8fcb14dc3e59962f9f2cd2 Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Fri, 6 Aug 2021 15:00:08 +0200 Subject: [PATCH] Creation of DocGenTemplate entity --- composer.json | 3 +- .../AdminDocGeneratorTemplateController.php | 9 +++ .../Controller/DocGeneratorController.php | 31 ++++++++ .../ChillDocGeneratorExtension.php | 50 +++++++++--- .../Entity/DocGeneratorTemplate.php | 77 +++++++++++++++++++ .../Form/DocGeneratorTemplateType.php | 38 +++++++++ .../DocGeneratorTemplateRepository.php | 21 +++++ .../config/{routing.yml => routes.yml} | 0 .../Admin/DocGeneratorTemplate/edit.twig.html | 12 +++ .../DocGeneratorTemplate/index.twig.html | 19 +++++ .../Admin/DocGeneratorTemplate/new.twig.html | 11 +++ .../migrations/Version20210805162522.php | 31 ++++++++ 12 files changed, 291 insertions(+), 11 deletions(-) create mode 100644 src/Bundle/ChillDocGeneratorBundle/Controller/AdminDocGeneratorTemplateController.php create mode 100644 src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorController.php create mode 100644 src/Bundle/ChillDocGeneratorBundle/Entity/DocGeneratorTemplate.php create mode 100644 src/Bundle/ChillDocGeneratorBundle/Form/DocGeneratorTemplateType.php create mode 100644 src/Bundle/ChillDocGeneratorBundle/Repository/DocGeneratorTemplateRepository.php rename src/Bundle/ChillDocGeneratorBundle/Resources/config/{routing.yml => routes.yml} (100%) create mode 100644 src/Bundle/ChillDocGeneratorBundle/Resources/view/Admin/DocGeneratorTemplate/edit.twig.html create mode 100644 src/Bundle/ChillDocGeneratorBundle/Resources/view/Admin/DocGeneratorTemplate/index.twig.html create mode 100644 src/Bundle/ChillDocGeneratorBundle/Resources/view/Admin/DocGeneratorTemplate/new.twig.html create mode 100644 src/Bundle/ChillDocGeneratorBundle/migrations/Version20210805162522.php diff --git a/composer.json b/composer.json index b5af76421..680307a7f 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,8 @@ "Chill\\PersonBundle\\": "src/Bundle/ChillPersonBundle", "Chill\\ReportBundle\\": "src/Bundle/ChillReportBundle", "Chill\\TaskBundle\\": "src/Bundle/ChillTaskBundle", - "Chill\\ThirdPartyBundle\\": "src/Bundle/ChillThirdPartyBundle" + "Chill\\ThirdPartyBundle\\": "src/Bundle/ChillThirdPartyBundle", + "Chill\\DocGeneratorBundle\\": "src/Bundle/ChillDocGeneratorBundle" } }, "autoload-dev": { diff --git a/src/Bundle/ChillDocGeneratorBundle/Controller/AdminDocGeneratorTemplateController.php b/src/Bundle/ChillDocGeneratorBundle/Controller/AdminDocGeneratorTemplateController.php new file mode 100644 index 000000000..0b870a34e --- /dev/null +++ b/src/Bundle/ChillDocGeneratorBundle/Controller/AdminDocGeneratorTemplateController.php @@ -0,0 +1,9 @@ +setContent('Test'); + } +} diff --git a/src/Bundle/ChillDocGeneratorBundle/DependencyInjection/ChillDocGeneratorExtension.php b/src/Bundle/ChillDocGeneratorBundle/DependencyInjection/ChillDocGeneratorExtension.php index 20c460347..24f3a2d01 100644 --- a/src/Bundle/ChillDocGeneratorBundle/DependencyInjection/ChillDocGeneratorExtension.php +++ b/src/Bundle/ChillDocGeneratorBundle/DependencyInjection/ChillDocGeneratorExtension.php @@ -13,7 +13,7 @@ use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; * * @link http://symfony.com/doc/current/cookbook/bundles/extension.html */ -class ChillCalendarExtension extends Extension implements PrependExtensionInterface +class ChillDocGeneratorExtension extends Extension implements PrependExtensionInterface { /** * {@inheritdoc} @@ -33,19 +33,49 @@ class ChillCalendarExtension extends Extension implements PrependExtensionInterf public function prepend(ContainerBuilder $container) { $this->preprendRoutes($container); + $this->prependCruds($container); } protected function preprendRoutes(ContainerBuilder $container) { - - $container->prependExtensionConfig('chill_main', [ - 'routing' => [ - 'resources' => [ - '@ChillDocGeneratorBundle/Resources/config/routing.yml' - ] - ] - ]); + $container->prependExtensionConfig('chill_main', array( + 'routing' => array( + 'resources' => array( + '@ChillDocGeneratorBundle/Resources/config/routes.yml' + ) + ) + )); } - + /** + * @param ContainerBuilder $container + */ + protected function prependCruds(ContainerBuilder $container) + { + $container->prependExtensionConfig('chill_main', [ + 'cruds' => [ + [ + 'class' => \Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate::class, + 'name' => 'docgen_template', + 'base_path' => '/admin/docgen/template', + 'form_class' => \Chill\DocGeneratorBundle\Form\DocGeneratorTemplateType::class, + 'controller' => \Chill\DocGeneratorBundle\Controller\AdminDocGeneratorTemplateController::class, + 'actions' => [ + 'index' => [ + 'template' => '@ChillDocGenerator/Admin/DocGeneratorTemplate/index.html.twig', + 'role' => 'ROLE_ADMIN' + ], + 'new' => [ + 'role' => 'ROLE_ADMIN', + 'template' => '@ChillDocGenerator/Admin/DocGeneratorTemplate/new.html.twig', + ], + 'edit' => [ + 'role' => 'ROLE_ADMIN', + 'template' => '@ChillDocGenerator/Admin/DocGeneratorTemplate/edit.html.twig', + ] + ] + ] + ] + ]); + } } diff --git a/src/Bundle/ChillDocGeneratorBundle/Entity/DocGeneratorTemplate.php b/src/Bundle/ChillDocGeneratorBundle/Entity/DocGeneratorTemplate.php new file mode 100644 index 000000000..430042024 --- /dev/null +++ b/src/Bundle/ChillDocGeneratorBundle/Entity/DocGeneratorTemplate.php @@ -0,0 +1,77 @@ +id; + } + + public function getName(): ?array + { + return $this->name; + } + + public function setName(array $name): self + { + $this->name = $name; + + return $this; + } + + public function getDescription(): ?string + { + return $this->description; + } + + public function setDescription(?string $description): self + { + $this->description = $description; + + return $this; + } + + public function getFile(): ?string + { + return $this->file; + } + + public function setFile(string $file): self + { + $this->file = $file; + + return $this; + } +} diff --git a/src/Bundle/ChillDocGeneratorBundle/Form/DocGeneratorTemplateType.php b/src/Bundle/ChillDocGeneratorBundle/Form/DocGeneratorTemplateType.php new file mode 100644 index 000000000..a0f36da0a --- /dev/null +++ b/src/Bundle/ChillDocGeneratorBundle/Form/DocGeneratorTemplateType.php @@ -0,0 +1,38 @@ +add('name', TranslatableStringFormType::class, [ + 'label' => 'Nom' + ]) + ->add('description') + ->add('file') + ; + } + + /** + * @param OptionsResolver $resolver + */ + public function configureOptions(OptionsResolver $resolver) + { + $resolver + ->setDefault('class', DocGeneratorTemplate::class) + ; + } +} diff --git a/src/Bundle/ChillDocGeneratorBundle/Repository/DocGeneratorTemplateRepository.php b/src/Bundle/ChillDocGeneratorBundle/Repository/DocGeneratorTemplateRepository.php new file mode 100644 index 000000000..83f206d4b --- /dev/null +++ b/src/Bundle/ChillDocGeneratorBundle/Repository/DocGeneratorTemplateRepository.php @@ -0,0 +1,21 @@ +{{ 'Title'|trans }} + {{ 'File'|trans }} + {% endblock %} + + {% block table_entities_tbody %} + {% for entity in entities %} + + {{ entity.name | localize_translatable_string }} + {{ entity.file }} + + {% endfor %} + {% endblock %} + {% endembed %} +{% endblock %} diff --git a/src/Bundle/ChillDocGeneratorBundle/Resources/view/Admin/DocGeneratorTemplate/new.twig.html b/src/Bundle/ChillDocGeneratorBundle/Resources/view/Admin/DocGeneratorTemplate/new.twig.html new file mode 100644 index 000000000..f31ac39c9 --- /dev/null +++ b/src/Bundle/ChillDocGeneratorBundle/Resources/view/Admin/DocGeneratorTemplate/new.twig.html @@ -0,0 +1,11 @@ +{% extends '@ChillPerson/Admin/layout.html.twig' %} + +{% block title %} + {% include('@ChillMain/CRUD/_new_title.html.twig') %} +{% endblock %} + +{% block layout_wvm_content %} + {% embed '@ChillMain/CRUD/_new_content.html.twig' %} + {% block content_form_actions_save_and_show %}{% endblock %} + {% endembed %} +{% endblock %} diff --git a/src/Bundle/ChillDocGeneratorBundle/migrations/Version20210805162522.php b/src/Bundle/ChillDocGeneratorBundle/migrations/Version20210805162522.php new file mode 100644 index 000000000..26a6c3d56 --- /dev/null +++ b/src/Bundle/ChillDocGeneratorBundle/migrations/Version20210805162522.php @@ -0,0 +1,31 @@ +addSql('CREATE SEQUENCE chill_docgen_template_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE TABLE chill_docgen_template (id INT NOT NULL, name JSON NOT NULL, description TEXT DEFAULT NULL, file VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); + } + + public function down(Schema $schema): void + { + $this->addSql('DROP SEQUENCE chill_docgen_template_id_seq CASCADE'); + $this->addSql('DROP TABLE chill_docgen_template'); + } +}