serialization forr evaluations

This commit is contained in:
2021-08-19 15:03:56 +02:00
parent bab06796f1
commit 60f7bdc926
5 changed files with 70 additions and 56 deletions

View File

@@ -8,7 +8,7 @@
<div id="startDate" class="action-row">
<label>{{ $t('startDate') }}</label>
<input v-model="startDate" type="date"/>
<input v-model="startDate" type="date" required="true"/>
</div>
<div id="endDate" class="action-row">

View File

@@ -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) });
}
},

View File

@@ -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);
},
}
});