From c06f17550e414cc7713d3d725096de370acf36f4 Mon Sep 17 00:00:00 2001 From: Paul Coudeville Date: Wed, 4 Sep 2024 16:47:21 +0200 Subject: [PATCH] fix(errs): fixing errors --- src/Controller/Api/BlockController.php | 28 ++++++++++++++++++++++++++ src/Controller/Api/ZoneController.php | 1 + src/Registry/EntityRegistry.php | 5 +++++ src/Resources/editor/src/App.vue | 2 ++ src/Service/ZoneService.php | 19 +++++++++-------- 5 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 src/Controller/Api/BlockController.php diff --git a/src/Controller/Api/BlockController.php b/src/Controller/Api/BlockController.php new file mode 100644 index 00000000..c0dd9e81 --- /dev/null +++ b/src/Controller/Api/BlockController.php @@ -0,0 +1,28 @@ +entityRegistry = $entityRegistry; + } + + /** + * Endpoint to list all available blocks + */ + public function listBlocks(): JsonResponse + { + $this->entityRegistry->getAvailableBlockTypes(); + } + +} diff --git a/src/Controller/Api/ZoneController.php b/src/Controller/Api/ZoneController.php index c9ae88ee..6ecd3e84 100644 --- a/src/Controller/Api/ZoneController.php +++ b/src/Controller/Api/ZoneController.php @@ -91,4 +91,5 @@ public function updateZone(Request $request, string $id): JsonResponse return new JsonResponse(['status' => 'Zone updated successfully']); } + } diff --git a/src/Registry/EntityRegistry.php b/src/Registry/EntityRegistry.php index 8bacbb3d..b84a720e 100644 --- a/src/Registry/EntityRegistry.php +++ b/src/Registry/EntityRegistry.php @@ -39,4 +39,9 @@ public function getFieldClass(string $type): ?string { return $this->fieldTypes[$type] ?? null; } + + public function getAvailableBlock(): BlockCollection + { + + } } diff --git a/src/Resources/editor/src/App.vue b/src/Resources/editor/src/App.vue index ec2263aa..6b667290 100644 --- a/src/Resources/editor/src/App.vue +++ b/src/Resources/editor/src/App.vue @@ -8,9 +8,11 @@ import { buildNewBlockContentFromBlockStructure } from "./core-logic/utils/build const zoneStore = useZoneStore(); onMounted(() => { + // @todo: get the content from the server instead of using the test data const columnContent = buildNewBlockContentFromBlockStructure(columnStructure); const allFieldsContent = buildNewBlockContentFromBlockStructure(allFieldsStructure); + zoneStore.$patch({ availableBlocks: [columnStructure, allFieldsStructure], content: [columnContent, allFieldsContent], diff --git a/src/Service/ZoneService.php b/src/Service/ZoneService.php index 28b2db47..a7273279 100644 --- a/src/Service/ZoneService.php +++ b/src/Service/ZoneService.php @@ -4,13 +4,10 @@ namespace PrestaSafe\PrettyBlocks\Service; -use PrestaSafe\PrettyBlocks\Entity\Component\AbstractComponent; -use PrestaSafe\PrettyBlocks\Entity\PrimitiveField\AbstractPrimitiveField; -use PrestaSafe\PrettyBlocks\Entity\PrimitiveField\TextField; +use PrestaSafe\PrettyBlocks\Entity\Block\BlockInterface; use PrestaSafe\PrettyBlocks\Entity\Zone; use PrestaSafe\PrettyBlocks\Factory\EntityFactory; use PrestaSafe\PrettyBlocks\Repository\ZoneRepository; -use PrestaSafe\PrettyBlocks\Entity\Block\BlockInterface; class ZoneService { @@ -42,16 +39,22 @@ public function updateZone(Zone $zone, array $blocks): void // Add new blocks foreach ($blocks as $blockData) { - $block = $this->hydrateBlockFromData($blockData); + $block = $this->hydrateBlockFromDataStructure($blockData); $zone->addBlock($block); } $this->zoneRepository->save($zone); } - private function hydrateBlockFromData(array $data): BlockInterface + private function hydrateBlockFromDataStructure(array $data): BlockInterface { - return $this->entityFactory->createBlock($data); - } + $block = $this->entityFactory->createBlock($data); + // Hydrater les champs du bloc + foreach ($data['fields'] as $fieldData) { + $field = $this->entityFactory->createField($fieldData); + $block->addField($field); + } + return $block; + } }