Removes update from api when deletion leaves orphans terms. This is done now only locally.

This commit is contained in:
Mateus Machado Luna 2018-08-14 15:44:27 -03:00
parent b325710ccd
commit f743e0d77d
4 changed files with 26 additions and 36 deletions

View File

@ -123,7 +123,9 @@ export default {
...mapActions('taxonomy', [
'updateChildTerm',
'deleteChildTerm',
'fetchChildTerms'
'fetchChildTerms',
'clearTerms',
'updateChildTermLocal'
]),
addNewChildTerm() {
this.showChildren = true;
@ -205,8 +207,12 @@ export default {
title: this.$i18n.get('label_warning'),
message: this.$i18n.get('info_warning_selected_term_delete'),
onConfirm: () => {
// If all checks passed, term can be deleted
this.deleteChildTerm({taxonomyId: this.taxonomyId, termId: this.term.id, parent: this.term.parent })
this.deleteChildTerm({
taxonomyId: this.taxonomyId,
termId: this.term.id,
parent: this.term.parent })
.then(() => {
this.totalTerms = this.totalTerms - 1;
})
@ -216,21 +222,14 @@ export default {
// Updates parent IDs for orphans
if (this.term.children != undefined && this.term.children.length > 0) {
for (let orphanTerm of this.term.children) {
this.updateChildTerm({
taxonomyId: this.taxonomyId,
termId: orphanTerm.id,
name: orphanTerm.name,
description: orphanTerm.description,
parent: this.term.parent,
for (let orphanTerm of this.term.children) {
this.updateChildTermLocal({
term: orphanTerm,
parent: this.term.parent,
oldParent: this.term.id
})
.catch((error) => {
this.$console.log(error);
});
}
}
});
}
}
},
}
});

View File

@ -344,27 +344,11 @@ export default {
deleteBasicTerm(term) {
this.deleteTerm({taxonomyId: this.taxonomyId, termId: term.id })
.then(() => {
this.totalTerms = this.totalTerms - 1;
this.searchTerms(this.offset);
})
.catch((error) => {
this.$console.log(error);
});
// Updates parent IDs for orphans
for (let orphanTerm of this.termsList) {
if (orphanTerm.parent == term.id) {
this.updateTerm({
taxonomyId: this.taxonomyId,
termId: orphanTerm.id,
name: orphanTerm.name,
description: orphanTerm.description,
parent: term.parent
})
.catch((error) => {
this.$console.log(error);
});
}
}
}
},
created() {

View File

@ -277,6 +277,11 @@ export const updateChildTerm = ({ commit }, { taxonomyId, termId, name, descript
});
};
// Used to update parent changes after deletion only locally
export const updateChildTermLocal = ({ commit }, { term, parent, oldParent }) => {
commit('updateChildTerm', { term: term, parent: parent, oldParent: oldParent });
};
export const deleteChildTerm = ({ commit }, { taxonomyId, termId, parent }) => {
return new Promise(( resolve, reject ) => {
axios.tainacan.delete(`/taxonomy/${taxonomyId}/terms/${termId}?permanently=1`)
@ -294,4 +299,5 @@ export const deleteChildTerm = ({ commit }, { taxonomyId, termId, parent }) => {
export const clearTerms = ({ commit }) => {
commit('clearTerms');
};
};

View File

@ -123,10 +123,11 @@ export const updateChildTerm = (state, { term, parent, oldParent }) => {
}
}
} else {
// Removes from old parent
this.deleteChildTerm(term.id, oldParent)
deleteChildTerm(term.id, oldParent)
// Adds it to new one
this.addChildTerm(term, parent);
addChildTerm(term, parent);
}
};