From beca41774edb0b1c99aa211934da2743baf04b13 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Tue, 29 Jun 2021 11:49:23 +0200 Subject: [PATCH 1/3] vue activity: fix duplicates and add condition in initial loading --- .../ChillActivityBundle/Entity/Activity.php | 9 ++--- .../Activity/components/SocialIssuesAcc.vue | 39 ++++++++++++------- .../Resources/public/vuejs/Activity/store.js | 31 +++++++-------- 3 files changed, 42 insertions(+), 37 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Entity/Activity.php b/src/Bundle/ChillActivityBundle/Entity/Activity.php index eb1a8386e..c212471be 100644 --- a/src/Bundle/ChillActivityBundle/Entity/Activity.php +++ b/src/Bundle/ChillActivityBundle/Entity/Activity.php @@ -108,15 +108,14 @@ class Activity implements HasCenterInterface, HasScopeInterface * @ORM\JoinTable(name="chill_activity_activity_chill_person_socialissue") * @Groups({"read"}) */ - private $socialIssues; + private ?Collection $socialIssues = null; /** * @ORM\ManyToMany(targetEntity="Chill\PersonBundle\Entity\SocialWork\SocialAction") * @ORM\JoinTable(name="chill_activity_activity_chill_person_socialaction") * @Groups({"read"}) */ - private $socialActions; - + private ?Collection $socialActions = null; /** * @ORM\ManyToOne(targetEntity="Chill\ActivityBundle\Entity\ActivityType") @@ -283,7 +282,7 @@ class Activity implements HasCenterInterface, HasScopeInterface return $this->socialIssues; } - public function addSocialIssue(SocialIssue $socialIssue): self + public function addSocialIssue(?SocialIssue $socialIssue): self { if (!$this->socialIssues->contains($socialIssue)) { $this->socialIssues[] = $socialIssue; @@ -307,7 +306,7 @@ class Activity implements HasCenterInterface, HasScopeInterface return $this->socialActions; } - public function addSocialAction(SocialAction $socialAction): self + public function addSocialAction(?SocialAction $socialAction): self { if (!$this->socialActions->contains($socialAction)) { $this->socialActions[] = $socialAction; diff --git a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/SocialIssuesAcc.vue b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/SocialIssuesAcc.vue index 4ac1b1957..779c9cff8 100644 --- a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/SocialIssuesAcc.vue +++ b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/SocialIssuesAcc.vue @@ -120,24 +120,30 @@ export default { getSocialIssues().then(response => new Promise((resolve, reject) => { this.$store.commit('updateIssuesOther', response.results); + // ajoute dans la liste les issues déjà associées (si elles ne s'y trouvent pas déjà) this.socialIssuesSelected.forEach(issue => { - this.$store.commit('addIssueInList', issue); + if (this.socialIssuesList.filter(i => i.id === issue.id).length !== 1) { + this.$store.commit('addIssueInList', issue); + } }, this); - console.log(this.socialIssuesOther.length, this.socialIssuesOther); + // enlève du multiselect les issues qui sont dans la liste des checkbox this.socialIssuesList.forEach(issue => { this.$store.commit('removeIssueInOther', issue); }, this); - console.log(this.socialIssuesOther.length); // grr !!! - // TODO décompter les issues initiales du multiselect + // filtre les issues this.$store.commit('filterList', 'issues'); + // ajoute dans la liste les actions déjà associées (si elles ne s'y trouvent pas déjà) this.socialActionsSelected.forEach(action => { this.$store.commit('addActionInList', action); }, this); + + // filtre les actions this.$store.commit('filterList', 'actions'); + this.issueIsLoading = false; resolve(); })); @@ -175,22 +181,25 @@ export default { this.$store.commit('resetActionsList'); + // remettre les ActionsSelected dans ActionsList + this.socialIssuesSelected.forEach(item => { - console.log('for issue', item.id); + //console.log('for issue', item.id); this.actionIsLoading = true; getSocialActionByIssue(item.id) - .then(actions => new Promise((resolve, reject) => { - - actions.results.forEach(action => { - this.$store.commit('addActionInList', action); - }, this); - - this.$store.commit('filterList', 'actions'); - - this.actionIsLoading = false; - resolve(); + .then(actions => new Promise((resolve, reject) => { + + actions.results.forEach(action => { + this.$store.commit('addActionInList', action); + }, this); + + this.$store.commit('filterList', 'actions'); + + this.actionIsLoading = false; + resolve(); })); + }, this); } } diff --git a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/store.js b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/store.js index 9684ab375..c87573797 100644 --- a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/store.js +++ b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/store.js @@ -29,47 +29,44 @@ const store = createStore({ // SocialIssueAcc addIssueInList(state, issue) { - console.log('add list issue', issue.id); + //console.log('add issue list', issue.id); state.activity.accompanyingPeriod.socialIssues.push(issue); }, addIssueSelected(state, issue) { - console.log('add selected issue', issue.id); + //console.log('add issue selected', issue.id); state.activity.socialIssues.push(issue); }, updateIssuesSelected(state, issues) { - console.log('update selected issues', issues); + //console.log('update issues selected', issues); state.activity.socialIssues = issues; }, updateIssuesOther(state, payload) { - console.log('update other issues'); + //console.log('update issues other'); state.socialIssuesOther = payload; }, removeIssueInOther(state, issue) { - console.log('remove other issue', issue.id); - state.socialIssuesOther = state.socialIssuesOther.filter(item => item !== issue); + //console.log('remove issue other', issue.id); + state.socialIssuesOther = state.socialIssuesOther.filter(i => i.id !== issue.id); }, resetActionsList(state) { - console.log('reset actions list'); + //console.log('reset list actions'); state.socialActionsList = []; }, addActionInList(state, action) { - console.log('add list action', action.id); + //console.log('add action list', action.id); state.socialActionsList.push(action); }, updateActionsSelected(state, actions) { - console.log('update selected actions', actions); + //console.log('update actions selected', actions); state.activity.socialActions = actions; }, filterList(state, list) { const filterList = (list) => { - console.log('filter ' + list.length + ' items: uniq'); // grr !!! - // TODO un filtrage qui enlève les doublons - //list = list.filter((v, i, a) => a.indexOf(v) === i); - let _list = [...new Set(list)]; - - console.log('filter ' + list.length + ' items: sort', list); - _list.sort((a,b) => (a.text > b.text) ? 1 : ((b.text > a.text) ? -1 : 0)); - return _list; + // remove duplicates entries + list = list.filter((value, index) => list.findIndex(array => array.id === value.id) === index); + // alpha sort + list.sort((a,b) => (a.text > b.text) ? 1 : ((b.text > a.text) ? -1 : 0)); + return list; }; if (list === 'issues') { state.activity.accompanyingPeriod.socialIssues = filterList(state.activity.accompanyingPeriod.socialIssues); From 2a974e1269ad92427021c491aae09a0853d76846 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Tue, 29 Jun 2021 12:23:11 +0200 Subject: [PATCH 2/3] fix socialActions selected visibility if all issues unchecked + cleaning --- .../Activity/components/SocialIssuesAcc.vue | 53 ++++++++++--------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/SocialIssuesAcc.vue b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/SocialIssuesAcc.vue index 779c9cff8..4e1761814 100644 --- a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/SocialIssuesAcc.vue +++ b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/SocialIssuesAcc.vue @@ -35,11 +35,6 @@ v-bind:options="socialIssuesOther" v-model="value" @select="addIssueInList"> - - - @@ -57,7 +52,7 @@ new Promise((resolve, reject) => { this.$store.commit('updateIssuesOther', response.results); - // ajoute dans la liste les issues déjà associées (si elles ne s'y trouvent pas déjà) + /* Add in list the issues already associated (if not yet listed) + */ this.socialIssuesSelected.forEach(issue => { if (this.socialIssuesList.filter(i => i.id === issue.id).length !== 1) { this.$store.commit('addIssueInList', issue); } }, this); - // enlève du multiselect les issues qui sont dans la liste des checkbox + /* Remove from multiselect the issues that are not yet in checkbox list + */ this.socialIssuesList.forEach(issue => { this.$store.commit('removeIssueInOther', issue); }, this); - // filtre les issues + /* Filter issues + */ this.$store.commit('filterList', 'issues'); - // ajoute dans la liste les actions déjà associées (si elles ne s'y trouvent pas déjà) + /* Add in list the actions already associated (if not yet listed) + */ this.socialActionsSelected.forEach(action => { this.$store.commit('addActionInList', action); }, this); - // filtre les actions + /* Filter issues + */ this.$store.commit('filterList', 'actions'); - this.issueIsLoading = false; resolve(); })); @@ -154,7 +153,7 @@ export default { remove it from multiselect, and add socialActions concerned */ addIssueInList(value) { - console.log('addIssueInList', value); + //console.log('addIssueInList', value); this.$store.commit('addIssueInList', value); this.$store.commit('removeIssueInOther', value); this.$store.dispatch('addIssueSelected', value); @@ -163,28 +162,23 @@ export default { /* Update value for selected issues checkboxes */ updateIssuesSelected(issues) { - console.log('updateIssuesSelected', issues); + //console.log('updateIssuesSelected', issues); this.$store.dispatch('updateIssuesSelected', issues); this.updateActionsList(); }, /* Update value for selected actions checkboxes */ updateActionsSelected(actions) { - console.log('updateActionsSelected', actions); + //console.log('updateActionsSelected', actions); this.$store.dispatch('updateActionsSelected', actions); }, - /* Add socialActions concerned: reset actions list, then loop on each issue selected + /* Add socialActions concerned: after reset, loop on each issue selected to get social actions concerned */ updateActionsList() { - console.log('updateActionsList'); - - this.$store.commit('resetActionsList'); - - // remettre les ActionsSelected dans ActionsList - + //console.log('updateActionsList'); + this.resetActionsList(); this.socialIssuesSelected.forEach(item => { - //console.log('for issue', item.id); this.actionIsLoading = true; getSocialActionByIssue(item.id) @@ -199,7 +193,14 @@ export default { this.actionIsLoading = false; resolve(); })); - + }, this); + }, + /* Reset socialActions List: flush list and restore selected actions + */ + resetActionsList() { + this.$store.commit('resetActionsList'); + this.socialActionsSelected.forEach(item => { + this.$store.commit('addActionInList', item); }, this); } } From 9d9be7f831b5fd57816d54aad2d657b47a2fbd32 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Tue, 29 Jun 2021 14:31:56 +0200 Subject: [PATCH 3/3] vue activity: fix backend when hidden return empty string --- src/Bundle/ChillActivityBundle/Entity/Activity.php | 7 ++----- src/Bundle/ChillActivityBundle/Form/ActivityType.php | 10 ++++++++-- .../vuejs/Activity/components/SocialIssuesAcc.vue | 1 - 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Entity/Activity.php b/src/Bundle/ChillActivityBundle/Entity/Activity.php index c212471be..fbd10e723 100644 --- a/src/Bundle/ChillActivityBundle/Entity/Activity.php +++ b/src/Bundle/ChillActivityBundle/Entity/Activity.php @@ -108,14 +108,14 @@ class Activity implements HasCenterInterface, HasScopeInterface * @ORM\JoinTable(name="chill_activity_activity_chill_person_socialissue") * @Groups({"read"}) */ - private ?Collection $socialIssues = null; + private Collection $socialIssues; /** * @ORM\ManyToMany(targetEntity="Chill\PersonBundle\Entity\SocialWork\SocialAction") * @ORM\JoinTable(name="chill_activity_activity_chill_person_socialaction") * @Groups({"read"}) */ - private ?Collection $socialActions = null; + private Collection $socialActions; /** * @ORM\ManyToOne(targetEntity="Chill\ActivityBundle\Entity\ActivityType") @@ -298,9 +298,6 @@ class Activity implements HasCenterInterface, HasScopeInterface return $this; } - /** - * @return Collection|SocialAction[] - */ public function getSocialActions(): Collection { return $this->socialActions; diff --git a/src/Bundle/ChillActivityBundle/Form/ActivityType.php b/src/Bundle/ChillActivityBundle/Form/ActivityType.php index 80d0991e7..3ad204f18 100644 --- a/src/Bundle/ChillActivityBundle/Form/ActivityType.php +++ b/src/Bundle/ChillActivityBundle/Form/ActivityType.php @@ -123,13 +123,16 @@ class ActivityType extends AbstractType return implode(',', $socialIssueIds); }, function (?string $socialIssuesAsString): array { + if (null === $socialIssuesAsString) { + return []; + } return array_map( fn(string $id): ?SocialIssue => $this->om->getRepository(SocialIssue::class)->findOneBy(['id' => (int) $id]), explode(',', $socialIssuesAsString) ); } )) - ; + ; } if ($activityType->isVisible('socialActions') && $accompanyingPeriod) { @@ -144,13 +147,16 @@ class ActivityType extends AbstractType return implode(',', $socialActionIds); }, function (?string $socialActionsAsString): array { + if (null === $socialActionsAsString) { + return []; + } return array_map( fn(string $id): ?SocialAction => $this->om->getRepository(SocialAction::class)->findOneBy(['id' => (int) $id]), explode(',', $socialActionsAsString) ); } )) - ; + ; } if ($activityType->isVisible('date')) { diff --git a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/SocialIssuesAcc.vue b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/SocialIssuesAcc.vue index 4e1761814..154209cbf 100644 --- a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/SocialIssuesAcc.vue +++ b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/SocialIssuesAcc.vue @@ -64,7 +64,6 @@ {{ $t('activity.select_first_a_social_issue') }} -