mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
add Comment component, make POST comment request
This commit is contained in:
parent
2aa13dceff
commit
e0dc0a8fdb
@ -14,9 +14,8 @@ const datetimeFormats = {
|
|||||||
},
|
},
|
||||||
long: {
|
long: {
|
||||||
year: "numeric",
|
year: "numeric",
|
||||||
month: "short",
|
month: "numeric",
|
||||||
day: "numeric",
|
day: "numeric",
|
||||||
weekday: "short",
|
|
||||||
hour: "numeric",
|
hour: "numeric",
|
||||||
minute: "numeric",
|
minute: "numeric",
|
||||||
hour12: false
|
hour12: false
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
<persons-associated></persons-associated>
|
<persons-associated></persons-associated>
|
||||||
<requestor></requestor>
|
<requestor></requestor>
|
||||||
<resources></resources>
|
<resources></resources>
|
||||||
|
<comment></comment>
|
||||||
<!--test></test-->
|
<!--test></test-->
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -13,6 +14,7 @@ import AccompanyingCourse from './components/AccompanyingCourse.vue';
|
|||||||
import PersonsAssociated from './components/PersonsAssociated.vue';
|
import PersonsAssociated from './components/PersonsAssociated.vue';
|
||||||
import Requestor from './components/Requestor.vue';
|
import Requestor from './components/Requestor.vue';
|
||||||
import Resources from './components/Resources.vue';
|
import Resources from './components/Resources.vue';
|
||||||
|
import Comment from './components/Comment.vue';
|
||||||
//import Test from './components/Test.vue';
|
//import Test from './components/Test.vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@ -22,6 +24,7 @@ export default {
|
|||||||
PersonsAssociated,
|
PersonsAssociated,
|
||||||
Requestor,
|
Requestor,
|
||||||
Resources,
|
Resources,
|
||||||
|
Comment,
|
||||||
//Test
|
//Test
|
||||||
},
|
},
|
||||||
computed: mapState([
|
computed: mapState([
|
||||||
|
@ -121,18 +121,27 @@ const postResource = (id, payload, method) => {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Endpoint v.2 chill_api_single_accompanying_course_comment,
|
* Endpoint v.2 chill_api_single_accompanying_course_comment,
|
||||||
* method POST/DELETE, add/remove a comment to the accompanyingCourse
|
* method POST/DELETE/PATCH, add/remove a comment to the accompanyingCourse
|
||||||
*
|
*
|
||||||
* @id integer - id of accompanyingCourse
|
* @id integer - id of accompanyingCourse
|
||||||
* @payload
|
* @payload
|
||||||
* @method string - POST or DELETE
|
* @method string - POST, DELETE or PATCH
|
||||||
*/
|
*/
|
||||||
const postComment = (id, payload, method) => {
|
const postComment = (id, payload) => {
|
||||||
console.log('payload', 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);
|
console.log('body', body);
|
||||||
const url = `/1.0/person/accompanying-course/${id}/comment.json`;
|
const url = `/api/1.0/person/accompanying-course/${id}/comment.json`;
|
||||||
return fetch(url, {
|
return fetch(url, {
|
||||||
method: method,
|
method: payload.method,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json;charset=utf-8'
|
'Content-Type': 'application/json;charset=utf-8'
|
||||||
},
|
},
|
||||||
@ -142,7 +151,7 @@ const postComment = (id, payload, method) => {
|
|||||||
if (response.ok) { return response.json(); }
|
if (response.ok) { return response.json(); }
|
||||||
throw Error('Error with request resource response');
|
throw Error('Error with request resource response');
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
export {
|
export {
|
||||||
getAccompanyingCourse,
|
getAccompanyingCourse,
|
||||||
|
@ -0,0 +1,76 @@
|
|||||||
|
<template>
|
||||||
|
<div class="vue-component">
|
||||||
|
<h3>{{ $t('comment.title') }}</h3>
|
||||||
|
|
||||||
|
<div class="error flash_message" v-if="errors.length > 0">
|
||||||
|
{{ errors[0] }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="firstComment">
|
||||||
|
créé par {{ firstComment.creator.text }}
|
||||||
|
le {{ $d(firstComment.createdAt.datetime, 'long') }}
|
||||||
|
<div v-if="firstComment.updatedAt.datetime !== firstComment.createdAt.datetime">
|
||||||
|
modifié par {{ firstComment.updatedBy.text }}
|
||||||
|
le {{ $d(firstComment.updatedAt.datetime, 'long') }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form @submit.prevent="submitform">
|
||||||
|
<textarea
|
||||||
|
name="content"
|
||||||
|
v-bind:placeholder="$t('comment.content')"
|
||||||
|
rows="8"
|
||||||
|
cols="80"
|
||||||
|
ckeditor="ckeditor"
|
||||||
|
v-model="content">
|
||||||
|
</textarea>
|
||||||
|
<button type="submit" class="sc-button bt-save">{{ $t('action.save') }}</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: "Comment",
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
formdata: {
|
||||||
|
content: ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
comments() {
|
||||||
|
return this.$store.state.accompanyingCourse.comments;
|
||||||
|
},
|
||||||
|
firstComment() {
|
||||||
|
return this.comments[0];
|
||||||
|
},
|
||||||
|
content: {
|
||||||
|
set(value) {
|
||||||
|
this.formdata.content = value;
|
||||||
|
},
|
||||||
|
get() {
|
||||||
|
return (this.comments.length > 0) ? this.comments[0].content : null ;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
errors() {
|
||||||
|
return this.$store.state.errorMsg;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
submitform() {
|
||||||
|
this.formdata['method'] = (!this.firstComment)? 'POST' : 'PATCH';
|
||||||
|
this.$store.dispatch('postFirstComment', this.formdata);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* TODO
|
||||||
|
* - patch endpoint to update Content
|
||||||
|
* - delete/reset button ?
|
||||||
|
* - manage flash messages => specific component ?
|
||||||
|
* - ckeditor
|
||||||
|
*/
|
||||||
|
</script>
|
@ -54,6 +54,10 @@ const appMessages = {
|
|||||||
text: "Dénomination",
|
text: "Dénomination",
|
||||||
description: "Description",
|
description: "Description",
|
||||||
add_resources: "Ajouter des interlocuteurs",
|
add_resources: "Ajouter des interlocuteurs",
|
||||||
|
},
|
||||||
|
comment: {
|
||||||
|
title: "Ajout d'une note",
|
||||||
|
content: "Rédigez une première note..."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -4,7 +4,8 @@ import { getAccompanyingCourse,
|
|||||||
patchAccompanyingCourse,
|
patchAccompanyingCourse,
|
||||||
postParticipation,
|
postParticipation,
|
||||||
postRequestor,
|
postRequestor,
|
||||||
postResource } from '../api';
|
postResource,
|
||||||
|
postComment } from '../api';
|
||||||
|
|
||||||
const debug = process.env.NODE_ENV !== 'production';
|
const debug = process.env.NODE_ENV !== 'production';
|
||||||
const id = window.accompanyingCourseId;
|
const id = window.accompanyingCourseId;
|
||||||
@ -68,6 +69,9 @@ let initPromise = getAccompanyingCourse(id)
|
|||||||
toggleConfidential(state, value) {
|
toggleConfidential(state, value) {
|
||||||
//console.log('### mutation: toggleConfidential');
|
//console.log('### mutation: toggleConfidential');
|
||||||
state.accompanyingCourse.confidential = value;
|
state.accompanyingCourse.confidential = value;
|
||||||
|
},
|
||||||
|
postFirstComment(state, comment) {
|
||||||
|
state.accompanyingCourse.comments.push(comment);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
@ -145,6 +149,13 @@ let initPromise = getAccompanyingCourse(id)
|
|||||||
commit('toggleConfidential', course.confidential);
|
commit('toggleConfidential', course.confidential);
|
||||||
resolve();
|
resolve();
|
||||||
})).catch((error) => { commit('catchError', error) });
|
})).catch((error) => { commit('catchError', error) });
|
||||||
|
},
|
||||||
|
postFirstComment({ commit }, payload) {
|
||||||
|
postComment(id, payload)
|
||||||
|
.then(comment => new Promise((resolve, reject) => {
|
||||||
|
commit('postFirstComment', comment);
|
||||||
|
resolve();
|
||||||
|
})).catch((error) => { commit('catchError', error) });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user