From 21cc0007fb7e28eb52044884ed3a5f6db9cfc259 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Fri, 21 May 2021 18:24:32 +0200 Subject: [PATCH] transformValue to payload, body and method --- .../components/SocialIssue.vue | 33 ++++++++++++++++--- .../vuejs/AccompanyingCourse/store/index.js | 2 +- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/SocialIssue.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/SocialIssue.vue index 20d21e1c0..af283d55e 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/SocialIssue.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/SocialIssue.vue @@ -55,13 +55,36 @@ export default { })).catch(error => this.$store.commit('catchError', error)); }, updateSocialIssues(value) { - console.log('@@@ CHANGE value', value); + console.log('@@@ CHANGED value'); this.$store.dispatch('updateSocialIssues', this.transformValue(value)); }, - transformValue(value) { - let payload = value; - let body = {}; //{ type: "social_issue", id: 5 }; - let method = ''; //'POST' : 'DELETE'; + transformValue(updated) { + let stored = this.value; + //console.log('updated', updated, updated.length); + //console.log('stored', stored, stored.length); + + let added = updated.filter(x => stored.indexOf(x) === -1).shift(); + //console.log('added', added); + + let removed = stored.filter(x => updated.indexOf(x) === -1).shift(); + //console.log('removed', removed); + + let method = (typeof removed === 'undefined') ? 'POST' : 'DELETE'; + console.log('method', method); + + //let concat = (...arrays) => [].concat(...arrays.filter(Array.isArray)); + //let changed = concat(added, removed); + //let changed = [...new Set([...added, ...removed ])]; + + let changed = (typeof removed === 'undefined') ? added : removed; + //console.log('changed', changed); + + let body = { type: "social_issue", id: changed.id }; + + console.log('body', body); + console.log(changed.text); + + let payload = updated; return { payload, body, method }; } } diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js index 3990f8c84..4a0b19334 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js @@ -179,7 +179,7 @@ let initPromise = getAccompanyingCourse(id) })).catch((error) => { commit('catchError', error) }); }, updateSocialIssues({ commit }, { payload, body, method }) { - console.log('## action: payload', { payload, body, method }); + //console.log('## action: payload', { payload, body, method }); //postSocialIssue(id, body, method) //.then(response => new Promise((resolve, reject) => {