mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 21:34:25 +00:00
serialization forr evaluations
This commit is contained in:
parent
bab06796f1
commit
60f7bdc926
@ -30,6 +30,13 @@ const dateToISO = (date) => {
|
|||||||
* **Experimental**
|
* **Experimental**
|
||||||
*/
|
*/
|
||||||
const ISOToDate = (str) => {
|
const ISOToDate = (str) => {
|
||||||
|
if (null === str) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if ("" === str.trim()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
let
|
let
|
||||||
[year, month, day] = str.split('-');
|
[year, month, day] = str.split('-');
|
||||||
|
|
||||||
@ -86,11 +93,12 @@ const datetimeToISO = (date) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const intervalDaysToISO = (days) => {
|
const intervalDaysToISO = (days) => {
|
||||||
|
console.log(days);
|
||||||
if (null === days) {
|
if (null === days) {
|
||||||
return null;
|
return 'PD0';
|
||||||
}
|
}
|
||||||
|
|
||||||
return `PD${days}`;
|
return `P${days}D`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const intervalISOToDays = (str) => {
|
const intervalISOToDays = (str) => {
|
||||||
@ -98,10 +106,14 @@ const intervalISOToDays = (str) => {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ("" === str.trim()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
let days = 0;
|
let days = 0;
|
||||||
let isDate = true;
|
let isDate = true;
|
||||||
|
let vstring = "";
|
||||||
for (let i = 0; i < str.length; i = i + 1) {
|
for (let i = 0; i < str.length; i = i + 1) {
|
||||||
// we do not take time into account
|
|
||||||
if (!isDate) {
|
if (!isDate) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -109,21 +121,35 @@ const intervalISOToDays = (str) => {
|
|||||||
case 'P':
|
case 'P':
|
||||||
isDate = true;
|
isDate = true;
|
||||||
break;
|
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':
|
case 'T':
|
||||||
isDate = false;
|
isDate = false;
|
||||||
break;
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,6 +74,7 @@ class AccompanyingPeriodWorkEvaluation implements TrackUpdateInterface, TrackCre
|
|||||||
/**
|
/**
|
||||||
* @ORM\Column(type="dateinterval", nullable=true, options={"default": null})
|
* @ORM\Column(type="dateinterval", nullable=true, options={"default": null})
|
||||||
* @Serializer\Groups({"read"})
|
* @Serializer\Groups({"read"})
|
||||||
|
* @Serializer\Groups({"write"})
|
||||||
* @Serializer\Groups({"accompanying_period_work_evaluation:create"})
|
* @Serializer\Groups({"accompanying_period_work_evaluation:create"})
|
||||||
*/
|
*/
|
||||||
private ?DateInterval $warningInterval = null;
|
private ?DateInterval $warningInterval = null;
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
<div id="startDate" class="action-row">
|
<div id="startDate" class="action-row">
|
||||||
<label>{{ $t('startDate') }}</label>
|
<label>{{ $t('startDate') }}</label>
|
||||||
<input v-model="startDate" type="date"/>
|
<input v-model="startDate" type="date" required="true"/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="endDate" class="action-row">
|
<div id="endDate" class="action-row">
|
||||||
|
@ -143,6 +143,7 @@ export default {
|
|||||||
return dateToISO(this.evaluation.startDate);
|
return dateToISO(this.evaluation.startDate);
|
||||||
},
|
},
|
||||||
set(v) {
|
set(v) {
|
||||||
|
console.log(v);
|
||||||
this.$store.commit('setEvaluationStartDate', { key: this.evaluation.key, date: ISOToDate(v) });
|
this.$store.commit('setEvaluationStartDate', { key: this.evaluation.key, date: ISOToDate(v) });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -1,26 +1,36 @@
|
|||||||
import { createStore } from 'vuex';
|
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 { findSocialActionsBySocialIssue } from 'ChillPersonAssets/vuejs/_api/SocialWorkSocialAction.js';
|
||||||
import { create } from 'ChillPersonAssets/vuejs/_api/AccompanyingCourseWork.js';
|
import { create } from 'ChillPersonAssets/vuejs/_api/AccompanyingCourseWork.js';
|
||||||
|
|
||||||
const debug = process.env.NODE_ENV !== 'production';
|
const debug = process.env.NODE_ENV !== 'production';
|
||||||
|
|
||||||
console.log('acw', window.accompanyingCourseWork);
|
|
||||||
|
|
||||||
const store = createStore({
|
const store = createStore({
|
||||||
strict: debug,
|
strict: debug,
|
||||||
state: {
|
state: {
|
||||||
work: window.accompanyingCourseWork,
|
work: window.accompanyingCourseWork,
|
||||||
startDate: ISOToDatetime(window.accompanyingCourseWork.startDate.datetime),
|
startDate: window.accompanyingCourseWork.startDate !== null ?
|
||||||
endDate: (window.accompanyingCourseWork.endDate !== null ?
|
ISOToDatetime(window.accompanyingCourseWork.startDate.datetime) : null,
|
||||||
ISOToDatetime(window.accompanyingCourseWork.endDate.datetime) : null),
|
endDate: window.accompanyingCourseWork.endDate !== null ?
|
||||||
|
ISOToDatetime(window.accompanyingCourseWork.endDate.datetime) : null,
|
||||||
note: window.accompanyingCourseWork.note,
|
note: window.accompanyingCourseWork.note,
|
||||||
goalsPicked: window.accompanyingCourseWork.goals,
|
goalsPicked: window.accompanyingCourseWork.goals,
|
||||||
goalsForAction: [],
|
goalsForAction: [],
|
||||||
resultsPicked: window.accompanyingCourseWork.results,
|
resultsPicked: window.accompanyingCourseWork.results,
|
||||||
resultsForAction: [],
|
resultsForAction: [],
|
||||||
resultsForGoal: [],
|
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: [],
|
evaluationsForAction: [],
|
||||||
personsPicked: window.accompanyingCourseWork.persons,
|
personsPicked: window.accompanyingCourseWork.persons,
|
||||||
personsReachables: window.accompanyingCourseWork.accompanyingPeriod.participations.filter(p => p.endDate == null)
|
personsReachables: window.accompanyingCourseWork.accompanyingPeriod.participations.filter(p => p.endDate == null)
|
||||||
@ -57,7 +67,7 @@ const store = createStore({
|
|||||||
return {
|
return {
|
||||||
type: 'accompanying_period_work',
|
type: 'accompanying_period_work',
|
||||||
id: state.work.id,
|
id: state.work.id,
|
||||||
startDate: {
|
startDate: state.startDate === null ? null : {
|
||||||
datetime: datetimeToISO(state.startDate)
|
datetime: datetimeToISO(state.startDate)
|
||||||
},
|
},
|
||||||
endDate: state.endDate === null ? null : {
|
endDate: state.endDate === null ? null : {
|
||||||
@ -93,16 +103,16 @@ const store = createStore({
|
|||||||
id: e.evaluation.id,
|
id: e.evaluation.id,
|
||||||
type: e.evaluation.type
|
type: e.evaluation.type
|
||||||
},
|
},
|
||||||
startDate: e.startDate,
|
startDate: e.startDate !== null ? { datetime: datetimeToISO(e.startDate) } : null,
|
||||||
endDate: e.endDate,
|
endDate: e.endDate !== null ? { datetime: datetimeToISO(e.endDate) } : null,
|
||||||
maxDate: e.maxDate,
|
maxDate: e.maxDate !== null ? { datetime: datetimeToISO(e.maxDate) } : null,
|
||||||
warningInterval: e.warningInterval,
|
warningInterval: intervalDaysToISO(e.warningInterval),
|
||||||
comment: e.comment,
|
comment: e.comment,
|
||||||
documents: e.documents
|
|
||||||
};
|
};
|
||||||
if (e.id !== undefined) {
|
if (e.id !== undefined) {
|
||||||
o.id = e.id;
|
o.id = e.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
return o;
|
return o;
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
@ -116,23 +126,18 @@ const store = createStore({
|
|||||||
state.endDate = date;
|
state.endDate = date;
|
||||||
},
|
},
|
||||||
setResultsForAction(state, results) {
|
setResultsForAction(state, results) {
|
||||||
//console.log('set results for action', results);
|
|
||||||
state.resultsForAction = results;
|
state.resultsForAction = results;
|
||||||
},
|
},
|
||||||
setResultsForGoal(state, { goal, results }) {
|
setResultsForGoal(state, { goal, results }) {
|
||||||
//console.log('set results for goal', results);
|
|
||||||
state.goalsForAction.push(goal);
|
state.goalsForAction.push(goal);
|
||||||
for (let i in results) {
|
for (let i in results) {
|
||||||
let r = results[i];
|
let r = results[i];
|
||||||
r.goalId = goal.id;
|
r.goalId = goal.id;
|
||||||
//console.log('adding result', r);
|
|
||||||
state.resultsForGoal.push(r);
|
state.resultsForGoal.push(r);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
setEvaluationsForAction(state, results) {
|
setEvaluationsForAction(state, results) {
|
||||||
//console.log('set evaluations for action', results);
|
|
||||||
state.evaluationsForAction = results;
|
state.evaluationsForAction = results;
|
||||||
console.log('e4a', state.evaluationsForAction);
|
|
||||||
},
|
},
|
||||||
addResultPicked(state, result) {
|
addResultPicked(state, result) {
|
||||||
state.resultsPicked.push(result);
|
state.resultsPicked.push(result);
|
||||||
@ -154,10 +159,6 @@ const store = createStore({
|
|||||||
},
|
},
|
||||||
addResultForGoalPicked(state, { goal, result}) {
|
addResultForGoalPicked(state, { goal, result}) {
|
||||||
let found = state.goalsPicked.find(g => g.goal.id === goal.id);
|
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) {
|
if (found === undefined) {
|
||||||
return;
|
return;
|
||||||
@ -187,11 +188,9 @@ const store = createStore({
|
|||||||
editEvaluation: true,
|
editEvaluation: true,
|
||||||
};
|
};
|
||||||
state.evaluationsPicked.push(e);
|
state.evaluationsPicked.push(e);
|
||||||
console.log('ep', state.evaluationsPicked);
|
|
||||||
},
|
},
|
||||||
removeEvaluation(state, evaluation) {
|
removeEvaluation(state, evaluation) {
|
||||||
state.evaluationsPicked = state.evaluationsPicked.filter(e => e.key !== evaluation.key);
|
state.evaluationsPicked = state.evaluationsPicked.filter(e => e.key !== evaluation.key);
|
||||||
console.log('ep', state.evaluationsPicked);
|
|
||||||
},
|
},
|
||||||
setEvaluationStartDate(state, {key, date}) {
|
setEvaluationStartDate(state, {key, date}) {
|
||||||
state.evaluationsPicked.find(e => e.key === key)
|
state.evaluationsPicked.find(e => e.key === key)
|
||||||
@ -218,7 +217,6 @@ const store = createStore({
|
|||||||
evaluation.editEvaluation = !evaluation.editEvaluation;
|
evaluation.editEvaluation = !evaluation.editEvaluation;
|
||||||
},
|
},
|
||||||
setPersonsPickedIds(state, ids) {
|
setPersonsPickedIds(state, ids) {
|
||||||
//console.log('persons ids', ids);
|
|
||||||
state.personsPicked = state.personsReachables
|
state.personsPicked = state.personsReachables
|
||||||
.filter(p => ids.includes(p.id))
|
.filter(p => ids.includes(p.id))
|
||||||
},
|
},
|
||||||
@ -229,11 +227,10 @@ const store = createStore({
|
|||||||
state.handlingThirdParty = thirdParty;
|
state.handlingThirdParty = thirdParty;
|
||||||
},
|
},
|
||||||
addThirdParties(state, thirdParties) {
|
addThirdParties(state, thirdParties) {
|
||||||
//console.log('addThirdParties', thirdParties);
|
|
||||||
// filter to remove existing thirdparties
|
// filter to remove existing thirdparties
|
||||||
let ids = state.thirdParties.map(t => t.id);
|
let ids = state.thirdParties.map(t => t.id);
|
||||||
let unexistings = thirdParties.filter(t => !ids.includes(t.id));
|
let unexistings = thirdParties.filter(t => !ids.includes(t.id));
|
||||||
//console.log('unexisting third parties', unexistings);
|
|
||||||
for (let i in unexistings) {
|
for (let i in unexistings) {
|
||||||
state.thirdParties.push(unexistings[i]);
|
state.thirdParties.push(unexistings[i]);
|
||||||
}
|
}
|
||||||
@ -243,7 +240,6 @@ const store = createStore({
|
|||||||
.filter(t => t.id !== thirdParty.id);
|
.filter(t => t.id !== thirdParty.id);
|
||||||
},
|
},
|
||||||
setErrors(state, errors) {
|
setErrors(state, errors) {
|
||||||
//console.log('handling errors', errors);
|
|
||||||
state.errors = errors;
|
state.errors = errors;
|
||||||
},
|
},
|
||||||
setIsPosting(state, st) {
|
setIsPosting(state, st) {
|
||||||
@ -252,12 +248,10 @@ const store = createStore({
|
|||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
getReachablesGoalsForAction({ getters, commit, dispatch }) {
|
getReachablesGoalsForAction({ getters, commit, dispatch }) {
|
||||||
//console.log('getReachablesGoalsForAction');
|
|
||||||
let
|
let
|
||||||
socialActionId = getters.socialAction.id,
|
socialActionId = getters.socialAction.id,
|
||||||
url = `/api/1.0/person/social-work/goal/by-social-action/${socialActionId}.json`
|
url = `/api/1.0/person/social-work/goal/by-social-action/${socialActionId}.json`
|
||||||
;
|
;
|
||||||
//console.log(url);
|
|
||||||
window
|
window
|
||||||
.fetch(
|
.fetch(
|
||||||
url
|
url
|
||||||
@ -275,11 +269,9 @@ const store = createStore({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
getReachablesResultsForGoal({ commit }, goal) {
|
getReachablesResultsForGoal({ commit }, goal) {
|
||||||
//console.log('getReachablesResultsForGoal');
|
|
||||||
let
|
let
|
||||||
url = `/api/1.0/person/social-work/result/by-goal/${goal.id}.json`
|
url = `/api/1.0/person/social-work/result/by-goal/${goal.id}.json`
|
||||||
;
|
;
|
||||||
//console.log(url);
|
|
||||||
window.fetch(url)
|
window.fetch(url)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
@ -289,17 +281,14 @@ const store = createStore({
|
|||||||
throw { m: 'Error while retriving results for goal', s: response.status, b: response.body };
|
throw { m: 'Error while retriving results for goal', s: response.status, b: response.body };
|
||||||
})
|
})
|
||||||
.then(data => {
|
.then(data => {
|
||||||
//console.log('data');
|
|
||||||
commit('setResultsForGoal', { goal, results: data.results });
|
commit('setResultsForGoal', { goal, results: data.results });
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getReachablesResultsForAction({ getters, commit }) {
|
getReachablesResultsForAction({ getters, commit }) {
|
||||||
//console.log('getReachablesResultsForAction');
|
|
||||||
let
|
let
|
||||||
socialActionId = getters.socialAction.id,
|
socialActionId = getters.socialAction.id,
|
||||||
url = `/api/1.0/person/social-work/result/by-social-action/${socialActionId}.json`
|
url = `/api/1.0/person/social-work/result/by-social-action/${socialActionId}.json`
|
||||||
;
|
;
|
||||||
//console.log(url);
|
|
||||||
window.fetch(url)
|
window.fetch(url)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.ok) {
|
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 };
|
throw { m: 'Error while retriving results for social action', s: response.status, b: response.body };
|
||||||
})
|
})
|
||||||
.then(data => {
|
.then(data => {
|
||||||
//console.log('data retrived', data);
|
|
||||||
commit('setResultsForAction', data.results);
|
commit('setResultsForAction', data.results);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getReachablesEvaluationsForAction({ getters, commit }) {
|
getReachablesEvaluationsForAction({ getters, commit }) {
|
||||||
//console.log('getReachablesEvaluationsForAction');
|
|
||||||
let
|
let
|
||||||
socialActionId = getters.socialAction.id,
|
socialActionId = getters.socialAction.id,
|
||||||
url = `/api/1.0/person/social-work/evaluation/by-social-action/${socialActionId}.json`
|
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`,
|
url = `/api/1.0/person/accompanying-course/work/${state.work.id}.json`,
|
||||||
errors = []
|
errors = []
|
||||||
;
|
;
|
||||||
//console.log('action submitting', payload, url);
|
|
||||||
commit('setIsPosting', true);
|
commit('setIsPosting', true);
|
||||||
|
|
||||||
window.fetch(url, {
|
window.fetch(url, {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
headers: {
|
headers: {
|
||||||
@ -372,8 +360,6 @@ const store = createStore({
|
|||||||
dispatch('getReachablesResultsForAction');
|
dispatch('getReachablesResultsForAction');
|
||||||
dispatch('getReachablesGoalsForAction');
|
dispatch('getReachablesGoalsForAction');
|
||||||
dispatch('getReachablesEvaluationsForAction');
|
dispatch('getReachablesEvaluationsForAction');
|
||||||
|
|
||||||
console.log('ep', this.state.evaluationsPicked);
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user