2020-02-25 21:11:36 +01:00
|
|
|
<template>
|
2020-09-05 22:35:52 +02:00
|
|
|
<div :class="{'has-top-border': canWrite || comments.length > 0}" class="content details">
|
2020-08-11 20:18:59 +02:00
|
|
|
<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-11-15 17:17:08 +01:00
|
|
|
<progress class="progress is-small is-info" max="100" v-if="taskCommentService.loading">
|
|
|
|
Loading comments...
|
2020-07-14 21:26:05 +02:00
|
|
|
</progress>
|
2020-09-05 22:35:52 +02:00
|
|
|
<div :key="c.id" class="media comment" v-for="c in comments">
|
2020-11-15 17:17:08 +01:00
|
|
|
<figure class="media-left is-hidden-mobile">
|
2020-09-05 22:35:52 +02:00
|
|
|
<img :src="c.author.getAvatarUrl(48)" alt="" class="image is-avatar" height="48" width="48"/>
|
2020-02-25 21:11:36 +01:00
|
|
|
</figure>
|
|
|
|
<div class="media-content">
|
2020-11-15 17:17:08 +01:00
|
|
|
<div class="comment-info">
|
|
|
|
<img :src="c.author.getAvatarUrl(20)" alt="" class="image is-avatar" height="20" width="20"/>
|
2020-02-25 21:11:36 +01:00
|
|
|
<strong>{{ c.author.username }}</strong>
|
2020-11-15 17:17:08 +01:00
|
|
|
<span v-tooltip="formatDate(c.created)">{{ formatDateSince(c.created) }}</span>
|
|
|
|
<span v-if="+new Date(c.created) !== +new Date(c.updated)" v-tooltip="formatDate(c.updated)">
|
|
|
|
· edited {{ formatDateSince(c.updated) }}
|
|
|
|
</span>
|
2020-07-14 21:26:05 +02:00
|
|
|
</div>
|
|
|
|
<editor
|
2020-09-05 22:35:52 +02:00
|
|
|
:has-preview="true"
|
|
|
|
:is-edit-enabled="canWrite"
|
|
|
|
:upload-callback="attachmentUpload"
|
|
|
|
:upload-enabled="true"
|
|
|
|
@change="() => {toggleEdit(c);editComment()}"
|
|
|
|
v-model="c.comment"
|
2020-11-15 17:17:08 +01:00
|
|
|
:has-edit-bottom="true"
|
|
|
|
:bottom-actions="actions[c.id]"
|
2020-07-14 21:26:05 +02:00
|
|
|
/>
|
2020-02-25 21:11:36 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-08-11 20:18:59 +02:00
|
|
|
<div class="media comment" v-if="canWrite">
|
2020-11-15 17:17:08 +01:00
|
|
|
<figure class="media-left is-hidden-mobile">
|
2020-09-05 22:35:52 +02:00
|
|
|
<img :src="userAvatar" alt="" class="image is-avatar" height="48" width="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
|
2020-09-05 22:35:52 +02:00
|
|
|
:class="{'is-loading': taskCommentService.loading && !isCommentEdit}"
|
|
|
|
:has-preview="false"
|
|
|
|
:upload-callback="attachmentUpload"
|
|
|
|
:upload-enabled="true"
|
|
|
|
placeholder="Add your comment..."
|
|
|
|
v-if="editorActive"
|
|
|
|
v-model="newComment.comment"
|
2020-07-14 21:26:05 +02:00
|
|
|
/>
|
2020-02-25 21:11:36 +01:00
|
|
|
</div>
|
|
|
|
<div class="field">
|
2020-09-05 22:35:52 +02:00
|
|
|
<button :class="{'is-loading': taskCommentService.loading && !isCommentEdit}"
|
|
|
|
:disabled="newComment.comment === ''"
|
|
|
|
@click="addComment()" class="button is-primary">Comment
|
2020-07-14 21:26:05 +02:00
|
|
|
</button>
|
2020-02-25 21:11:36 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<modal
|
2020-09-05 22:35:52 +02:00
|
|
|
@close="showDeleteModal = false"
|
|
|
|
@submit="deleteComment()"
|
|
|
|
v-if="showDeleteModal">
|
2020-02-25 21:11:36 +01:00
|
|
|
<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>
|
2020-09-05 22:35:52 +02:00
|
|
|
import TaskCommentService from '../../../services/taskComment'
|
|
|
|
import TaskCommentModel from '../../../models/taskComment'
|
|
|
|
import attachmentUpload from '../mixins/attachmentUpload'
|
|
|
|
import LoadingComponent from '../../misc/loading'
|
|
|
|
import ErrorComponent from '../../misc/error'
|
2020-02-25 21:11:36 +01:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
export default {
|
|
|
|
name: 'comments',
|
|
|
|
components: {
|
|
|
|
editor: () => ({
|
2020-11-02 21:47:31 +01:00
|
|
|
component: import(/* webpackChunkName: "editor" */ '../../input/editor'),
|
2020-09-05 22:35:52 +02:00
|
|
|
loading: LoadingComponent,
|
|
|
|
error: ErrorComponent,
|
|
|
|
timeout: 60000,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
mixins: [
|
|
|
|
attachmentUpload,
|
|
|
|
],
|
|
|
|
props: {
|
|
|
|
taskId: {
|
|
|
|
type: Number,
|
|
|
|
required: true,
|
2020-07-14 21:26:05 +02:00
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
canWrite: {
|
|
|
|
default: true,
|
2020-02-25 21:11:36 +01:00
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
comments: [],
|
2020-02-25 21:11:36 +01:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
showDeleteModal: false,
|
|
|
|
commentToDelete: TaskCommentModel,
|
2020-02-25 21:11:36 +01:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
isCommentEdit: false,
|
|
|
|
commentEdit: TaskCommentModel,
|
2020-02-25 21:11:36 +01:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
taskCommentService: TaskCommentService,
|
|
|
|
newComment: TaskCommentModel,
|
|
|
|
editorActive: true,
|
2020-11-15 17:17:08 +01:00
|
|
|
actions: {},
|
2020-09-05 22:35:52 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
this.taskCommentService = new TaskCommentService()
|
|
|
|
this.newComment = new TaskCommentModel({taskId: this.taskId})
|
|
|
|
this.commentEdit = new TaskCommentModel({taskId: this.taskId})
|
|
|
|
this.commentToDelete = new TaskCommentModel({taskId: this.taskId})
|
|
|
|
this.comments = []
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.loadComments()
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
taskId() {
|
2020-02-25 21:11:36 +01:00
|
|
|
this.loadComments()
|
|
|
|
},
|
2020-11-15 17:17:08 +01:00
|
|
|
canWrite() {
|
|
|
|
this.makeActions()
|
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
userAvatar() {
|
|
|
|
return this.$store.state.auth.info.getAvatarUrl(48)
|
2020-03-23 18:29:25 +01:00
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
loadComments() {
|
|
|
|
this.taskCommentService.getAll({taskId: this.taskId})
|
|
|
|
.then(r => {
|
|
|
|
this.$set(this, 'comments', r)
|
2020-11-15 17:17:08 +01:00
|
|
|
this.makeActions()
|
2020-09-05 22:35:52 +02:00
|
|
|
})
|
|
|
|
.catch(e => {
|
|
|
|
this.error(e, this)
|
|
|
|
})
|
2020-05-08 20:43:51 +02:00
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
addComment() {
|
|
|
|
if (this.newComment.comment === '') {
|
|
|
|
return
|
|
|
|
}
|
2020-07-14 21:26:05 +02:00
|
|
|
|
2020-09-05 22:35:52 +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-07-14 21:26:05 +02:00
|
|
|
|
2020-09-05 22:35:52 +02: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
|
|
|
|
}
|
|
|
|
this.commentEdit.taskId = this.taskId
|
|
|
|
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)
|
2020-02-25 21:11:36 +01:00
|
|
|
}
|
2020-09-05 22:35:52 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(e => {
|
|
|
|
this.error(e, this)
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.isCommentEdit = false
|
|
|
|
})
|
|
|
|
},
|
|
|
|
deleteComment() {
|
|
|
|
this.taskCommentService.delete(this.commentToDelete)
|
|
|
|
.then(() => {
|
|
|
|
for (const a in this.comments) {
|
|
|
|
if (this.comments[a].id === this.commentToDelete.id) {
|
|
|
|
this.comments.splice(a, 1)
|
2020-02-25 21:11:36 +01:00
|
|
|
}
|
2020-09-05 22:35:52 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(e => {
|
|
|
|
this.error(e, this)
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.showDeleteModal = false
|
|
|
|
})
|
2020-02-25 21:11:36 +01:00
|
|
|
},
|
2020-11-15 17:17:08 +01:00
|
|
|
makeActions() {
|
|
|
|
if (this.canWrite) {
|
|
|
|
this.comments.forEach(c => {
|
|
|
|
this.$set(this.actions, c.id, [{
|
|
|
|
action: () => this.toggleDelete(c.id),
|
|
|
|
title: 'Remove',
|
|
|
|
}])
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
|
|
|
}
|
2020-02-25 21:11:36 +01:00
|
|
|
</script>
|