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});
},
replaceDocument(oldDocument, storedObject) {
console.log(oldDocument);
console.log(storedObject);
//console.log(oldDocument) how to get the old document?
let document = {
type: 'accompanying_period_work_evaluation_document',
storedObject: storedObject,

View File

@ -213,27 +213,28 @@ const store = createStore({
}));
},
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;
}
evaluations.documents = evaluations.documents.filter(d => d.key !== document.key);
evaluation.documents = evaluation.documents.filter(d => d.key !== document.key);
},
replaceDocument(state, payload) {
console.log('payload', payload)
console.log(state.evaluationsPicked)
let evaluations = state.evaluationsPicked.find(e => e.key === payload.key);
console.log(evaluations)
if (evaluations === undefined) {
let evaluation = state.evaluationsPicked.find(e => e.key === payload.key);
if (evaluation === undefined) {
return;
}
//Add document with map
evaluations.documents = evaluations.documents.map(d => d.key === payload.oldDocument.key ? payload.document : d); //TODO no key on documents!
console.log(evaluations)
let newDocument = Object.assign(
payload.document, {
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) {
let e = {