diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/api.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/api.js
index 40e883968..5e3210536 100644
--- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/api.js
+++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/api.js
@@ -119,45 +119,10 @@ const postResource = (id, payload, method) => {
});
};
-/*
-* Endpoint v.2 chill_api_single_accompanying_course_comment,
-* method POST/DELETE/PATCH, add/remove a comment to the accompanyingCourse
-*
-* @id integer - id of accompanyingCourse
-* @payload
-* @method string - POST, DELETE or PATCH
-*/
-const postComment = (id, payload) => {
- console.log('payload', payload);
- const body = { type: "accompanying_period_comment" };
- switch (payload.method) {
- case 'POST':
- body['content'] = payload.content;
- break;
- case 'DELETE':
- body['id'] = 42;
- break;
- }
- console.log('body', body);
- const url = `/api/1.0/person/accompanying-course/${id}/comment.json`;
- return fetch(url, {
- method: payload.method,
- headers: {
- 'Content-Type': 'application/json;charset=utf-8'
- },
- body: JSON.stringify(body)
- })
- .then(response => {
- if (response.ok) { return response.json(); }
- throw Error('Error with request resource response');
- });
-};
-
export {
getAccompanyingCourse,
patchAccompanyingCourse,
postParticipation,
postRequestor,
postResource,
- postComment
};
diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Comment.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Comment.vue
index f1ccf7667..dd0c223c4 100644
--- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Comment.vue
+++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Comment.vue
@@ -6,12 +6,12 @@
{{ errors[0] }}
-
- créé par {{ firstComment.creator.text }}
- le {{ $d(firstComment.createdAt.datetime, 'long') }}
-
- modifié par {{ firstComment.updatedBy.text }}
- le {{ $d(firstComment.updatedAt.datetime, 'long') }}
+
+ créé par {{ initialComment.creator.text }}
+ le {{ $d(initialComment.createdAt.datetime, 'long') }}
+
+ modifié par {{ initialComment.updatedBy.text }}
+ le {{ $d(initialComment.updatedAt.datetime, 'long') }}
@@ -28,9 +28,17 @@
+
+
+
+
@@ -40,23 +48,21 @@ export default {
data() {
return {
formdata: {
+ type: "accompanying_period_comment",
content: ''
}
}
},
computed: {
- comments() {
- return this.$store.state.accompanyingCourse.comments;
- },
- firstComment() {
- return this.comments[0];
+ initialComment() {
+ return this.$store.state.accompanyingCourse.initialComment;
},
content: {
set(value) {
this.formdata.content = value;
},
get() {
- return (this.comments.length > 0) ? this.comments[0].content : null ;
+ return (this.initialComment)? this.initialComment.content : null;
}
},
errors() {
@@ -65,8 +71,12 @@ export default {
},
methods: {
submitform() {
- this.formdata['method'] = (!this.firstComment)? 'POST' : 'PATCH';
+ console.log('submit');
this.$store.dispatch('postFirstComment', this.formdata);
+ },
+ removeComment() {
+ console.log('remove');
+ this.$store.dispatch('postFirstComment', null);
}
}
}
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 ebaf52de2..9efdd8d81 100644
--- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js
+++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js
@@ -4,8 +4,7 @@ import { getAccompanyingCourse,
patchAccompanyingCourse,
postParticipation,
postRequestor,
- postResource,
- postComment } from '../api';
+ postResource } from '../api';
const debug = process.env.NODE_ENV !== 'production';
const id = window.accompanyingCourseId;
@@ -74,7 +73,8 @@ let initPromise = getAccompanyingCourse(id)
state.accompanyingCourse.confidential = value;
},
postFirstComment(state, comment) {
- state.accompanyingCourse.comments.push(comment);
+ console.log('### mutation: postFirstComment', comment);
+ state.accompanyingCourse.initialComment = comment;
}
},
actions: {
@@ -162,9 +162,10 @@ let initPromise = getAccompanyingCourse(id)
})).catch((error) => { commit('catchError', error) });
},
postFirstComment({ commit }, payload) {
- postComment(id, payload)
- .then(comment => new Promise((resolve, reject) => {
- commit('postFirstComment', comment);
+ console.log('## action: postFirstComment: payload', payload);
+ patchAccompanyingCourse(id, { type: "accompanying_period", initialComment: payload })
+ .then(course => new Promise((resolve, reject) => {
+ commit('postFirstComment', course.initialComment);
resolve();
})).catch((error) => { commit('catchError', error) });
}