AccompanyingCourseWorkEdit: replace document by a new one (working now)

This commit is contained in:
nobohan 2022-03-14 10:42:16 +01:00
parent dbe186547f
commit 6eac6044cd
2 changed files with 13 additions and 16 deletions

View File

@ -297,10 +297,6 @@ export default {
this.$store.commit('addDocument', {key: this.evaluation.key, document: document}); this.$store.commit('addDocument', {key: this.evaluation.key, document: document});
}, },
replaceDocument(oldDocument, storedObject) { replaceDocument(oldDocument, storedObject) {
console.log(oldDocument);
console.log(storedObject);
//console.log(oldDocument) how to get the old document?
let document = { let document = {
type: 'accompanying_period_work_evaluation_document', type: 'accompanying_period_work_evaluation_document',
storedObject: storedObject, storedObject: storedObject,

View File

@ -213,27 +213,28 @@ const store = createStore({
})); }));
}, },
removeDocument(state, {key, document}) { removeDocument(state, {key, document}) {
let evaluations = state.evaluationsPicked.find(e => e.key === key); let evaluation = state.evaluationsPicked.find(e => e.key === key);
if (evaluations === undefined) { if (evaluation === undefined) {
return; return;
} }
evaluations.documents = evaluations.documents.filter(d => d.key !== document.key); evaluation.documents = evaluation.documents.filter(d => d.key !== document.key);
}, },
replaceDocument(state, payload) { replaceDocument(state, payload) {
console.log('payload', payload) let evaluation = state.evaluationsPicked.find(e => e.key === payload.key);
console.log(state.evaluationsPicked) if (evaluation === undefined) {
let evaluations = state.evaluationsPicked.find(e => e.key === payload.key);
console.log(evaluations)
if (evaluations === undefined) {
return; return;
} }
//Add document with map let newDocument = Object.assign(
evaluations.documents = evaluations.documents.map(d => d.key === payload.oldDocument.key ? payload.document : d); //TODO no key on documents! payload.document, {
console.log(evaluations) key: evaluation.documents.length + 1,
workflows_availables: state.work.workflows_availables_evaluation_documents,
workflows: [],
}
);
evaluation.documents = evaluation.documents.map(d => d.id === payload.oldDocument.id ? newDocument : d);
}, },
addEvaluation(state, evaluation) { addEvaluation(state, evaluation) {
let e = { let e = {