accompanyingCourseWork: add documents to vue form

This commit is contained in:
nobohan 2022-02-24 15:24:58 +01:00
parent c073ec14c8
commit 0661eb8701
3 changed files with 26 additions and 4 deletions

View File

@ -139,7 +139,6 @@ export default {
this.modal.showModal = false; this.modal.showModal = false;
}) })
.catch((error) => { .catch((error) => {
console.log(error); //TODO error handling
if (error.name === 'ValidationException') { if (error.name === 'ValidationException') {
for (let v of error.violations) { for (let v of error.violations) {
this.$toast.open({message: v }); this.$toast.open({message: v });

View File

@ -67,9 +67,9 @@
<div class="flex-table"> <div class="flex-table">
<div class="item-bloc" v-for="(d, i) in evaluation.documents" :key="i"> <div class="item-bloc" v-for="(d, i) in evaluation.documents" :key="i">
<div class="item-row"> <div class="item-row">
<div class="item-col"><h6>{{ d.template.name.fr }}</h6></div> <div v-if="d.template" class="item-col"><h6>{{ d.template.name.fr }}</h6></div>
<div class="item-col"> <div class="item-col">
<p>Créé par {{ d.createdBy.text }}<br/> <p v-if="d.createdBy">Créé par {{ d.createdBy.text }}<br/>
Le {{ $d(ISOToDatetime(d.createdAt.datetime), 'long') }}</p> Le {{ $d(ISOToDatetime(d.createdAt.datetime), 'long') }}</p>
</div> </div>
@ -246,6 +246,17 @@ export default {
addDocument(storedObject) { addDocument(storedObject) {
console.log(storedObject); console.log(storedObject);
console.log('Add document'); console.log('Add document');
//TODO build here the document object
let document = {
type: 'accompanying_period_work_evaluation_document',
storedObject: storedObject,
template: { // TODO remove
name: {
fr: storedObject.filename
}
},
};
this.$store.commit('addDocument', {key: this.evaluation.key, document: document});
} }
}, },
} }

View File

@ -110,6 +110,7 @@ const store = createStore({
maxDate: e.maxDate !== null ? { datetime: datetimeToISO(e.maxDate) } : null, maxDate: e.maxDate !== null ? { datetime: datetimeToISO(e.maxDate) } : null,
warningInterval: intervalDaysToISO(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;
@ -197,6 +198,15 @@ const store = createStore({
found.results = found.results.filter(r => r.id !== result.id); found.results = found.results.filter(r => r.id !== result.id);
}, },
addDocument(state, payload) {
state.evaluationsPicked.forEach(
e => {
if (e.key === payload.key) {
e.documents.push(payload.document);
}
}
)
},
addEvaluation(state, evaluation) { addEvaluation(state, evaluation) {
let e = { let e = {
type: "accompanying_period_work_evaluation", type: "accompanying_period_work_evaluation",
@ -374,13 +384,15 @@ const store = createStore({
}); });
} }
}, },
addDocument({commit}, payload) {
commit('addDocument', payload);
},
submit({ getters, state, commit }, callback) { submit({ getters, state, commit }, callback) {
let let
payload = getters.buildPayload, payload = getters.buildPayload,
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 = []
; ;
commit('setIsPosting', true); commit('setIsPosting', true);
return makeFetch('PUT', url, payload) return makeFetch('PUT', url, payload)