From 154fa4719d7a3bbcb9428da4f09d706e841b272f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 23 Jun 2021 17:46:51 +0200 Subject: [PATCH 1/5] add involved persons to accompanying period work --- .../AccompanyingPeriodWork.php | 33 +++++++++++++++++ .../AccompanyingCourseWorkCreate/App.vue | 37 ++++++++++++++++++- .../AccompanyingCourseWorkCreate/store.js | 33 ++++++++++++++--- .../migrations/Version20210623135043.php | 34 +++++++++++++++++ 4 files changed, 131 insertions(+), 6 deletions(-) create mode 100644 src/Bundle/ChillPersonBundle/migrations/Version20210623135043.php diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php index b42242a5b..5fd01acf3 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php @@ -4,6 +4,7 @@ namespace Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\SocialWork\Result; use Chill\PersonBundle\Entity\SocialWork\SocialAction; +use Chill\PersonBundle\Entity\Person; use Chill\MainBundle\Entity\User; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\ThirdPartyBundle\Entity\ThirdParty; @@ -148,11 +149,22 @@ use Symfony\Component\Validator\Constraints as Assert; */ private Collection $thirdParties; + /** + * + * @ORM\ManyToMany(targetEntity=Person::class) + * @ORM\JoinTable(name="chill_person_accompanying_period_work_person") + * @Serializer\Groups({"read"}) + * @Serializer\Groups({"accompanying_period_work:edit"}) + * @Serializer\Groups({"accompanying_period_work:create"}) + */ + private Collection $persons; + public function __construct() { $this->goals = new ArrayCollection(); $this->results = new ArrayCollection(); $this->thirdParties = new ArrayCollection(); + $this->persons = new ArrayCollection(); } public function getId(): ?int @@ -390,4 +402,25 @@ use Symfony\Component\Validator\Constraints as Assert; return $this; } + + public function getPersons(): Collection + { + return $this->persons; + } + + public function addPerson(Person $person): self + { + if (!$this->persons->contains($person)) { + $this->persons[] = $person; + } + + return $this; + } + + public function removePerson(Person $person): self + { + $this->persons->removeElement($person); + + return $this; + } } diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkCreate/App.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkCreate/App.vue index 7e8f2d5f0..96edce825 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkCreate/App.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkCreate/App.vue @@ -28,8 +28,19 @@

spinner

- +
+

{{ $t('persons_involved') }}

+ + +
+ +

