diff --git a/src/Bundle/ChillMainBundle/Resources/views/Form/fields.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Form/fields.html.twig index 9f07b3aa0..15794b9f7 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Form/fields.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Form/fields.html.twig @@ -266,27 +266,6 @@ data-label="{{ form.vars['label']|trans|escape('html_attr') }}"> {% endblock %} -{% block pick_linked_entities_row %} -
-
- {{ form_label(form) }} - {{ form_help(form) }} -
-
-
-
- {{ form_widget(form) }} -
-
-{% endblock %} - -{% block pick_linked_entities_widget %} - -
-{% endblock %} - {% block pick_postal_code_widget %} {{ form_help(form)}} diff --git a/src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodWorkDuplicateController.php b/src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodWorkDuplicateController.php index c20340577..03ab458ab 100644 --- a/src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodWorkDuplicateController.php +++ b/src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodWorkDuplicateController.php @@ -11,30 +11,38 @@ declare(strict_types=1); namespace Chill\PersonBundle\Controller; +use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork; use Chill\PersonBundle\Form\FindAccompanyingPeriodWorkType; use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Serializer\Serializer; +use Symfony\Component\Serializer\SerializerInterface; use Symfony\Contracts\Translation\TranslatorInterface; - +use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; class AccompanyingPeriodWorkDuplicateController extends AbstractController { - public function __construct(private readonly AccompanyingPeriodWorkRepository $accompanyingPeriodWorkRepository, private readonly TranslatorInterface $translator) {} + public function __construct(private readonly AccompanyingPeriodWorkRepository $accompanyingPeriodWorkRepository, private readonly TranslatorInterface $translator, private readonly SerializerInterface $serializer) {} + /** + * @ParamConverter("accompanyingPeriodWork", options={"id": "acpw_id"}) + */ #[Route(path: '{_locale}/person/accompanying-period/work/{id}/assign-duplicate', name: 'chill_person_accompanying_period_work_assign_duplicate', methods: ['GET'])] - public function assignDuplicate(int $id, Request $request) + public function assignDuplicate(AccompanyingPeriodWork $acpw, Request $request) { - $acpw1= $this->accompanyingPeriodWorkRepository->find($id); - $accompanyingPeriod = $acpw1->getAccompanyingPeriod(); + $accompanyingPeriod = $acpw->getAccompanyingPeriod(); - if (null === $acpw1) { - throw $this->createNotFoundException("Accompanying period work with id {$id} not".' found on this server'); - } + $acpwList = $this->accompanyingPeriodWorkRepository->findByAccompanyingPeriod($accompanyingPeriod); + + $acpwListArray = $this->serializer->normalize($acpwList, 'json', ['groups' => ['read']]); + $acpwListJson = json_encode($acpwListArray); + + dump($acpwListJson); $this->denyAccessUnlessGranted( 'CHILL_MAIN_ACCOMPANYING_PERIOD_WORK_UPDATE', - $acpw1, + $acpw, 'You are not allowed to merge this accompanying period work' ); @@ -46,23 +54,23 @@ class AccompanyingPeriodWorkDuplicateController extends AbstractController $acpw2 = $form->get('person')->getData(); // Validation: Ensure person1 is not the same as person2 - if ($acpw1->getId() === $acpw2->getId()) { + if ($acpw->getId() === $acpw2->getId()) { $this->addFlash('error', $this->translator->trans('The entities you are trying to merge cannot be the same')); - return $this->redirectToRoute('chill_person_accompanying_period_work_show', ['id' => $acpw1->getId()]); + return $this->redirectToRoute('chill_person_accompanying_period_work_show', ['id' => $acpw->getId()]); } $direction = $form->get('direction')->getData(); if ('starting' === $direction) { $params = [ - 'acpw1_id' => $acpw1->getId(), + 'acpw1_id' => $acpw->getId(), 'acpw2_id' => $acpw2->getId(), ]; } else { $params = [ 'acpw1_id' => $acpw2->getId(), - 'acpw2_id' => $acpw1->getId(), + 'acpw2_id' => $acpw->getId(), ]; } @@ -70,8 +78,9 @@ class AccompanyingPeriodWorkDuplicateController extends AbstractController } return $this->render('@ChillPerson/AccompanyingPeriodWorkDuplicate/assign_acpw_duplicate.html.twig', [ - 'accompanyingCourse' => $acpw1->getAccompanyingPeriod(), - 'acpw' => $acpw1, + 'accompanyingCourse' => $acpw->getAccompanyingPeriod(), + 'acpwListJson' => $acpwListJson, + 'acpw' => $acpw, 'form' => $form->createView(), ]); } diff --git a/src/Bundle/ChillPersonBundle/Form/FindAccompanyingPeriodWorkType.php b/src/Bundle/ChillPersonBundle/Form/FindAccompanyingPeriodWorkType.php index c5ffa5406..1fd856e0b 100644 --- a/src/Bundle/ChillPersonBundle/Form/FindAccompanyingPeriodWorkType.php +++ b/src/Bundle/ChillPersonBundle/Form/FindAccompanyingPeriodWorkType.php @@ -31,10 +31,8 @@ class FindAccompanyingPeriodWorkType extends AbstractType $suggestedAcpw = $this->repository->findByAccompanyingPeriod($accompanyingPeriod); $builder - ->add('acpw', PickLinkedAccompanyingPeriodWorkType::class, [ + ->add('acpw', HiddenType::class, [ 'label' => 'Accompanying period work', - 'suggested' => $suggestedAcpw, - 'multiple' => false, ]) ->add('direction', HiddenType::class, [ 'data' => 'starting', diff --git a/src/Bundle/ChillPersonBundle/Form/Type/PickLinkedAccompanyingPeriodWorkType.php b/src/Bundle/ChillPersonBundle/Form/Type/PickLinkedAccompanyingPeriodWorkType.php deleted file mode 100644 index 5b0e9a7dc..000000000 --- a/src/Bundle/ChillPersonBundle/Form/Type/PickLinkedAccompanyingPeriodWorkType.php +++ /dev/null @@ -1,51 +0,0 @@ -vars['multiple'] = $options['multiple']; - $view->vars['types'] = ['acpw']; - $view->vars['uniqid'] = uniqid('pick_acpw_dyn'); - $view->vars['suggested'] = []; - $view->vars['as_id'] = true === $options['as_id'] ? '1' : '0'; - $view->vars['submit_on_adding_new_entity'] = false; - - foreach ($options['suggested'] as $suggestion) { - $view->vars['suggested'][] = $this->normalizer->normalize($suggestion, 'json', ['groups' => 'read']); - } - } - - public function configureOptions(OptionsResolver $resolver) - { - $resolver - ->setDefault('multiple', false) - ->setAllowedTypes('multiple', ['bool']) - ->setDefault('compound', false) - ->setDefault('suggested', []) - ->setDefault('as_id', false) - ->setAllowedTypes('as_id', ['bool']) - ->setDefault('submit_on_adding_new_entity', false) - ->setAllowedTypes('submit_on_adding_new_entity', ['bool']); - } - - public function getBlockPrefix() - { - return 'pick_linked_entities'; - } - -} diff --git a/src/Bundle/ChillPersonBundle/Resources/public/mod/DuplicateSelector/AccompanyingPeriodWorkSelector.js b/src/Bundle/ChillPersonBundle/Resources/public/mod/DuplicateSelector/AccompanyingPeriodWorkSelector.js new file mode 100644 index 000000000..3ec34b7a4 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Resources/public/mod/DuplicateSelector/AccompanyingPeriodWorkSelector.js @@ -0,0 +1,12 @@ +import { createApp } from 'vue'; +import AccompanyingPeriodWorkSelector from "../../vuejs/_components/DuplicateSelector/AccompanyingPeriodWorkSelector.vue"; + + +document.addEventListener("DOMContentLoaded", () => { + const el = document.getElementById('linked-acpw-selector'); + if (el) { + createApp(AccompanyingPeriodWorkSelector, { + acpwList: JSON.parse(el.dataset.acpwList) + }).mount(el); + } +}); diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/DuplicateSelector/AccompanyingPeriodWorkSelector.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/DuplicateSelector/AccompanyingPeriodWorkSelector.vue new file mode 100644 index 000000000..579b9f638 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/DuplicateSelector/AccompanyingPeriodWorkSelector.vue @@ -0,0 +1,33 @@ + + + + diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/Entity/AccompanyingPeriodWorkRenderBox.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/Entity/AccompanyingPeriodWorkRenderBox.vue index c1b13b319..a596b02fe 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/Entity/AccompanyingPeriodWorkRenderBox.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/Entity/AccompanyingPeriodWorkRenderBox.vue @@ -1,22 +1,42 @@ + diff --git a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingPeriodWorkDuplicate/assign_acpw_duplicate.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingPeriodWorkDuplicate/assign_acpw_duplicate.html.twig index 7a3467f34..c0d142626 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingPeriodWorkDuplicate/assign_acpw_duplicate.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingPeriodWorkDuplicate/assign_acpw_duplicate.html.twig @@ -9,8 +9,10 @@

{{ 'Assign an accompanying period work duplicate'|trans }}

- {{ form_start(form) }} + {%- if form.acpw is defined -%} +
+ {% endif %} {{ form_rest(form) }}