2020-02-25 21:11:36 +01:00
|
|
|
<template>
|
2020-08-11 20:18:59 +02:00
|
|
|
<div class="content details" :class="{'has-top-border': canWrite || comments.length > 0}">
|
|
|
|
<h1 v-if="canWrite || comments.length > 0">
|
2020-02-25 21:11:36 +01:00
|
|
|
<span class="icon is-grey">
|
|
|
|
<icon :icon="['far', 'comments']"/>
|
|
|
|
</span>
|
|
|
|
Comments
|
|
|
|
</h1>
|
|
|
|
<div class="comments">
|
2020-07-14 21:26:05 +02:00
|
|
|
<progress class="progress is-small is-info" max="100" v-if="taskCommentService.loading">Loading
|
|
|
|
comments...
|
|
|
|
</progress>
|
2020-02-25 21:11:36 +01:00
|
|
|
<div class="media comment" v-for="c in comments" :key="c.id">
|
|
|
|
<figure class="media-left">
|
2020-03-01 21:58:58 +01:00
|
|
|
<img class="image is-avatar" :src="c.author.getAvatarUrl(48)" alt="" width="48" height="48"/>
|
2020-02-25 21:11:36 +01:00
|
|
|
</figure>
|
|
|
|
<div class="media-content">
|
2020-08-11 20:18:59 +02:00
|
|
|
<div class="comment-info" :class="{'is-pulled-up': canWrite}">
|
2020-02-25 21:11:36 +01:00
|
|
|
<strong>{{ c.author.username }}</strong>
|
|
|
|
<small v-tooltip="formatDate(c.created)">{{ formatDateSince(c.created) }}</small>
|
2020-07-14 21:26:05 +02:00
|
|
|
<small v-if="+new Date(c.created) !== +new Date(c.updated)" v-tooltip="formatDate(c.updated)"> ·
|
|
|
|
edited {{ formatDateSince(c.updated) }}</small>
|
|
|
|
</div>
|
|
|
|
<editor
|
|
|
|
v-model="c.comment"
|
|
|
|
:has-preview="true"
|
|
|
|
@change="() => {toggleEdit(c);editComment()}"
|
|
|
|
:upload-enabled="true"
|
|
|
|
:upload-callback="attachmentUpload"
|
2020-08-11 20:18:59 +02:00
|
|
|
:is-edit-enabled="canWrite"
|
2020-07-14 21:26:05 +02:00
|
|
|
/>
|
2020-08-11 20:18:59 +02:00
|
|
|
<div class="comment-actions" v-if="canWrite">
|
2020-07-14 21:26:05 +02:00
|
|
|
<a @click="toggleDelete(c.id)">Remove</a>
|
2020-02-25 21:11:36 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-08-11 20:18:59 +02:00
|
|
|
<div class="media comment" v-if="canWrite">
|
2020-02-25 21:11:36 +01:00
|
|
|
<figure class="media-left">
|
2020-05-08 20:43:51 +02:00
|
|
|
<img class="image is-avatar" :src="userAvatar" alt="" width="48" height="48"/>
|
2020-02-25 21:11:36 +01:00
|
|
|
</figure>
|
|
|
|
<div class="media-content">
|
|
|
|
<div class="form">
|
|
|
|
<div class="field">
|
2020-07-14 21:26:05 +02:00
|
|
|
<editor
|
|
|
|
placeholder="Add your comment..."
|
|
|
|
:class="{'is-loading': taskCommentService.loading && !isCommentEdit}"
|
|
|
|
v-model="newComment.comment"
|
|
|
|
:has-preview="false"
|
|
|
|
:upload-enabled="true"
|
|
|
|
:upload-callback="attachmentUpload"
|
|
|
|
v-if="editorActive"
|
|
|
|
/>
|
2020-02-25 21:11:36 +01:00
|
|
|
</div>
|
|
|
|
<div class="field">
|
2020-07-14 21:26:05 +02:00
|
|
|
<button class="button is-primary"
|
|
|
|
:class="{'is-loading': taskCommentService.loading && !isCommentEdit}"
|
|
|
|
@click="addComment()" :disabled="newComment.comment === ''">Comment
|
|
|
|
</button>
|
2020-02-25 21:11:36 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<modal
|
|
|
|
v-if="showDeleteModal"
|
|
|
|
@close="showDeleteModal = false"
|
|
|
|
@submit="deleteComment()">
|
|
|
|
<span slot="header">Delete this comment</span>
|
|
|
|
<p slot="text">Are you sure you want to delete this comment?
|
|
|
|
<br/>This <b>CANNOT BE UNDONE!</b></p>
|
|
|
|
</modal>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import TaskCommentService from '../../../services/taskComment'
|
|
|
|
import TaskCommentModel from '../../../models/taskComment'
|
2020-07-14 21:26:05 +02:00
|
|
|
import attachmentUpload from '../mixins/attachmentUpload'
|
2020-07-27 19:53:19 +02:00
|
|
|
import LoadingComponent from '../../misc/loading'
|
|
|
|
import ErrorComponent from '../../misc/error'
|
2020-02-25 21:11:36 +01:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'comments',
|
2020-07-14 21:26:05 +02:00
|
|
|
components: {
|
2020-07-27 19:53:19 +02:00
|
|
|
editor: () => ({
|
|
|
|
component: import(/* webpackPrefetch: true *//* webpackChunkName: "editor" */ '../../input/editor'),
|
|
|
|
loading: LoadingComponent,
|
|
|
|
error: ErrorComponent,
|
|
|
|
timeout: 60000,
|
|
|
|
}),
|
2020-07-14 21:26:05 +02:00
|
|
|
},
|
|
|
|
mixins: [
|
|
|
|
attachmentUpload,
|
|
|
|
],
|
2020-02-25 21:11:36 +01:00
|
|
|
props: {
|
2020-04-17 12:19:53 +02:00
|
|
|
taskId: {
|
2020-02-25 21:11:36 +01:00
|
|
|
type: Number,
|
|
|
|
required: true,
|
2020-08-11 20:18:59 +02:00
|
|
|
},
|
|
|
|
canWrite: {
|
|
|
|
default: true,
|
|
|
|
},
|
2020-02-25 21:11:36 +01:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
comments: [],
|
|
|
|
|
|
|
|
showDeleteModal: false,
|
|
|
|
commentToDelete: TaskCommentModel,
|
|
|
|
|
|
|
|
isCommentEdit: false,
|
|
|
|
commentEdit: TaskCommentModel,
|
|
|
|
|
|
|
|
taskCommentService: TaskCommentService,
|
|
|
|
newComment: TaskCommentModel,
|
2020-07-14 21:26:05 +02:00
|
|
|
editorActive: true,
|
2020-02-25 21:11:36 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
this.taskCommentService = new TaskCommentService()
|
2020-04-17 12:19:53 +02:00
|
|
|
this.newComment = new TaskCommentModel({taskId: this.taskId})
|
|
|
|
this.commentEdit = new TaskCommentModel({taskId: this.taskId})
|
|
|
|
this.commentToDelete = new TaskCommentModel({taskId: this.taskId})
|
2020-02-25 21:11:36 +01:00
|
|
|
this.comments = []
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.loadComments()
|
|
|
|
},
|
2020-03-23 18:29:25 +01:00
|
|
|
watch: {
|
2020-04-17 12:19:53 +02:00
|
|
|
taskId() {
|
2020-03-23 18:29:25 +01:00
|
|
|
this.loadComments()
|
2020-08-11 20:18:59 +02:00
|
|
|
},
|
2020-03-23 18:29:25 +01:00
|
|
|
},
|
2020-05-08 20:43:51 +02:00
|
|
|
computed: {
|
|
|
|
userAvatar() {
|
|
|
|
return this.$store.state.auth.info.getAvatarUrl(48)
|
|
|
|
},
|
|
|
|
},
|
2020-02-25 21:11:36 +01:00
|
|
|
methods: {
|
|
|
|
loadComments() {
|
2020-04-17 12:19:53 +02:00
|
|
|
this.taskCommentService.getAll({taskId: this.taskId})
|
2020-02-25 21:11:36 +01:00
|
|
|
.then(r => {
|
|
|
|
this.$set(this, 'comments', r)
|
|
|
|
})
|
|
|
|
.catch(e => {
|
|
|
|
this.error(e, this)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
addComment() {
|
|
|
|
if (this.newComment.comment === '') {
|
|
|
|
return
|
|
|
|
}
|
2020-07-14 21:26:05 +02:00
|
|
|
|
|
|
|
// This makes the editor trigger its mounted function again which makes it forget every input
|
|
|
|
// it currently has in its textarea. This is a counter-hack to a hack inside of vue-easymde
|
|
|
|
// which made it impossible to detect change from the outside. Therefore the component would
|
|
|
|
// not update if new content from the outside was made available.
|
|
|
|
// See https://github.com/NikulinIlya/vue-easymde/issues/3
|
|
|
|
this.editorActive = false
|
|
|
|
this.$nextTick(() => this.editorActive = true)
|
|
|
|
|
2020-02-25 21:11:36 +01:00
|
|
|
this.taskCommentService.create(this.newComment)
|
|
|
|
.then(r => {
|
|
|
|
this.comments.push(r)
|
|
|
|
this.newComment.comment = ''
|
|
|
|
})
|
|
|
|
.catch(e => {
|
|
|
|
this.error(e, this)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
toggleEdit(comment) {
|
|
|
|
this.isCommentEdit = !this.isCommentEdit
|
|
|
|
this.commentEdit = comment
|
|
|
|
},
|
|
|
|
toggleDelete(commentId) {
|
|
|
|
this.showDeleteModal = !this.showDeleteModal
|
|
|
|
this.commentToDelete.id = commentId
|
|
|
|
},
|
|
|
|
editComment() {
|
|
|
|
if (this.commentEdit.comment === '') {
|
|
|
|
return
|
|
|
|
}
|
2020-04-17 12:19:53 +02:00
|
|
|
this.commentEdit.taskId = this.taskId
|
2020-02-25 21:11:36 +01:00
|
|
|
this.taskCommentService.update(this.commentEdit)
|
|
|
|
.then(r => {
|
|
|
|
for (const c in this.comments) {
|
|
|
|
if (this.comments[c].id === this.commentEdit.id) {
|
|
|
|
this.$set(this.comments, c, r)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(e => {
|
|
|
|
this.error(e, this)
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.isCommentEdit = false
|
|
|
|
})
|
|
|
|
},
|
|
|
|
deleteComment() {
|
|
|
|
this.taskCommentService.delete(this.commentToDelete)
|
2020-06-01 00:09:21 +02:00
|
|
|
.then(() => {
|
2020-02-25 21:11:36 +01:00
|
|
|
for (const a in this.comments) {
|
|
|
|
if (this.comments[a].id === this.commentToDelete.id) {
|
|
|
|
this.comments.splice(a, 1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(e => {
|
|
|
|
this.error(e, this)
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.showDeleteModal = false
|
|
|
|
})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
</script>
|