@@ -85,6 +96,14 @@ #picking { grid-area: picking; + + #persons { + ul { + padding: 0; + + list-style-type: none; + } + } } #start_date { @@ -105,6 +124,7 @@ import { mapState, mapActions, mapGetters } from 'vuex'; import VueMultiselect from 'vue-multiselect'; import { dateToISO, ISOToDate } from 'ChillMainAssets/js/date.js'; +import Person from 'ChillPersonAssets/vuejs/_components/Person/Person.vue'; const i18n = { messages: { @@ -115,6 +135,7 @@ const i18n = { pick_social_issue: "Choisir une problématique sociale", pick_an_action: "Choisir une action d'accompagnement", pick_social_issue_linked_with_action: "Indiquez la problématique sociale liée à l'action d'accompagnement", + persons_involved: "Usagers concernés", } } @@ -124,6 +145,7 @@ export default { name: 'App', components: { VueMultiselect, + Person, }, methods: { submit() { @@ -136,6 +158,7 @@ export default { 'socialIssues', 'socialActionsReachables', 'errors', + 'personsReachables', ]), ...mapGetters([ 'hasSocialIssuePicked', @@ -144,6 +167,18 @@ export default { 'isPostingWork', 'hasErrors', ]), + personsPicked: { + get() { + let s = this.$store.state.personsPicked.map(p => p.id); + console.log('persons picked', s); + + return s; + }, + set(v) { + console.log('persons picked', v); + this.$store.commit('setPersonsPickedIds', v); + } + }, socialIssuePicked: { get() { let s = this.$store.state.socialIssuePicked; diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkCreate/store.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkCreate/store.js index 8f0aed245..5efe3a6e9 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkCreate/store.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkCreate/store.js @@ -14,6 +14,10 @@ const store = createStore({ socialIssuePicked: null, socialActionsReachables: [], socialActionPicked: null, + personsPicked: window.accompanyingCourse.participations.filter(p => p.endDate == null) + .map(p => p.person), + personsReachables: window.accompanyingCourse.participations.filter(p => p.endDate == null) + .map(p => p.person), startDate: new Date(), endDate: null, isLoadingSocialActions: false, @@ -44,9 +48,17 @@ const store = createStore({ }, startDate: { datetime: datetimeToISO(state.startDate) - } + }, + persons: [] }; + for (let i in state.personsPicked) { + payload.persons.push({ + id: state.personsPicked[i].id, + type: 'person' + }); + } + if (null !== state.endDate) { payload.endDate = { datetime: datetimeToISO(state.endDate) @@ -71,12 +83,16 @@ const store = createStore({ state.socialActionPicked = socialAction; }, setSocialIssue(state, socialIssueId) { + console.log('set social issue', socialIssueId); if (socialIssueId === null) { state.socialIssuePicked = null; - return; + } else { + let mapped = state.socialIssues + .find(e => e.id === socialIssueId); + console.log('mapped', mapped); + state.socialIssuePicked = mapped; + console.log('social issue setted', state.socialIssuePicked); } - state.socialIssuePicked = state.socialIssues - .find(e => e.id === socialIssueId); }, setIsLoadingSocialActions(state, s) { state.isLoadingSocialActions = s; @@ -90,6 +106,11 @@ const store = createStore({ setEndDate(state, date) { state.endDate = date; }, + setPersonsPickedIds(state, ids) { + console.log('persons ids', ids); + state.personsPicked = state.personsReachables + .filter(p => ids.includes(p.id)) + }, addErrors(state, { errors, cancel_posting }) { console.log('add errors', errors); state.errors = errors; @@ -103,8 +124,10 @@ const store = createStore({ console.log('pick social issue'); commit('setIsLoadingSocialActions', true); - commit('setSocialIssue', null); + commit('setSocialAction', null); commit('setSocialActionsReachables', []); + commit('setSocialIssue', null); + findSocialActionsBySocialIssue(socialIssueId).then( (response) => { diff --git a/src/Bundle/ChillPersonBundle/migrations/Version20210623135043.php b/src/Bundle/ChillPersonBundle/migrations/Version20210623135043.php new file mode 100644 index 000000000..d7f2f4ccc --- /dev/null +++ b/src/Bundle/ChillPersonBundle/migrations/Version20210623135043.php @@ -0,0 +1,34 @@ +addSql("CREATE TABLE chill_person_accompanying_period_work_person (accompanyingperiodwork_id INT NOT NULL, person_id INT NOT NULL, PRIMARY KEY(accompanyingperiodwork_id, person_id))"); + $this->addSql("CREATE INDEX IDX_615F494CB99F6060 ON chill_person_accompanying_period_work_person (accompanyingperiodwork_id)"); + $this->addSql("CREATE INDEX IDX_615F494C217BBB47 ON chill_person_accompanying_period_work_person (person_id)"); + $this->addSql("ALTER TABLE chill_person_accompanying_period_work_person ADD CONSTRAINT FK_615F494CB99F6060 FOREIGN KEY (accompanyingperiodwork_id) REFERENCES chill_person_accompanying_period_work (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE"); + $this->addSql("ALTER TABLE chill_person_accompanying_period_work_person ADD CONSTRAINT FK_615F494C217BBB47 FOREIGN KEY (person_id) REFERENCES chill_person_person (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE"); + + } + + public function down(Schema $schema): void + { + $this->addSql("DROP TABLE chill_person_accompanying_period_work_person"); + } +} From 5a4a0a3617794d0635e51298a5f15c3e1eaff7af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 23 Jun 2021 21:26:36 +0200 Subject: [PATCH 2/5] add results for actions in course edit form --- .../vuejs/AccompanyingCourseWorkEdit/App.vue | 73 ++++++++++++++++-- .../_components/AddResult.vue | 76 +++++++++++++++++++ .../vuejs/AccompanyingCourseWorkEdit/store.js | 9 +++ 3 files changed, 151 insertions(+), 7 deletions(-) create mode 100644 src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/_components/AddResult.vue diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/App.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/App.vue index f46c36d03..3ef3b3390 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/App.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/App.vue @@ -2,30 +2,41 @@

