From 94475166942d32e2875ed112047b907fc71ca5d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 18 Aug 2021 22:30:32 +0200 Subject: [PATCH 1/3] fix bug in saving evaluation dates --- .../vuejs/AccompanyingCourseWorkEdit/App.vue | 2 +- .../components/AddEvaluation.vue | 9 ++-- .../components/FormEvaluation.vue | 51 +++++++------------ .../vuejs/AccompanyingCourseWorkEdit/store.js | 28 +++++++--- 4 files changed, 43 insertions(+), 47 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/App.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/App.vue index cf18dd4f2..500e84e76 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/App.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/App.vue @@ -87,7 +87,7 @@ diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/components/AddEvaluation.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/components/AddEvaluation.vue index 931c4ab27..401cf2b7b 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/components/AddEvaluation.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/components/AddEvaluation.vue @@ -8,13 +8,13 @@
{{ $t('startDate') }} :
-
{{ $d(evaluation.startDate.datetime, 'short') }}
+
{{ $d(evaluation.startDate, 'short') }}
{{ $t('endDate') }} :
-
{{ $d(evaluation.endDate.datetime, 'short') }}
+
{{ $d(evaluation.endDate, 'short') }}
{{ $t('maxDate') }} :
-
{{ $d(evaluation.maxDate.datetime, 'short') }}
+
{{ $d(evaluation.maxDate, 'short') }}
{{ $t('warningInterval') }} :
{{ evaluation.warningInterval }}
@@ -70,7 +70,7 @@ export default { components: { FormEvaluation }, - props: ['evaluation'], + props: ['evaluation', 'editEvaluation'], i18n, data() { return { @@ -91,7 +91,6 @@ export default { this.editEvaluation = !this.editEvaluation; }, submitForm() { - this.$refs.FormEvaluation.saveEvaluation(); this.toggleEditEvaluation(); } } diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/components/FormEvaluation.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/components/FormEvaluation.vue index 3e04b4f5b..8cabc92c9 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/components/FormEvaluation.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/components/FormEvaluation.vue @@ -139,37 +139,28 @@ export default { }, */ startDate: { - get() { - if (this.evaluation.startDate) { - return this.evaluation.startDate.datetime.split('T')[0]; - } - return null; - }, - set(v) { - this.evaluation.startDate.datetime = `${v}T00:00:00+0100`; - } + get() { + return dateToISO(this.evaluation.startDate); + }, + set(v) { + this.$store.commit('setEvaluationStartDate', { key: this.evaluation.key, date: ISOToDate(v) }); + } }, endDate: { - get() { - if (this.evaluation.endDate) { - return this.evaluation.endDate.datetime.split('T')[0]; - } - return null; - }, - set(v) { - this.evaluation.endDate.datetime = `${v}T00:00:00+0100`; - } + get() { + return dateToISO(this.evaluation.endDate); + }, + set(v) { + this.$store.commit('setEvaluationEndDate', { key: this.evaluation.key, date: ISOToDate(v) }); + } }, maxDate: { - get() { - if (this.evaluation.maxDate) { - return this.evaluation.maxDate.datetime.split('T')[0]; - } - return null; - }, - set(v) { - this.evaluation.maxDate.datetime = `${v}T00:00:00+0100`; - } + get() { + return dateToISO(this.evaluation.maxDate); + }, + set(v) { + this.$store.commit('setEvaluationMaxDate', { key: this.evaluation.key, date: ISOToDate(v) }); + } }, warningInterval: { get() { return this.evaluation.warningInterval; }, @@ -203,12 +194,6 @@ export default { }) ; }, - saveEvaluation() { - console.log('save evaluation'); - - console.log('dispatch action: post/patch/put evaluation'); - console.log('commit mutation: update state.mutation'); - } }, mounted() { //this.listAllStatus(); diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/store.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/store.js index f91539a16..71a97ea21 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/store.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/store.js @@ -165,7 +165,7 @@ const store = createStore({ found.results.push(result); }, - removeResultForGoalPicked(state, { goal, result}) { + removeResultForGoalPicked(state, { goal, result }) { let found = state.goalsPicked.find(g => g.goal.id === goal.id); if (found === undefined) { @@ -177,14 +177,14 @@ const store = createStore({ addEvaluation(state, evaluation) { let e = { type: "accompanying_period_work_evaluation", + key: state.evaluationsPicked.length + 1, evaluation: evaluation, - //startDate, - //endDate, - //maxDate, - //warningInterval - //comment, - //documents, - } + "startDate": null, + "endDate": null, + "maxDate": null, + "warningInterval": null, + "comment": "", + }; state.evaluationsPicked.push(e); console.log('ep', state.evaluationsPicked); }, @@ -192,6 +192,18 @@ const store = createStore({ state.evaluationsPicked = state.evaluationsPicked.filter(e => e.id !== evaluation.id); console.log('ep', state.evaluationsPicked); }, + setEvaluationStartDate(state, {key, date}) { + state.evaluationsPicked.find(e => e.key == key) + .startDate = date; + }, + setEvaluationEndDate(state, {key, date}) { + state.evaluationsPicked.find(e => e.key == key) + .endDate = date; + }, + setEvaluationMaxDate(state, {key, date}) { + state.evaluationsPicked.find(e => e.key == key) + .maxDate = date; + }, setPersonsPickedIds(state, ids) { //console.log('persons ids', ids); state.personsPicked = state.personsReachables From bab06796f106246445ca12e43a4f9411b08eb66b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 19 Aug 2021 10:14:10 +0200 Subject: [PATCH 2/3] improve editing of evaluation - an evaluation type can be repeated multiple times on the same action; - in vue, evaluation are listed by key, not id, - adding an evaluation make appears directly in "edit" mode; - ... --- .../src/Entity/AsideActivity.php | 2 +- .../Resources/public/chill/js/date.js | 143 ++++++++++++------ .../vuejs/AccompanyingCourseWorkEdit/App.vue | 8 +- .../components/AddEvaluation.vue | 23 +-- .../components/FormEvaluation.vue | 10 +- .../vuejs/AccompanyingCourseWorkEdit/store.js | 31 ++-- 6 files changed, 134 insertions(+), 83 deletions(-) diff --git a/src/Bundle/ChillAsideActivityBundle/src/Entity/AsideActivity.php b/src/Bundle/ChillAsideActivityBundle/src/Entity/AsideActivity.php index 40d8aa6cd..92478d787 100644 --- a/src/Bundle/ChillAsideActivityBundle/src/Entity/AsideActivity.php +++ b/src/Bundle/ChillAsideActivityBundle/src/Entity/AsideActivity.php @@ -13,7 +13,7 @@ use Symfony\Component\Validator\Constraints as Assert; * @ORM\Entity * @ORM\Table(schema="chill_asideactivity") */ -final class AsideActivity implements TrackUpdateInterface, TrackCreationInterface +class AsideActivity implements TrackUpdateInterface, TrackCreationInterface { /** * @ORM\Id diff --git a/src/Bundle/ChillMainBundle/Resources/public/chill/js/date.js b/src/Bundle/ChillMainBundle/Resources/public/chill/js/date.js index ec66da770..e31132b67 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/chill/js/date.js +++ b/src/Bundle/ChillMainBundle/Resources/public/chill/js/date.js @@ -13,15 +13,15 @@ * */ const dateToISO = (date) => { - if (null === date) { - return null; - } + if (null === date) { + return null; + } - return [ - date.getFullYear(), - (date.getMonth() + 1).toString().padStart(2, '0'), - date.getDate().toString().padStart(2, '0') - ].join('-'); + return [ + date.getFullYear(), + (date.getMonth() + 1).toString().padStart(2, '0'), + date.getDate().toString().padStart(2, '0') + ].join('-'); }; /** @@ -30,10 +30,10 @@ const dateToISO = (date) => { * **Experimental** */ const ISOToDate = (str) => { - let - [year, month, day] = str.split('-'); - - return new Date(year, month-1, day); + let + [year, month, day] = str.split('-'); + + return new Date(year, month-1, day); } /** @@ -41,53 +41,100 @@ const ISOToDate = (str) => { * */ const ISOToDatetime = (str) => { - if (null === str) { - return null; - } + if (null === str) { + return null; + } - let - [cal, times] = str.split('T'), - [year, month, date] = cal.split('-'), - [time, timezone] = times.split(times.charAt(8)), - [hours, minutes, seconds] = time.split(':') - ; + let + [cal, times] = str.split('T'), + [year, month, date] = cal.split('-'), + [time, timezone] = times.split(times.charAt(8)), + [hours, minutes, seconds] = time.split(':') + ; - return new Date(year, month-1, date, hours, minutes, seconds); + return new Date(year, month-1, date, hours, minutes, seconds); } /** * Convert a date to ISO8601, valid for usage in api - * + * */ const datetimeToISO = (date) => { - let cal, time, offset; - cal = [ - date.getFullYear(), - (date.getMonth() + 1).toString().padStart(2, '0'), - date.getDate().toString().padStart(2, '0') - ].join('-'); - - time = [ - date.getHours().toString().padStart(2, '0'), - date.getMinutes().toString().padStart(2, '0'), - date.getSeconds().toString().padStart(2, '0') - ].join(':'); + let cal, time, offset; + cal = [ + date.getFullYear(), + (date.getMonth() + 1).toString().padStart(2, '0'), + date.getDate().toString().padStart(2, '0') + ].join('-'); - offset = [ - date.getTimezoneOffset() <= 0 ? '+' : '-', - Math.abs(Math.floor(date.getTimezoneOffset() / 60)).toString().padStart(2, '0'), - ':', - Math.abs(date.getTimezoneOffset() % 60).toString().padStart(2, '0'), - ].join(''); - - let x = cal + 'T' + time + offset; + time = [ + date.getHours().toString().padStart(2, '0'), + date.getMinutes().toString().padStart(2, '0'), + date.getSeconds().toString().padStart(2, '0') + ].join(':'); - return x; + offset = [ + date.getTimezoneOffset() <= 0 ? '+' : '-', + Math.abs(Math.floor(date.getTimezoneOffset() / 60)).toString().padStart(2, '0'), + ':', + Math.abs(date.getTimezoneOffset() % 60).toString().padStart(2, '0'), + ].join(''); + + let x = cal + 'T' + time + offset; + + return x; }; +const intervalDaysToISO = (days) => { + if (null === days) { + return null; + } + + return `PD${days}`; +} + +const intervalISOToDays = (str) => { + if (null === str) { + return null + } + + let days = 0; + let isDate = true; + for (let i = 0; i < str.length; i = i + 1) { + // we do not take time into account + if (!isDate) { + continue; + } + switch (str.charAt(i)) { + case 'P': + isDate = true; + break; + case 'Y': + i = i+1; + days = days + Number.parseInt(str.charAt(i)) * 365; + break; + case 'M': + i = i+1; + days = days + Number.parseInt(str.charAt(i)) * 30; + break; + case 'D': + i = i+1; + days = days + Number.parseInt(str.charAt(i)); + break; + case 'T': + isDate = false; + break; + } + } + + return days; +} + export { - dateToISO, - ISOToDate, - ISOToDatetime, - datetimeToISO + dateToISO, + ISOToDate, + ISOToDatetime, + datetimeToISO, + intervalISOToDays, + intervalDaysToISO, }; diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/App.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/App.vue index 500e84e76..651943724 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/App.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/App.vue @@ -96,7 +96,7 @@

{{ $t('available_evaluations_text') }}

    -
  • +
  • {{ e.title.fr }}
  • @@ -349,12 +349,6 @@ export default { return this.$store.state.goalsForAction.filter(g => !pickedIds.includes(g.id)); }, - availableForCheckEvaluation() { - //console.log('evaluationsPicked', this.$store.state.evaluationsPicked); - //console.log('evaluationsForAction', this.$store.state.evaluationsForAction); - let pickedIds = this.$store.state.evaluationsPicked.map(e => e.evaluation.id); - return this.$store.state.evaluationsForAction.filter(e => !pickedIds.includes(e.id)); - }, pickedEvaluations() { return this.$store.state.evaluationsPicked; }, diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/components/AddEvaluation.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/components/AddEvaluation.vue index 401cf2b7b..f7e0902f4 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/components/AddEvaluation.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/components/AddEvaluation.vue @@ -1,10 +1,10 @@