From 8b517f169f309e56985c123bceb5f4f072036c67 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Fri, 24 Feb 2023 17:17:35 +0100 Subject: [PATCH 1/7] FEATURE [suggested][entities] add suggested entities option to dynamic picker types --- src/Bundle/ChillMainBundle/Form/Type/PickUserDynamicType.php | 4 +++- .../ChillPersonBundle/Form/Type/PickPersonDynamicType.php | 4 +++- .../Form/Type/PickThirdpartyDynamicType.php | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Form/Type/PickUserDynamicType.php b/src/Bundle/ChillMainBundle/Form/Type/PickUserDynamicType.php index 2fbfdcf11..9a2c1fbb4 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/PickUserDynamicType.php +++ b/src/Bundle/ChillMainBundle/Form/Type/PickUserDynamicType.php @@ -46,6 +46,7 @@ class PickUserDynamicType extends AbstractType $view->vars['multiple'] = $options['multiple']; $view->vars['types'] = ['user']; $view->vars['uniqid'] = uniqid('pick_user_dyn'); + $view->vars['suggested'] = $this->serializer->serialize($options['suggested'], 'json', ['groups' => 'read']); } public function configureOptions(OptionsResolver $resolver) @@ -53,7 +54,8 @@ class PickUserDynamicType extends AbstractType $resolver ->setDefault('multiple', false) ->setAllowedTypes('multiple', ['bool']) - ->setDefault('compound', false); + ->setDefault('compound', false) + ->setDefault('suggested', null); } public function getBlockPrefix() diff --git a/src/Bundle/ChillPersonBundle/Form/Type/PickPersonDynamicType.php b/src/Bundle/ChillPersonBundle/Form/Type/PickPersonDynamicType.php index b0be9dd27..91e46d193 100644 --- a/src/Bundle/ChillPersonBundle/Form/Type/PickPersonDynamicType.php +++ b/src/Bundle/ChillPersonBundle/Form/Type/PickPersonDynamicType.php @@ -45,6 +45,7 @@ class PickPersonDynamicType extends AbstractType $view->vars['multiple'] = $options['multiple']; $view->vars['types'] = ['person']; $view->vars['uniqid'] = uniqid('pick_user_dyn'); + $view->vars['suggested'] = $this->serializer->serialize($options['suggested'], 'json', ['groups' => 'read']); } public function configureOptions(OptionsResolver $resolver) @@ -52,7 +53,8 @@ class PickPersonDynamicType extends AbstractType $resolver ->setDefault('multiple', false) ->setAllowedTypes('multiple', ['bool']) - ->setDefault('compound', false); + ->setDefault('compound', false) + ->setDefault('suggested', null); } public function getBlockPrefix() diff --git a/src/Bundle/ChillThirdPartyBundle/Form/Type/PickThirdpartyDynamicType.php b/src/Bundle/ChillThirdPartyBundle/Form/Type/PickThirdpartyDynamicType.php index ada4064eb..d813918f7 100644 --- a/src/Bundle/ChillThirdPartyBundle/Form/Type/PickThirdpartyDynamicType.php +++ b/src/Bundle/ChillThirdPartyBundle/Form/Type/PickThirdpartyDynamicType.php @@ -45,6 +45,7 @@ class PickThirdpartyDynamicType extends AbstractType $view->vars['multiple'] = $options['multiple']; $view->vars['types'] = ['thirdparty']; $view->vars['uniqid'] = uniqid('pick_user_dyn'); + $view->vars['suggested'] = $this->serializer->serialize($options['suggested'], 'json', ['groups' => 'read']); } public function configureOptions(OptionsResolver $resolver) @@ -52,7 +53,8 @@ class PickThirdpartyDynamicType extends AbstractType $resolver ->setDefault('multiple', false) ->setAllowedTypes('multiple', ['bool']) - ->setDefault('compound', false); + ->setDefault('compound', false) + ->setDefault('suggested', null); } public function getBlockPrefix() From 9e6579a1769379485f7b0c671298179751067336 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Fri, 24 Feb 2023 17:20:35 +0100 Subject: [PATCH 2/7] [workflow][method] add method to get involved/suggested users --- ...AccompanyingCourseDocumentWorkflowHandler.php | 10 ++++++++++ .../Entity/Workflow/EntityWorkflow.php | 16 ++++++++++++++++ .../Workflow/EntityWorkflowHandlerInterface.php | 5 +++++ ...riodWorkEvaluationDocumentWorkflowHandler.php | 15 +++++++++++++++ ...anyingPeriodWorkEvaluationWorkflowHandler.php | 14 ++++++++++++++ .../AccompanyingPeriodWorkWorkflowHandler.php | 13 +++++++++++++ 6 files changed, 73 insertions(+) diff --git a/src/Bundle/ChillDocStoreBundle/Workflow/AccompanyingCourseDocumentWorkflowHandler.php b/src/Bundle/ChillDocStoreBundle/Workflow/AccompanyingCourseDocumentWorkflowHandler.php index 96787a6fc..ec714aa74 100644 --- a/src/Bundle/ChillDocStoreBundle/Workflow/AccompanyingCourseDocumentWorkflowHandler.php +++ b/src/Bundle/ChillDocStoreBundle/Workflow/AccompanyingCourseDocumentWorkflowHandler.php @@ -95,6 +95,16 @@ class AccompanyingCourseDocumentWorkflowHandler implements EntityWorkflowHandler return null; } + public function getSuggestedUsers(EntityWorkflow $entityWorkflow): array + { + $suggestedUsers = $entityWorkflow->getUsersInvolved(); + + $referrer = $this->getRelatedEntity($entityWorkflow)->getCourse()->getUser(); + $suggestedUsers[$referrer->getId()] = $referrer; + + return $suggestedUsers; + } + public function getTemplate(EntityWorkflow $entityWorkflow, array $options = []): string { return '@ChillDocStore/AccompanyingCourseDocument/_workflow.html.twig'; diff --git a/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php b/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php index c448ea19e..62e6bac0f 100644 --- a/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php +++ b/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php @@ -348,6 +348,22 @@ class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface return $this->transitionningStep; } + /** + * @return User[] + */ + public function getUsersInvolved(): array + { + $usersInvolved = []; + + foreach ($this->steps as $step) { + foreach ($step->getDestUser() as $u) { + $usersInvolved[$u->getId()] = $u; + } + } + + return $usersInvolved; + } + public function getWorkflowName(): string { return $this->workflowName; diff --git a/src/Bundle/ChillMainBundle/Workflow/EntityWorkflowHandlerInterface.php b/src/Bundle/ChillMainBundle/Workflow/EntityWorkflowHandlerInterface.php index 5058fed7c..73e260c37 100644 --- a/src/Bundle/ChillMainBundle/Workflow/EntityWorkflowHandlerInterface.php +++ b/src/Bundle/ChillMainBundle/Workflow/EntityWorkflowHandlerInterface.php @@ -36,6 +36,11 @@ interface EntityWorkflowHandlerInterface */ public function getRoleShow(EntityWorkflow $entityWorkflow): ?string; + /** + * @return User[] + */ + public function getSuggestedUsers(EntityWorkflow $entityWorkflow): array; + public function getTemplate(EntityWorkflow $entityWorkflow, array $options = []): string; public function getTemplateData(EntityWorkflow $entityWorkflow, array $options = []): array; diff --git a/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler.php b/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler.php index 735463fc2..2c78e2099 100644 --- a/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler.php +++ b/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler.php @@ -97,6 +97,21 @@ class AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler implements EntityW return AccompanyingPeriodWorkEvaluationDocumentVoter::SEE; } + public function getSuggestedUsers(EntityWorkflow $entityWorkflow): array + { + $suggestedUsers = $entityWorkflow->getUsersInvolved(); + + $referrer = $this->getRelatedEntity($entityWorkflow) + ->getAccompanyingPeriodWorkEvaluation() + ->getAccompanyingPeriodWork() + ->getAccompanyingPeriod() + ->getUser(); + + $suggestedUsers[$referrer->getId()] = $referrer; + + return $suggestedUsers; + } + public function getTemplate(EntityWorkflow $entityWorkflow, array $options = []): string { return '@ChillPerson/Workflow/_evaluation_document.html.twig'; diff --git a/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationWorkflowHandler.php b/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationWorkflowHandler.php index 25edce03b..a6d9fc9b4 100644 --- a/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationWorkflowHandler.php +++ b/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationWorkflowHandler.php @@ -87,6 +87,20 @@ class AccompanyingPeriodWorkEvaluationWorkflowHandler implements EntityWorkflowH return AccompanyingPeriodWorkEvaluationVoter::SEE; } + public function getSuggestedUsers(EntityWorkflow $entityWorkflow): array + { + $suggestedUsers = $entityWorkflow->getUsersInvolved(); + + $referrer = $this->getRelatedEntity($entityWorkflow) + ->getAccompanyingPeriodWork() + ->getAccompanyingPeriod() + ->getUser(); + + $suggestedUsers[$referrer->getId()] = $referrer; + + return $suggestedUsers; + } + public function getTemplate(EntityWorkflow $entityWorkflow, array $options = []): string { return '@ChillPerson/Workflow/_evaluation.html.twig'; diff --git a/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkWorkflowHandler.php b/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkWorkflowHandler.php index b6829ab77..142a57229 100644 --- a/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkWorkflowHandler.php +++ b/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkWorkflowHandler.php @@ -94,6 +94,19 @@ class AccompanyingPeriodWorkWorkflowHandler implements EntityWorkflowHandlerInte return null; } + public function getSuggestedUsers(EntityWorkflow $entityWorkflow): array + { + $suggestedUsers = $entityWorkflow->getUsersInvolved(); + + $referrer = $this->getRelatedEntity($entityWorkflow) + ->getAccompanyingPeriod() + ->getUser(); + + $suggestedUsers[$referrer->getId()] = $referrer; + + return $suggestedUsers; + } + public function getTemplate(EntityWorkflow $entityWorkflow, array $options = []): string { return '@ChillPerson/Workflow/_accompanying_period_work.html.twig'; From 365df4f3babd1a399e769880998e2c4936e25b4e Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Fri, 24 Feb 2023 17:22:41 +0100 Subject: [PATCH 3/7] [form][controller] pass suggested users on to workflow form --- .../Controller/WorkflowController.php | 16 ++++++++++++++-- .../ChillMainBundle/Form/WorkflowStepType.php | 2 ++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Controller/WorkflowController.php b/src/Bundle/ChillMainBundle/Controller/WorkflowController.php index 17b5db75e..0f00a177f 100644 --- a/src/Bundle/ChillMainBundle/Controller/WorkflowController.php +++ b/src/Bundle/ChillMainBundle/Controller/WorkflowController.php @@ -30,6 +30,7 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Security\Core\Exception\AccessDeniedException; +use Symfony\Component\Security\Core\Security; use Symfony\Component\Validator\Validator\ValidatorInterface; use Symfony\Component\Workflow\Registry; use Symfony\Component\Workflow\TransitionBlocker; @@ -48,11 +49,13 @@ class WorkflowController extends AbstractController private Registry $registry; + private Security $security; + private TranslatorInterface $translator; private ValidatorInterface $validator; - public function __construct(EntityWorkflowManager $entityWorkflowManager, EntityWorkflowRepository $entityWorkflowRepository, ValidatorInterface $validator, PaginatorFactory $paginatorFactory, Registry $registry, EntityManagerInterface $entityManager, TranslatorInterface $translator) + public function __construct(EntityWorkflowManager $entityWorkflowManager, EntityWorkflowRepository $entityWorkflowRepository, ValidatorInterface $validator, PaginatorFactory $paginatorFactory, Registry $registry, EntityManagerInterface $entityManager, TranslatorInterface $translator, Security $security) { $this->entityWorkflowManager = $entityWorkflowManager; $this->entityWorkflowRepository = $entityWorkflowRepository; @@ -61,6 +64,7 @@ class WorkflowController extends AbstractController $this->registry = $registry; $this->entityManager = $entityManager; $this->translator = $translator; + $this->security = $security; } /** @@ -291,10 +295,18 @@ class WorkflowController extends AbstractController if (count($workflow->getEnabledTransitions($entityWorkflow)) > 0) { // possible transition + + $usersInvolved = $entityWorkflow->getUsersInvolved(); + $currentUserFound = array_search($this->security->getUser(), $usersInvolved, true); + + if (false !== $currentUserFound) { + unset($usersInvolved[$currentUserFound]); + } + $transitionForm = $this->createForm( WorkflowStepType::class, $entityWorkflow->getCurrentStep(), - ['transition' => true, 'entity_workflow' => $entityWorkflow] + ['transition' => true, 'entity_workflow' => $entityWorkflow, 'suggested_users' => $usersInvolved] ); $transitionForm->handleRequest($request); diff --git a/src/Bundle/ChillMainBundle/Form/WorkflowStepType.php b/src/Bundle/ChillMainBundle/Form/WorkflowStepType.php index e01c7d4b6..23f932844 100644 --- a/src/Bundle/ChillMainBundle/Form/WorkflowStepType.php +++ b/src/Bundle/ChillMainBundle/Form/WorkflowStepType.php @@ -154,6 +154,7 @@ class WorkflowStepType extends AbstractType 'label' => 'workflow.dest for next steps', 'multiple' => true, 'mapped' => false, + 'suggested' => $options['suggested_users'], ]) ->add('future_dest_emails', ChillCollectionType::class, [ 'label' => 'workflow.dest by email', @@ -200,6 +201,7 @@ class WorkflowStepType extends AbstractType ->setAllowedTypes('transition', 'bool') ->setRequired('entity_workflow') ->setAllowedTypes('entity_workflow', EntityWorkflow::class) + ->setDefault('suggested_users', []) ->setDefault('constraints', [ new Callback( function ($step, ExecutionContextInterface $context, $payload) { From 73af63a2b589e3826538252ad50ab76e49617597 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Fri, 24 Feb 2023 17:24:42 +0100 Subject: [PATCH 4/7] [data][twig] pass suggested users to vue component through twig template data attribute --- .../ChillMainBundle/Resources/views/Form/fields.html.twig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Resources/views/Form/fields.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Form/fields.html.twig index 15d7625dd..2a9015746 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Form/fields.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Form/fields.html.twig @@ -249,7 +249,7 @@ {% block pick_entity_dynamic_widget %} -
+
{% endblock %} {% block pick_postal_code_widget %} @@ -269,4 +269,4 @@ {{ form_errors(form.fixedDate) }} -{% endblock %} \ No newline at end of file +{% endblock %} From c5fc6d4aadaaa7570ee33e3ca2f2928c38a36cb8 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Fri, 24 Feb 2023 17:25:28 +0100 Subject: [PATCH 5/7] [vue][suggested users] add suggested users in vue component and write create/remove logic --- .../public/module/pick-entity/index.js | 5 + .../public/vuejs/PickEntity/PickEntity.vue | 105 ++++++++++-------- 2 files changed, 64 insertions(+), 46 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Resources/public/module/pick-entity/index.js b/src/Bundle/ChillMainBundle/Resources/public/module/pick-entity/index.js index 890929c35..bb9cc744c 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/module/pick-entity/index.js +++ b/src/Bundle/ChillMainBundle/Resources/public/module/pick-entity/index.js @@ -23,8 +23,11 @@ function loadDynamicPicker(element) { (input.value === '[]' || input.value === '') ? null : [ JSON.parse(input.value) ] ) + suggested = null !== JSON.parse(el.dataset.suggested) ? JSON.parse(el.dataset.suggested) : null ; + console.log('suggested', suggested) + if (!isMultiple) { if (input.value === '[]'){ input.value = null; @@ -37,6 +40,7 @@ function loadDynamicPicker(element) { ':types="types" ' + ':picked="picked" ' + ':uniqid="uniqid" ' + + ':suggested="suggested" ' + '@addNewEntity="addNewEntity" ' + '@removeEntity="removeEntity">', components: { @@ -48,6 +52,7 @@ function loadDynamicPicker(element) { types: JSON.parse(el.dataset.types), picked: picked === null ? [] : picked, uniqid: el.dataset.uniqid, + suggested: suggested } }, methods: { diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/PickEntity/PickEntity.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/PickEntity/PickEntity.vue index e121ca950..02b53a6d3 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/PickEntity/PickEntity.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/PickEntity/PickEntity.vue @@ -17,6 +17,9 @@ +
    +
  • {{ s.text }}
  • +
From 4df6a6fc85f517c2955228d02300e33fecdc8815 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Fri, 10 Mar 2023 12:56:05 +0100 Subject: [PATCH 6/7] FIX [review] processing review, but stuck at transformation of json string to array --- .../AccompanyingCourseDocumentWorkflowHandler.php | 2 +- .../ChillMainBundle/Entity/Workflow/EntityWorkflow.php | 2 +- .../ChillMainBundle/Form/Type/PickUserDynamicType.php | 2 +- .../Resources/public/module/pick-entity/index.js | 8 +++++--- .../Resources/public/vuejs/PickEntity/PickEntity.vue | 5 +++-- .../ChillPersonBundle/Form/Type/PickPersonDynamicType.php | 2 +- ...panyingPeriodWorkEvaluationDocumentWorkflowHandler.php | 2 +- .../AccompanyingPeriodWorkEvaluationWorkflowHandler.php | 2 +- .../Workflow/AccompanyingPeriodWorkWorkflowHandler.php | 2 +- .../Form/Type/PickThirdpartyDynamicType.php | 2 +- 10 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/Bundle/ChillDocStoreBundle/Workflow/AccompanyingCourseDocumentWorkflowHandler.php b/src/Bundle/ChillDocStoreBundle/Workflow/AccompanyingCourseDocumentWorkflowHandler.php index ec714aa74..c538bd107 100644 --- a/src/Bundle/ChillDocStoreBundle/Workflow/AccompanyingCourseDocumentWorkflowHandler.php +++ b/src/Bundle/ChillDocStoreBundle/Workflow/AccompanyingCourseDocumentWorkflowHandler.php @@ -100,7 +100,7 @@ class AccompanyingCourseDocumentWorkflowHandler implements EntityWorkflowHandler $suggestedUsers = $entityWorkflow->getUsersInvolved(); $referrer = $this->getRelatedEntity($entityWorkflow)->getCourse()->getUser(); - $suggestedUsers[$referrer->getId()] = $referrer; + $suggestedUsers[spl_object_hash($referrer)] = $referrer; return $suggestedUsers; } diff --git a/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php b/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php index 62e6bac0f..99aba07fd 100644 --- a/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php +++ b/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php @@ -357,7 +357,7 @@ class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface foreach ($this->steps as $step) { foreach ($step->getDestUser() as $u) { - $usersInvolved[$u->getId()] = $u; + $usersInvolved[spl_object_hash($u)] = $u; } } diff --git a/src/Bundle/ChillMainBundle/Form/Type/PickUserDynamicType.php b/src/Bundle/ChillMainBundle/Form/Type/PickUserDynamicType.php index 9a2c1fbb4..6bfd95fe8 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/PickUserDynamicType.php +++ b/src/Bundle/ChillMainBundle/Form/Type/PickUserDynamicType.php @@ -55,7 +55,7 @@ class PickUserDynamicType extends AbstractType ->setDefault('multiple', false) ->setAllowedTypes('multiple', ['bool']) ->setDefault('compound', false) - ->setDefault('suggested', null); + ->setDefault('suggested', []); } public function getBlockPrefix() diff --git a/src/Bundle/ChillMainBundle/Resources/public/module/pick-entity/index.js b/src/Bundle/ChillMainBundle/Resources/public/module/pick-entity/index.js index bb9cc744c..41330c186 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/module/pick-entity/index.js +++ b/src/Bundle/ChillMainBundle/Resources/public/module/pick-entity/index.js @@ -23,10 +23,12 @@ function loadDynamicPicker(element) { (input.value === '[]' || input.value === '') ? null : [ JSON.parse(input.value) ] ) - suggested = null !== JSON.parse(el.dataset.suggested) ? JSON.parse(el.dataset.suggested) : null - ; + suggested = JSON.parse('[' + el.dataset.suggested + ']'); + // suggested = suggested[0]; - console.log('suggested', suggested) + console.log(typeof suggested) + // console.log(el.dataset.suggested) + console.log('suggested', typeof suggested[0]) if (!isMultiple) { if (input.value === '[]'){ diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/PickEntity/PickEntity.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/PickEntity/PickEntity.vue index 02b53a6d3..23a904b14 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/PickEntity/PickEntity.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/PickEntity/PickEntity.vue @@ -17,7 +17,8 @@ -
    +
      +

      hello {{ Object.keys(suggested) }}

    • {{ s.text }}
    @@ -55,7 +56,7 @@ export default { }, suggested: { type: Array, - default: null + default: [] } }, emits: ['addNewEntity', 'removeEntity'], diff --git a/src/Bundle/ChillPersonBundle/Form/Type/PickPersonDynamicType.php b/src/Bundle/ChillPersonBundle/Form/Type/PickPersonDynamicType.php index 91e46d193..c0955b3ad 100644 --- a/src/Bundle/ChillPersonBundle/Form/Type/PickPersonDynamicType.php +++ b/src/Bundle/ChillPersonBundle/Form/Type/PickPersonDynamicType.php @@ -54,7 +54,7 @@ class PickPersonDynamicType extends AbstractType ->setDefault('multiple', false) ->setAllowedTypes('multiple', ['bool']) ->setDefault('compound', false) - ->setDefault('suggested', null); + ->setDefault('suggested', []); } public function getBlockPrefix() diff --git a/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler.php b/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler.php index 2c78e2099..500daab6f 100644 --- a/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler.php +++ b/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler.php @@ -107,7 +107,7 @@ class AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler implements EntityW ->getAccompanyingPeriod() ->getUser(); - $suggestedUsers[$referrer->getId()] = $referrer; + $suggestedUsers[spl_object_hash($referrer)] = $referrer; return $suggestedUsers; } diff --git a/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationWorkflowHandler.php b/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationWorkflowHandler.php index a6d9fc9b4..db67ef045 100644 --- a/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationWorkflowHandler.php +++ b/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationWorkflowHandler.php @@ -96,7 +96,7 @@ class AccompanyingPeriodWorkEvaluationWorkflowHandler implements EntityWorkflowH ->getAccompanyingPeriod() ->getUser(); - $suggestedUsers[$referrer->getId()] = $referrer; + $suggestedUsers[spl_object_hash($referrer)] = $referrer; return $suggestedUsers; } diff --git a/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkWorkflowHandler.php b/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkWorkflowHandler.php index 142a57229..75ad04cfb 100644 --- a/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkWorkflowHandler.php +++ b/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkWorkflowHandler.php @@ -102,7 +102,7 @@ class AccompanyingPeriodWorkWorkflowHandler implements EntityWorkflowHandlerInte ->getAccompanyingPeriod() ->getUser(); - $suggestedUsers[$referrer->getId()] = $referrer; + $suggestedUsers[spl_object_hash($referrer)] = $referrer; return $suggestedUsers; } diff --git a/src/Bundle/ChillThirdPartyBundle/Form/Type/PickThirdpartyDynamicType.php b/src/Bundle/ChillThirdPartyBundle/Form/Type/PickThirdpartyDynamicType.php index d813918f7..2e282a31b 100644 --- a/src/Bundle/ChillThirdPartyBundle/Form/Type/PickThirdpartyDynamicType.php +++ b/src/Bundle/ChillThirdPartyBundle/Form/Type/PickThirdpartyDynamicType.php @@ -54,7 +54,7 @@ class PickThirdpartyDynamicType extends AbstractType ->setDefault('multiple', false) ->setAllowedTypes('multiple', ['bool']) ->setDefault('compound', false) - ->setDefault('suggested', null); + ->setDefault('suggested', []); } public function getBlockPrefix() From 3821bc3a70d7e51b92a6bec66d1b699b9874ebf4 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 15 Mar 2023 09:37:28 +0100 Subject: [PATCH 7/7] FIX [review] implement changes based on review --- .../Form/Type/PickUserDynamicType.php | 11 +++++++++-- .../public/module/pick-entity/index.js | 19 +++++++++++-------- .../public/vuejs/PickEntity/PickEntity.vue | 14 +++++--------- .../Resources/views/Form/fields.html.twig | 6 +++++- .../Form/Type/PickPersonDynamicType.php | 13 ++++++++++--- .../Form/Type/PickThirdpartyDynamicType.php | 11 +++++++++-- 6 files changed, 49 insertions(+), 25 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Form/Type/PickUserDynamicType.php b/src/Bundle/ChillMainBundle/Form/Type/PickUserDynamicType.php index 6bfd95fe8..de54d071a 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/PickUserDynamicType.php +++ b/src/Bundle/ChillMainBundle/Form/Type/PickUserDynamicType.php @@ -19,6 +19,7 @@ use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormView; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; +use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Serializer\SerializerInterface; /** @@ -28,12 +29,15 @@ class PickUserDynamicType extends AbstractType { private DenormalizerInterface $denormalizer; + private NormalizerInterface $normalizer; + private SerializerInterface $serializer; - public function __construct(DenormalizerInterface $denormalizer, SerializerInterface $serializer) + public function __construct(DenormalizerInterface $denormalizer, SerializerInterface $serializer, NormalizerInterface $normalizer) { $this->denormalizer = $denormalizer; $this->serializer = $serializer; + $this->normalizer = $normalizer; } public function buildForm(FormBuilderInterface $builder, array $options) @@ -46,7 +50,10 @@ class PickUserDynamicType extends AbstractType $view->vars['multiple'] = $options['multiple']; $view->vars['types'] = ['user']; $view->vars['uniqid'] = uniqid('pick_user_dyn'); - $view->vars['suggested'] = $this->serializer->serialize($options['suggested'], 'json', ['groups' => 'read']); + + foreach ($options['suggested'] as $user) { + $view->vars['suggested'][spl_object_hash($user)] = $this->normalizer->normalize($user, 'json', ['groups' => 'read']); + } } public function configureOptions(OptionsResolver $resolver) diff --git a/src/Bundle/ChillMainBundle/Resources/public/module/pick-entity/index.js b/src/Bundle/ChillMainBundle/Resources/public/module/pick-entity/index.js index 41330c186..ce9c66145 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/module/pick-entity/index.js +++ b/src/Bundle/ChillMainBundle/Resources/public/module/pick-entity/index.js @@ -23,12 +23,7 @@ function loadDynamicPicker(element) { (input.value === '[]' || input.value === '') ? null : [ JSON.parse(input.value) ] ) - suggested = JSON.parse('[' + el.dataset.suggested + ']'); - // suggested = suggested[0]; - - console.log(typeof suggested) - // console.log(el.dataset.suggested) - console.log('suggested', typeof suggested[0]) + suggested = JSON.parse(el.dataset.suggested); if (!isMultiple) { if (input.value === '[]'){ @@ -58,13 +53,18 @@ function loadDynamicPicker(element) { } }, methods: { - addNewEntity(entity) { + addNewEntity({entity, isSuggested = false}) { if (this.multiple) { if (!this.picked.some(el => { return el.type === entity.type && el.id === entity.id; })) { this.picked.push(entity); input.value = JSON.stringify(this.picked); + console.log(entity) + if (isSuggested) { + const indexToRemove = this.suggested.findIndex(e => e.id === entity.id) + this.suggested.splice(indexToRemove, 1); + } } } else { if (!this.picked.some(el => { @@ -76,9 +76,12 @@ function loadDynamicPicker(element) { } } }, - removeEntity(entity) { + removeEntity({entity, isSuggested = false}) { this.picked = this.picked.filter(e => !(e.type === entity.type && e.id === entity.id)); input.value = JSON.stringify(this.picked); + if (isSuggested) { + this.suggested.push(entity); + } }, } }) diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/PickEntity/PickEntity.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/PickEntity/PickEntity.vue index 23a904b14..7d6d0bd83 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/PickEntity/PickEntity.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/PickEntity/PickEntity.vue @@ -17,8 +17,7 @@
-
    -

    hello {{ Object.keys(suggested) }}

    +
    • {{ s.text }}
    @@ -105,14 +104,12 @@ export default { }, methods: { addNewSuggested(entity) { - this.$emit('addNewEntity', entity); - const indexToRemove = this.suggested.findIndex(e => e.id === entity.id) - this.suggested.splice(indexToRemove, 1); + this.$emit('addNewEntity', {entity: entity, isSuggested: true}); }, addNewEntity({ selected, modal }) { selected.forEach((item) => { - this.$emit('addNewEntity', item.result); - }, this + this.$emit('addNewEntity', { entity: item.result }); + }, this ); this.$refs.addPersons.resetSearch(); // to cast child method modal.showModal = false; @@ -121,8 +118,7 @@ export default { if (!this.$props.removableIfSet) { return; } - this.$emit('removeEntity', entity); - this.suggested.push(entity); + this.$emit('removeEntity',{ entity: entity, isSuggested: true }); } }, } diff --git a/src/Bundle/ChillMainBundle/Resources/views/Form/fields.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Form/fields.html.twig index 2a9015746..96c194a76 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Form/fields.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Form/fields.html.twig @@ -249,7 +249,11 @@ {% block pick_entity_dynamic_widget %} -
    +
    {% endblock %} {% block pick_postal_code_widget %} diff --git a/src/Bundle/ChillPersonBundle/Form/Type/PickPersonDynamicType.php b/src/Bundle/ChillPersonBundle/Form/Type/PickPersonDynamicType.php index c0955b3ad..3a875f8aa 100644 --- a/src/Bundle/ChillPersonBundle/Form/Type/PickPersonDynamicType.php +++ b/src/Bundle/ChillPersonBundle/Form/Type/PickPersonDynamicType.php @@ -18,21 +18,25 @@ use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormView; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; +use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Serializer\SerializerInterface; /** - * Pick user dymically, using vuejs module "AddPerson". + * m* Pick user dymically, using vuejs module "AddPerson". */ class PickPersonDynamicType extends AbstractType { private DenormalizerInterface $denormalizer; + private DenormalizerInterface $normalizer; + private SerializerInterface $serializer; - public function __construct(DenormalizerInterface $denormalizer, SerializerInterface $serializer) + public function __construct(DenormalizerInterface $denormalizer, SerializerInterface $serializer, NormalizerInterface $normalizer) { $this->denormalizer = $denormalizer; $this->serializer = $serializer; + $this->normalizer = $normalizer; } public function buildForm(FormBuilderInterface $builder, array $options) @@ -45,7 +49,10 @@ class PickPersonDynamicType extends AbstractType $view->vars['multiple'] = $options['multiple']; $view->vars['types'] = ['person']; $view->vars['uniqid'] = uniqid('pick_user_dyn'); - $view->vars['suggested'] = $this->serializer->serialize($options['suggested'], 'json', ['groups' => 'read']); + + foreach ($options['suggested'] as $person) { + $view->vars['suggested'][spl_object_hash($person)] = $this->normalizer->normalize($person, 'json', ['groups' => 'read']); + } } public function configureOptions(OptionsResolver $resolver) diff --git a/src/Bundle/ChillThirdPartyBundle/Form/Type/PickThirdpartyDynamicType.php b/src/Bundle/ChillThirdPartyBundle/Form/Type/PickThirdpartyDynamicType.php index 2e282a31b..7d5625ec6 100644 --- a/src/Bundle/ChillThirdPartyBundle/Form/Type/PickThirdpartyDynamicType.php +++ b/src/Bundle/ChillThirdPartyBundle/Form/Type/PickThirdpartyDynamicType.php @@ -18,6 +18,7 @@ use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormView; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; +use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Serializer\SerializerInterface; /** @@ -27,12 +28,15 @@ class PickThirdpartyDynamicType extends AbstractType { private DenormalizerInterface $denormalizer; + private NormalizerInterface $normalizer; + private SerializerInterface $serializer; - public function __construct(DenormalizerInterface $denormalizer, SerializerInterface $serializer) + public function __construct(DenormalizerInterface $denormalizer, SerializerInterface $serializer, NormalizerInterface $normalizer) { $this->denormalizer = $denormalizer; $this->serializer = $serializer; + $this->normalizer = $normalizer; } public function buildForm(FormBuilderInterface $builder, array $options) @@ -45,7 +49,10 @@ class PickThirdpartyDynamicType extends AbstractType $view->vars['multiple'] = $options['multiple']; $view->vars['types'] = ['thirdparty']; $view->vars['uniqid'] = uniqid('pick_user_dyn'); - $view->vars['suggested'] = $this->serializer->serialize($options['suggested'], 'json', ['groups' => 'read']); + + foreach ($options['suggested'] as $tp) { + $view->vars['suggested'][spl_object_hash($tp)] = $this->normalizer->normalize($tp, 'json', ['groups' => 'read']); + } } public function configureOptions(OptionsResolver $resolver)