Hello

-
+

{{ work.socialAction.text }}

-
+
-
+
-
+
-
+

Objectifs

Résultats

+ + + +
+
+ {{ $t('results_without_objective') }} +
+
+ +
+
@@ -33,20 +44,64 @@ diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/store.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/store.js index f72badc91..0e9e30897 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/store.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/store.js @@ -26,6 +26,9 @@ const store = createStore({ socialAction(state) { return state.work.socialAction; }, + hasResultsForAction(state) { + return state.resultsForAction.length > 0; + } }, mutations: { setStartDate(state, date) { @@ -48,6 +51,12 @@ const store = createStore({ state.resultsForGoal.push(r); } }, + addResultPicked(state, result) { + state.resultsPicked.push(result); + }, + removeResultPicked(state, result) { + state.resultsPicked = state.resultsPicked.filter(r => r.id !== result.id); + }, addErrors(state, errors) { console.log('handling errors', errors); for (let i in errors) { From ac4cf43753c0e36d851d736bd16194cfc2e50916 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 23 Jun 2021 22:40:11 +0200 Subject: [PATCH 3/5] add goals to work, and add results for each goal --- .../vuejs/AccompanyingCourseWorkEdit/App.vue | 57 ++++++++++++++++++- .../_components/AddResult.vue | 40 ++++++++++++- .../vuejs/AccompanyingCourseWorkEdit/store.js | 39 ++++++++++++- 3 files changed, 130 insertions(+), 6 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/App.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/App.vue index 3ef3b3390..feee033e4 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/App.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/App.vue @@ -27,8 +27,7 @@

Résultats

- - +
{{ $t('results_without_objective') }} @@ -37,6 +36,38 @@
+ + +
+
+ + + {{ g.title.fr }} + +
+
+ +
+
+ + +
+
+
+
    +
  • + + {{ g.title.fr }} +
  • +
+
+
+ + {{ $t('add_objective') }} +
+
+
+
@@ -106,12 +137,14 @@ export default { data() { return { editor: ClassicEditor, + showAddObjective: false, }; }, computed: { ...mapState([ 'work', 'resultsForAction', + 'goalsPicked', ]), ...mapGetters([ 'hasResultsForAction', @@ -142,6 +175,26 @@ export default { this.$store.mutate('setNote', note); } }, + availableForCheckGoal() { + let pickedIds = this.$store.state.goalsPicked.map(g => g.id); + console.log('pickeds goals id', pickedIds); + console.log(this.$store.state.goalsForAction); + + return this.$store.state.goalsForAction.filter(g => !pickedIds.includes(g.id)); + }, + }, + methods: { + toggleAddObjective() { + this.showAddObjective = !this.showAddObjective; + }, + addGoal(g) { + console.log('add Goal', g); + this.$store.commit('addGoal', g); + }, + removeGoal(g) { + console.log('remove goal', g); + this.$store.commit('removeGoal', g); + }, } }; diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/_components/AddResult.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/_components/AddResult.vue index ed86724d2..d56a287a8 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/_components/AddResult.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/_components/AddResult.vue @@ -1,5 +1,5 @@