From adac3842796439e8e29fbe331174fe61e0cb715a Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 3 Nov 2021 16:46:27 +0100 Subject: [PATCH] visgraph: prepare PATCH relationship when submitting (wip) --- .../Resources/public/vuejs/VisGraph/App.vue | 50 ++++++++++++++----- .../Resources/public/vuejs/VisGraph/api.js | 25 ++++++++++ 2 files changed, 62 insertions(+), 13 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/VisGraph/App.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/VisGraph/App.vue index 7ce74c749..7c1bcabad 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/VisGraph/App.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/VisGraph/App.vue @@ -305,19 +305,43 @@ export default { }, submitRelationship() { - console.log('submitRelationship') - if (this.modal.action !== 'delete') { - return postRelationship( - this.getPerson(this.modal.data.from), this.getPerson(this.modal.data.to), this.relation, this.reverse - ) - .then(relationship => new Promise(resolve => { - console.log('post response', relationship) - this.$store.dispatch('addLinkFromRelationship', adapt2vis(relationship)) - this.modal.showModal = false - this.resetForm() - resolve() - })) - .catch() + console.log('submitRelationship with action', this.modal.action) + switch (this.modal.action) { + + case 'create': + return postRelationship( + this.getPerson(this.modal.data.from), this.getPerson(this.modal.data.to), this.relation, this.reverse + ) + .then(relationship => new Promise(resolve => { + console.log('post response', relationship) + this.$store.dispatch('addLinkFromRelationship', adapt2vis(relationship)) + this.modal.showModal = false + this.resetForm() + resolve() + })) + .catch() + + case 'edit': + /// TODO + // récupérer la relationship, + // la modifier, + // patcher en reconstruisant le body, + // récupérer la réponse, + // mettre le link (edge) à jour + return patchRelationship(relationship) + .then(response => new Promise(resolve => { + console.log('patch response', response) + this.$store.dispatch('updateLinkFromRelationship', adapt2vis(response)) + this.modal.showModal = false + this.resetForm() + resolve() + })) + .catch() + + case 'delete': + break + default: + throw "undefined action" } } } diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/VisGraph/api.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/VisGraph/api.js index 0c5d06bff..d7b94d299 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/VisGraph/api.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/VisGraph/api.js @@ -139,10 +139,35 @@ const postRelationship = (fromPerson, toPerson, relation, reverse) => { ) } +/** + * @function patchRelationship + * @param relationship + * @returns {Promise} + */ +const patchRelationship = (relationship) => { + return patchFetch( + `/api/1.0/relations/relationship/${relationship._id}.json`, + { + type: 'relationship', + fromPerson: { type: 'person', + id: fromPerson._id + }, + toPerson: { type: 'person', + id: toPerson._id + }, + relation: { type: 'relation', + id: relation.id + }, + reverse: reverse + } + ) +} + export { getHouseholdByPerson, getCoursesByPerson, getRelationshipsByPerson, getRelationsList, postRelationship, + patchRelationship }