diff --git a/src/Bundle/ChillMainBundle/Resources/public/chill/js/date.js b/src/Bundle/ChillMainBundle/Resources/public/chill/js/date.js index e31132b67..22f935744 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/chill/js/date.js +++ b/src/Bundle/ChillMainBundle/Resources/public/chill/js/date.js @@ -30,6 +30,13 @@ const dateToISO = (date) => { * **Experimental** */ const ISOToDate = (str) => { + if (null === str) { + return null; + } + if ("" === str.trim()) { + return null; + } + let [year, month, day] = str.split('-'); @@ -86,11 +93,12 @@ const datetimeToISO = (date) => { }; const intervalDaysToISO = (days) => { + console.log(days); if (null === days) { - return null; + return 'PD0'; } - return `PD${days}`; + return `P${days}D`; } const intervalISOToDays = (str) => { @@ -98,10 +106,14 @@ const intervalISOToDays = (str) => { return null } + if ("" === str.trim()) { + return null; + } + let days = 0; let isDate = true; + let vstring = ""; for (let i = 0; i < str.length; i = i + 1) { - // we do not take time into account if (!isDate) { continue; } @@ -109,21 +121,35 @@ const intervalISOToDays = (str) => { 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; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + vstring = vstring + str.charAt(i); + break; + case 'Y': + days = days + Number.parseInt(vstring) * 365; + vstring = ""; + break; + case 'M': + days = days + Number.parseInt(vstring) * 30; + vstring = ""; + break; + case 'D': + days = days + Number.parseInt(vstring); + vstring = ""; + break; + default: + throw Error("this character should not appears: " + str.charAt(i)); } } diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWorkEvaluation.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWorkEvaluation.php index cd4bb3ac4..050be9f93 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWorkEvaluation.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWorkEvaluation.php @@ -74,6 +74,7 @@ class AccompanyingPeriodWorkEvaluation implements TrackUpdateInterface, TrackCre /** * @ORM\Column(type="dateinterval", nullable=true, options={"default": null}) * @Serializer\Groups({"read"}) + * @Serializer\Groups({"write"}) * @Serializer\Groups({"accompanying_period_work_evaluation:create"}) */ private ?DateInterval $warningInterval = null; diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/App.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/App.vue index 651943724..fb143789c 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/App.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/App.vue @@ -8,7 +8,7 @@
- +
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 51480e442..721d15450 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/components/FormEvaluation.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/components/FormEvaluation.vue @@ -143,6 +143,7 @@ export default { return dateToISO(this.evaluation.startDate); }, set(v) { + console.log(v); this.$store.commit('setEvaluationStartDate', { key: this.evaluation.key, date: ISOToDate(v) }); } }, diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/store.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/store.js index c5d5658d1..87b7d03e4 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/store.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/store.js @@ -1,26 +1,36 @@ import { createStore } from 'vuex'; -import { datetimeToISO, ISOToDatetime } from 'ChillMainAssets/chill/js/date.js'; +import { datetimeToISO, ISOToDatetime, intervalDaysToISO, intervalISOToDays } from 'ChillMainAssets/chill/js/date.js'; import { findSocialActionsBySocialIssue } from 'ChillPersonAssets/vuejs/_api/SocialWorkSocialAction.js'; import { create } from 'ChillPersonAssets/vuejs/_api/AccompanyingCourseWork.js'; const debug = process.env.NODE_ENV !== 'production'; -console.log('acw', window.accompanyingCourseWork); - const store = createStore({ strict: debug, state: { work: window.accompanyingCourseWork, - startDate: ISOToDatetime(window.accompanyingCourseWork.startDate.datetime), - endDate: (window.accompanyingCourseWork.endDate !== null ? - ISOToDatetime(window.accompanyingCourseWork.endDate.datetime) : null), + startDate: window.accompanyingCourseWork.startDate !== null ? + ISOToDatetime(window.accompanyingCourseWork.startDate.datetime) : null, + endDate: window.accompanyingCourseWork.endDate !== null ? + ISOToDatetime(window.accompanyingCourseWork.endDate.datetime) : null, note: window.accompanyingCourseWork.note, goalsPicked: window.accompanyingCourseWork.goals, goalsForAction: [], resultsPicked: window.accompanyingCourseWork.results, resultsForAction: [], resultsForGoal: [], - evaluationsPicked: window.accompanyingCourseWork.accompanyingPeriodWorkEvaluations, + evaluationsPicked: window.accompanyingCourseWork.accompanyingPeriodWorkEvaluations.map((e, index) => { + var k = Object.assign(e, { + key: index, + editEvaluation: false, + startDate: e.startDate !== null ? ISOToDatetime(e.startDate.datetime) : null, + endDate: e.endDate !== null ? ISOToDatetime(e.endDate.datetime) : null, + maxDate: e.maxDate !== null ? ISOToDatetime(e.maxDate.datetime) : null, + warningInterval: e.warningInterval !== null ? intervalISOToDays(e.warningInterval) : null, + }); + + return k; + }), evaluationsForAction: [], personsPicked: window.accompanyingCourseWork.persons, personsReachables: window.accompanyingCourseWork.accompanyingPeriod.participations.filter(p => p.endDate == null) @@ -57,7 +67,7 @@ const store = createStore({ return { type: 'accompanying_period_work', id: state.work.id, - startDate: { + startDate: state.startDate === null ? null : { datetime: datetimeToISO(state.startDate) }, endDate: state.endDate === null ? null : { @@ -93,16 +103,16 @@ const store = createStore({ id: e.evaluation.id, type: e.evaluation.type }, - startDate: e.startDate, - endDate: e.endDate, - maxDate: e.maxDate, - warningInterval: e.warningInterval, + startDate: e.startDate !== null ? { datetime: datetimeToISO(e.startDate) } : null, + endDate: e.endDate !== null ? { datetime: datetimeToISO(e.endDate) } : null, + maxDate: e.maxDate !== null ? { datetime: datetimeToISO(e.maxDate) } : null, + warningInterval: intervalDaysToISO(e.warningInterval), comment: e.comment, - documents: e.documents }; if (e.id !== undefined) { o.id = e.id; } + return o; }) }; @@ -116,23 +126,18 @@ const store = createStore({ state.endDate = date; }, setResultsForAction(state, results) { - //console.log('set results for action', results); state.resultsForAction = results; }, setResultsForGoal(state, { goal, results }) { - //console.log('set results for goal', results); state.goalsForAction.push(goal); for (let i in results) { let r = results[i]; r.goalId = goal.id; - //console.log('adding result', r); state.resultsForGoal.push(r); } }, setEvaluationsForAction(state, results) { - //console.log('set evaluations for action', results); state.evaluationsForAction = results; - console.log('e4a', state.evaluationsForAction); }, addResultPicked(state, result) { state.resultsPicked.push(result); @@ -154,10 +159,6 @@ const store = createStore({ }, addResultForGoalPicked(state, { goal, result}) { let found = state.goalsPicked.find(g => g.goal.id === goal.id); - //console.log('adResultForGoalPicked'); - //console.log('found', found); - //console.log('goal', goal); - //console.log('result', result); if (found === undefined) { return; @@ -187,11 +188,9 @@ const store = createStore({ editEvaluation: true, }; state.evaluationsPicked.push(e); - console.log('ep', state.evaluationsPicked); }, removeEvaluation(state, evaluation) { state.evaluationsPicked = state.evaluationsPicked.filter(e => e.key !== evaluation.key); - console.log('ep', state.evaluationsPicked); }, setEvaluationStartDate(state, {key, date}) { state.evaluationsPicked.find(e => e.key === key) @@ -218,7 +217,6 @@ const store = createStore({ evaluation.editEvaluation = !evaluation.editEvaluation; }, setPersonsPickedIds(state, ids) { - //console.log('persons ids', ids); state.personsPicked = state.personsReachables .filter(p => ids.includes(p.id)) }, @@ -229,11 +227,10 @@ const store = createStore({ state.handlingThirdParty = thirdParty; }, addThirdParties(state, thirdParties) { - //console.log('addThirdParties', thirdParties); // filter to remove existing thirdparties let ids = state.thirdParties.map(t => t.id); let unexistings = thirdParties.filter(t => !ids.includes(t.id)); - //console.log('unexisting third parties', unexistings); + for (let i in unexistings) { state.thirdParties.push(unexistings[i]); } @@ -243,7 +240,6 @@ const store = createStore({ .filter(t => t.id !== thirdParty.id); }, setErrors(state, errors) { - //console.log('handling errors', errors); state.errors = errors; }, setIsPosting(state, st) { @@ -252,12 +248,10 @@ const store = createStore({ }, actions: { getReachablesGoalsForAction({ getters, commit, dispatch }) { - //console.log('getReachablesGoalsForAction'); let socialActionId = getters.socialAction.id, url = `/api/1.0/person/social-work/goal/by-social-action/${socialActionId}.json` ; - //console.log(url); window .fetch( url @@ -275,11 +269,9 @@ const store = createStore({ }); }, getReachablesResultsForGoal({ commit }, goal) { - //console.log('getReachablesResultsForGoal'); let url = `/api/1.0/person/social-work/result/by-goal/${goal.id}.json` ; - //console.log(url); window.fetch(url) .then(response => { if (response.ok) { @@ -289,17 +281,14 @@ const store = createStore({ throw { m: 'Error while retriving results for goal', s: response.status, b: response.body }; }) .then(data => { - //console.log('data'); commit('setResultsForGoal', { goal, results: data.results }); }); }, getReachablesResultsForAction({ getters, commit }) { - //console.log('getReachablesResultsForAction'); let socialActionId = getters.socialAction.id, url = `/api/1.0/person/social-work/result/by-social-action/${socialActionId}.json` ; - //console.log(url); window.fetch(url) .then(response => { if (response.ok) { @@ -309,12 +298,10 @@ const store = createStore({ throw { m: 'Error while retriving results for social action', s: response.status, b: response.body }; }) .then(data => { - //console.log('data retrived', data); commit('setResultsForAction', data.results); }); }, getReachablesEvaluationsForAction({ getters, commit }) { - //console.log('getReachablesEvaluationsForAction'); let socialActionId = getters.socialAction.id, url = `/api/1.0/person/social-work/evaluation/by-social-action/${socialActionId}.json` @@ -336,8 +323,9 @@ const store = createStore({ url = `/api/1.0/person/accompanying-course/work/${state.work.id}.json`, errors = [] ; - //console.log('action submitting', payload, url); + commit('setIsPosting', true); + window.fetch(url, { method: 'PUT', headers: { @@ -372,8 +360,6 @@ const store = createStore({ dispatch('getReachablesResultsForAction'); dispatch('getReachablesGoalsForAction'); dispatch('getReachablesEvaluationsForAction'); - - console.log('ep', this.state.evaluationsPicked); }, } });