diff --git a/.idea/Easy_solution.iml b/.idea/Easy_solution.iml index 38c7f27..c9acc92 100644 --- a/.idea/Easy_solution.iml +++ b/.idea/Easy_solution.iml @@ -21,5 +21,7 @@ + + \ No newline at end of file diff --git a/assets/app.js b/assets/app.js index c70ee04..07bb76e 100644 --- a/assets/app.js +++ b/assets/app.js @@ -18,3 +18,4 @@ import './js/hoverable-collapse.js'; import './js/cookies.js'; import 'choices.js'; import 'choices.js/public/assets/styles/choices.min.css'; +import 'quill' diff --git a/assets/controllers/application_controller.js b/assets/controllers/application_controller.js new file mode 100644 index 0000000..4b1942b --- /dev/null +++ b/assets/controllers/application_controller.js @@ -0,0 +1,40 @@ +import { Controller } from '@hotwired/stimulus' +import Quill from 'quill' +// controllers/application_controller.js +export default class extends Controller { + static targets = ['hidden'] + + connect() { + // Map each editor to its toolbar and hidden field + this.editors = [ + { + editorSelector: '#editor-description', + toolbarSelector: '#toolbar-description', + hiddenTarget: this.hiddenTargets[0], + }, + { + editorSelector: '#editor-descriptionSmall', + toolbarSelector: '#toolbar-descriptionSmall', + hiddenTarget: this.hiddenTargets[1], + }, + ] + + this.editors.forEach(({ editorSelector, toolbarSelector, hiddenTarget }) => { + const quill = new Quill(editorSelector, { + modules: { + toolbar: toolbarSelector, // HTML toolbar container + }, + theme: 'snow', // include quill.snow.css + placeholder: 'Écrivez votre texte...', + }) + + // Keep hidden field in sync with editor HTML + quill.on('text-change', () => { + hiddenTarget.value = quill.root.innerHTML + }) + + // Ensure initial value sync in case user submits without changes + hiddenTarget.value = quill.root.innerHTML + }) + } +} \ No newline at end of file diff --git a/importmap.php b/importmap.php index 5111ef4..e42216c 100644 --- a/importmap.php +++ b/importmap.php @@ -42,4 +42,28 @@ return [ 'version' => '11.1.0', 'type' => 'css', ], + 'quill' => [ + 'version' => '2.0.3', + ], + 'lodash-es' => [ + 'version' => '4.17.21', + ], + 'parchment' => [ + 'version' => '3.0.0', + ], + 'quill-delta' => [ + 'version' => '5.1.0', + ], + 'eventemitter3' => [ + 'version' => '5.0.1', + ], + 'fast-diff' => [ + 'version' => '1.3.0', + ], + 'lodash.clonedeep' => [ + 'version' => '4.5.0', + ], + 'lodash.isequal' => [ + 'version' => '4.5.0', + ], ]; diff --git a/migrations/Version20251008081943.php b/migrations/Version20251008081943.php new file mode 100644 index 0000000..6577976 --- /dev/null +++ b/migrations/Version20251008081943.php @@ -0,0 +1,36 @@ +addSql('ALTER TABLE apps ALTER description TYPE TEXT'); + $this->addSql('ALTER TABLE apps ALTER description DROP NOT NULL'); + $this->addSql('ALTER TABLE apps ALTER description_small TYPE TEXT'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('CREATE SCHEMA public'); + $this->addSql('ALTER TABLE apps ALTER description TYPE VARCHAR(255)'); + $this->addSql('ALTER TABLE apps ALTER description SET NOT NULL'); + $this->addSql('ALTER TABLE apps ALTER description_small TYPE VARCHAR(255)'); + } +} diff --git a/src/Controller/ApplicationController.php b/src/Controller/ApplicationController.php index 03c36e9..c312d04 100644 --- a/src/Controller/ApplicationController.php +++ b/src/Controller/ApplicationController.php @@ -3,8 +3,11 @@ namespace App\Controller; use App\Entity\Apps; +use App\Service\ActionService; +use App\Service\UserService; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; @@ -12,7 +15,7 @@ use Symfony\Component\Routing\Attribute\Route; class ApplicationController extends AbstractController { - public function __construct(private readonly EntityManagerInterface $entityManager) + public function __construct(private readonly EntityManagerInterface $entityManager, private readonly UserService $userService, private readonly ActionService $actionService) { } @@ -27,4 +30,38 @@ class ApplicationController extends AbstractController ]); } + #[Route(path: '/edit/{id}', name: 'edit', methods: ['GET', 'POST'])] + public function edit(int $id, Request $request): Response{ + $this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN'); + $actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier()); + $application = $this->entityManager->getRepository(Apps::class)->find($id); + if (!$application) { + $this->addFlash('error', "L'application n'existe pas ou n'est pas reconnu."); + return $this->redirectToRoute('application_index'); + } + $applicationData = [ + 'id' => $application->getId(), + 'name' => $application->getName(), + 'description' => $application->getDescription(), + 'descriptionSmall' => $application->getDescriptionSmall(), + 'isActive' => $application->isActive(), + ]; + + + if ($request->isMethod('POST')) { + $data = $request->request->all(); + $application->setName($data['name']); + $application->setDescription($data['description']); + $application->setDescriptionSmall($data['descriptionSmall']); + $this->entityManager->persist($application); + $this->actionService->createAction("Modification de l'application ", $actingUser, null, $application->getId()); + + return $this->redirectToRoute('application_index'); + } + return $this->render('application/edit.html.twig', [ + 'apps' => $applicationData, + ]); + + } + } diff --git a/src/Entity/Apps.php b/src/Entity/Apps.php index 3306c8c..9431f35 100644 --- a/src/Entity/Apps.php +++ b/src/Entity/Apps.php @@ -5,6 +5,7 @@ namespace App\Entity; use App\Repository\AppsRepository; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; +use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity(repositoryClass: AppsRepository::class)] @@ -24,7 +25,7 @@ class Apps #[ORM\Column(length: 255)] private ?string $logo_url = null; - #[ORM\Column(length: 255)] + #[ORM\Column(type: Types::TEXT, nullable: true)] private ?string $description = null; #[ORM\Column(length: 255)] @@ -33,7 +34,7 @@ class Apps #[ORM\Column(options: ['default' => true])] private ?bool $isActive = null; - #[ORM\Column(length: 255, nullable: true)] + #[ORM\Column(type: Types::TEXT, nullable: true)] private ?string $descriptionSmall = null; /** diff --git a/templates/application/InformationCard.html.twig b/templates/application/InformationCard.html.twig index 9432d52..0619264 100644 --- a/templates/application/InformationCard.html.twig +++ b/templates/application/InformationCard.html.twig @@ -8,9 +8,12 @@
-

{{ application.description }}

+

{{ application.description|raw }}

Accéder à l'application + {% if is_granted("ROLE_SUPER_ADMIN") %} + Modifier l'application + {% endif %}
diff --git a/templates/application/appSmall.html.twig b/templates/application/appSmall.html.twig index bd51879..2cd60af 100644 --- a/templates/application/appSmall.html.twig +++ b/templates/application/appSmall.html.twig @@ -8,7 +8,7 @@