2020-02-25 20:11:36 +00:00
|
|
|
<template>
|
2021-01-16 21:55:43 +01:00
|
|
|
<div class="content details">
|
|
|
|
<h3 v-if="canWrite || comments.length > 0">
|
2020-02-25 20:11:36 +00:00
|
|
|
<span class="icon is-grey">
|
2021-01-23 18:54:22 +01:00
|
|
|
<icon :icon="['far', 'comments']"/>
|
2020-02-25 20:11:36 +00:00
|
|
|
</span>
|
2021-06-23 23:24:57 +00:00
|
|
|
{{ $t('task.comment.title') }}
|
2021-01-16 21:55:43 +01:00
|
|
|
</h3>
|
2020-02-25 20:11:36 +00:00
|
|
|
<div class="comments">
|
2021-01-17 17:57:57 +00:00
|
|
|
<span
|
|
|
|
class="is-inline-flex is-align-items-center"
|
2021-06-23 23:24:57 +00:00
|
|
|
v-if="taskCommentService.loading && saving === null && !creating"
|
2021-01-17 17:57:57 +00:00
|
|
|
>
|
2020-11-22 16:32:35 +00:00
|
|
|
<span class="loader is-inline-block mr-2"></span>
|
2021-06-23 23:24:57 +00:00
|
|
|
{{ $t('task.comment.loading') }}
|
2020-11-22 16:32:35 +00:00
|
|
|
</span>
|
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">
|
2021-01-17 17:57:57 +00:00
|
|
|
<img
|
|
|
|
:src="c.author.getAvatarUrl(48)"
|
|
|
|
alt=""
|
|
|
|
class="image is-avatar"
|
|
|
|
height="48"
|
|
|
|
width="48"
|
|
|
|
/>
|
2020-02-25 20:11:36 +00:00
|
|
|
</figure>
|
|
|
|
<div class="media-content">
|
2020-11-15 17:17:08 +01:00
|
|
|
<div class="comment-info">
|
2021-01-17 17:57:57 +00:00
|
|
|
<img
|
|
|
|
:src="c.author.getAvatarUrl(20)"
|
|
|
|
alt=""
|
|
|
|
class="image is-avatar"
|
|
|
|
height="20"
|
|
|
|
width="20"
|
|
|
|
/>
|
2021-06-23 23:24:57 +00:00
|
|
|
<strong>{{ c.author.getDisplayName() }}</strong>
|
2021-04-18 18:50:29 +02:00
|
|
|
<span v-tooltip="formatDate(c.created)" class="has-text-grey">
|
|
|
|
{{ formatDateSince(c.created) }}
|
|
|
|
</span>
|
2021-01-17 17:57:57 +00:00
|
|
|
<span
|
|
|
|
v-if="+new Date(c.created) !== +new Date(c.updated)"
|
|
|
|
v-tooltip="formatDate(c.updated)"
|
|
|
|
>
|
2021-06-23 23:24:57 +00:00
|
|
|
· {{ $t('task.comment.edited', {date: formatDateSince(c.updated)}) }}
|
2020-11-15 17:17:08 +01:00
|
|
|
</span>
|
2020-11-22 16:32:35 +00:00
|
|
|
<transition name="fade">
|
2021-01-17 17:57:57 +00:00
|
|
|
<span
|
|
|
|
class="is-inline-flex"
|
|
|
|
v-if="
|
|
|
|
taskCommentService.loading &&
|
|
|
|
saving === c.id
|
|
|
|
"
|
|
|
|
>
|
2021-06-23 23:24:57 +00:00
|
|
|
<span class="loader is-inline-block mr-2"></span>
|
|
|
|
{{ $t('misc.saving') }}
|
2020-11-22 16:32:35 +00:00
|
|
|
</span>
|
2021-01-17 17:57:57 +00:00
|
|
|
<span
|
|
|
|
class="has-text-success"
|
|
|
|
v-if="
|
|
|
|
!taskCommentService.loading &&
|
|
|
|
saved === c.id
|
|
|
|
"
|
|
|
|
>
|
2021-06-23 23:24:57 +00:00
|
|
|
{{ $t('misc.saved') }}
|
2020-11-22 16:32:35 +00:00
|
|
|
</span>
|
|
|
|
</transition>
|
2020-07-14 19:26:05 +00:00
|
|
|
</div>
|
|
|
|
<editor
|
2020-09-05 22:35:52 +02:00
|
|
|
:has-preview="true"
|
|
|
|
:is-edit-enabled="canWrite"
|
|
|
|
:upload-callback="attachmentUpload"
|
|
|
|
:upload-enabled="true"
|
2021-01-17 17:57:57 +00:00
|
|
|
@change="
|
|
|
|
() => {
|
|
|
|
toggleEdit(c)
|
|
|
|
editComment()
|
|
|
|
}
|
|
|
|
"
|
2020-09-05 22:35:52 +02:00
|
|
|
v-model="c.comment"
|
2020-11-15 17:17:08 +01:00
|
|
|
:has-edit-bottom="true"
|
|
|
|
:bottom-actions="actions[c.id]"
|
2020-07-14 19:26:05 +00:00
|
|
|
/>
|
2020-02-25 20:11:36 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-08-11 18:18:59 +00:00
|
|
|
<div class="media comment" v-if="canWrite">
|
2020-11-15 17:17:08 +01:00
|
|
|
<figure class="media-left is-hidden-mobile">
|
2021-01-17 17:57:57 +00:00
|
|
|
<img
|
|
|
|
:src="userAvatar"
|
|
|
|
alt=""
|
|
|
|
class="image is-avatar"
|
|
|
|
height="48"
|
|
|
|
width="48"
|
|
|
|
/>
|
2020-02-25 20:11:36 +00:00
|
|
|
</figure>
|
|
|
|
<div class="media-content">
|
|
|
|
<div class="form">
|
2020-11-22 16:32:35 +00:00
|
|
|
<transition name="fade">
|
2021-01-17 17:57:57 +00:00
|
|
|
<span
|
|
|
|
class="is-inline-flex"
|
|
|
|
v-if="taskCommentService.loading && creating"
|
|
|
|
>
|
2021-06-23 23:24:57 +00:00
|
|
|
<span class="loader is-inline-block mr-2"></span>
|
|
|
|
{{ $t('task.comment.creating') }}
|
2020-11-22 16:32:35 +00:00
|
|
|
</span>
|
|
|
|
</transition>
|
2020-02-25 20:11:36 +00:00
|
|
|
<div class="field">
|
2020-07-14 19:26:05 +00:00
|
|
|
<editor
|
2021-01-17 17:57:57 +00:00
|
|
|
:class="{
|
|
|
|
'is-loading':
|
|
|
|
taskCommentService.loading &&
|
|
|
|
!isCommentEdit,
|
|
|
|
}"
|
2020-09-05 22:35:52 +02:00
|
|
|
:has-preview="false"
|
|
|
|
:upload-callback="attachmentUpload"
|
|
|
|
:upload-enabled="true"
|
2021-06-23 23:24:57 +00:00
|
|
|
:placeholder="$t('task.comment.placeholder')"
|
2020-09-05 22:35:52 +02:00
|
|
|
v-if="editorActive"
|
|
|
|
v-model="newComment.comment"
|
2020-07-14 19:26:05 +00:00
|
|
|
/>
|
2020-02-25 20:11:36 +00:00
|
|
|
</div>
|
|
|
|
<div class="field">
|
2021-01-17 17:57:57 +00:00
|
|
|
<x-button
|
2021-06-23 23:24:57 +00:00
|
|
|
:loading="taskCommentService.loading && !isCommentEdit"
|
2021-01-17 17:57:57 +00:00
|
|
|
:disabled="newComment.comment === ''"
|
|
|
|
@click="addComment()"
|
|
|
|
>
|
2021-06-23 23:24:57 +00:00
|
|
|
{{ $t('task.comment.comment') }}
|
2021-01-17 17:57:57 +00:00
|
|
|
</x-button>
|
2020-02-25 20:11:36 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-01-23 18:54:22 +01:00
|
|
|
|
|
|
|
<transition name="modal">
|
|
|
|
<modal
|
|
|
|
@close="showDeleteModal = false"
|
|
|
|
@submit="deleteComment()"
|
|
|
|
v-if="showDeleteModal"
|
|
|
|
>
|
2021-06-23 23:24:57 +00:00
|
|
|
<span slot="header">{{ $t('task.comment.delete') }}</span>
|
2021-01-23 18:54:22 +01:00
|
|
|
<p slot="text">
|
2021-06-23 23:24:57 +00:00
|
|
|
{{ $t('task.comment.deleteText1') }}<br/>
|
|
|
|
<strong>{{ $t('task.comment.deleteText2') }}</strong>
|
2021-01-23 18:54:22 +01:00
|
|
|
</p>
|
|
|
|
</modal>
|
|
|
|
</transition>
|
2020-02-25 20:11:36 +00:00
|
|
|
</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 20:11:36 +00:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
export default {
|
|
|
|
name: 'comments',
|
|
|
|
components: {
|
|
|
|
editor: () => ({
|
2021-04-25 17:34:49 +02:00
|
|
|
component: import(/* webpackChunkName: "editor" */ '../../input/editor'),
|
2020-09-05 22:35:52 +02:00
|
|
|
loading: LoadingComponent,
|
|
|
|
error: ErrorComponent,
|
|
|
|
timeout: 60000,
|
|
|
|
}),
|
|
|
|
},
|
2021-01-17 17:57:57 +00:00
|
|
|
mixins: [attachmentUpload],
|
2020-09-05 22:35:52 +02:00
|
|
|
props: {
|
|
|
|
taskId: {
|
|
|
|
type: Number,
|
|
|
|
required: true,
|
2020-07-14 19:26:05 +00:00
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
canWrite: {
|
|
|
|
default: true,
|
2020-02-25 20:11:36 +00:00
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
comments: [],
|
2020-02-25 20:11:36 +00:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
showDeleteModal: false,
|
|
|
|
commentToDelete: TaskCommentModel,
|
2020-02-25 20:11:36 +00:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
isCommentEdit: false,
|
|
|
|
commentEdit: TaskCommentModel,
|
2020-02-25 20:11:36 +00: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-11-22 16:32:35 +00:00
|
|
|
|
|
|
|
saved: null,
|
|
|
|
saving: null,
|
|
|
|
creating: false,
|
2020-09-05 22:35:52 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
this.taskCommentService = new TaskCommentService()
|
2021-01-23 18:54:22 +01:00
|
|
|
this.newComment = new TaskCommentModel({taskId: this.taskId})
|
|
|
|
this.commentEdit = new TaskCommentModel({taskId: this.taskId})
|
|
|
|
this.commentToDelete = new TaskCommentModel({taskId: this.taskId})
|
2020-09-05 22:35:52 +02:00
|
|
|
this.comments = []
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.loadComments()
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
taskId() {
|
2020-02-25 20:11:36 +00: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() {
|
2021-01-17 17:57:57 +00:00
|
|
|
this.taskCommentService
|
2021-01-23 18:54:22 +01:00
|
|
|
.getAll({taskId: this.taskId})
|
2021-04-25 17:34:49 +02:00
|
|
|
.then(r => {
|
2020-09-05 22:35:52 +02:00
|
|
|
this.$set(this, 'comments', r)
|
2020-11-15 17:17:08 +01:00
|
|
|
this.makeActions()
|
2020-09-05 22:35:52 +02:00
|
|
|
})
|
2021-01-17 17:57:57 +00:00
|
|
|
.catch((e) => {
|
2021-06-22 22:07:57 +02:00
|
|
|
this.error(e)
|
2020-09-05 22:35:52 +02:00
|
|
|
})
|
2020-05-08 18:43:51 +00:00
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
addComment() {
|
|
|
|
if (this.newComment.comment === '') {
|
|
|
|
return
|
|
|
|
}
|
2020-07-14 19:26:05 +00: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
|
2021-01-17 17:57:57 +00:00
|
|
|
this.$nextTick(() => (this.editorActive = true))
|
2020-11-22 16:32:35 +00:00
|
|
|
this.creating = true
|
2020-07-14 19:26:05 +00:00
|
|
|
|
2021-01-17 17:57:57 +00:00
|
|
|
this.taskCommentService
|
|
|
|
.create(this.newComment)
|
|
|
|
.then((r) => {
|
2020-09-05 22:35:52 +02:00
|
|
|
this.comments.push(r)
|
|
|
|
this.newComment.comment = ''
|
2021-06-23 23:24:57 +00:00
|
|
|
this.success({message: this.$t('task.comment.addedSuccess')})
|
2020-09-05 22:35:52 +02:00
|
|
|
})
|
2021-01-17 17:57:57 +00:00
|
|
|
.catch((e) => {
|
2021-06-22 22:07:57 +02:00
|
|
|
this.error(e)
|
2020-09-05 22:35:52 +02:00
|
|
|
})
|
2020-11-22 16:32:35 +00:00
|
|
|
.finally(() => {
|
|
|
|
this.creating = false
|
|
|
|
})
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
|
|
|
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-11-22 16:32:35 +00:00
|
|
|
|
|
|
|
this.saving = this.commentEdit.id
|
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
this.commentEdit.taskId = this.taskId
|
2021-01-17 17:57:57 +00:00
|
|
|
this.taskCommentService
|
|
|
|
.update(this.commentEdit)
|
|
|
|
.then((r) => {
|
2020-09-05 22:35:52 +02:00
|
|
|
for (const c in this.comments) {
|
|
|
|
if (this.comments[c].id === this.commentEdit.id) {
|
|
|
|
this.$set(this.comments, c, r)
|
2020-02-25 20:11:36 +00:00
|
|
|
}
|
2020-09-05 22:35:52 +02:00
|
|
|
}
|
2020-11-22 16:32:35 +00:00
|
|
|
this.saved = this.commentEdit.id
|
|
|
|
setTimeout(() => {
|
|
|
|
this.saved = null
|
|
|
|
}, 2000)
|
2020-09-05 22:35:52 +02:00
|
|
|
})
|
2021-01-17 17:57:57 +00:00
|
|
|
.catch((e) => {
|
2021-06-22 22:07:57 +02:00
|
|
|
this.error(e)
|
2020-09-05 22:35:52 +02:00
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.isCommentEdit = false
|
2020-11-22 16:32:35 +00:00
|
|
|
this.saving = null
|
2020-09-05 22:35:52 +02:00
|
|
|
})
|
|
|
|
},
|
|
|
|
deleteComment() {
|
2021-01-17 17:57:57 +00:00
|
|
|
this.taskCommentService
|
|
|
|
.delete(this.commentToDelete)
|
2020-09-05 22:35:52 +02:00
|
|
|
.then(() => {
|
|
|
|
for (const a in this.comments) {
|
|
|
|
if (this.comments[a].id === this.commentToDelete.id) {
|
|
|
|
this.comments.splice(a, 1)
|
2020-02-25 20:11:36 +00:00
|
|
|
}
|
2020-09-05 22:35:52 +02:00
|
|
|
}
|
|
|
|
})
|
2021-01-17 17:57:57 +00:00
|
|
|
.catch((e) => {
|
2021-06-22 22:07:57 +02:00
|
|
|
this.error(e)
|
2020-09-05 22:35:52 +02:00
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.showDeleteModal = false
|
|
|
|
})
|
2020-02-25 20:11:36 +00:00
|
|
|
},
|
2020-11-15 17:17:08 +01:00
|
|
|
makeActions() {
|
|
|
|
if (this.canWrite) {
|
2021-01-17 17:57:57 +00:00
|
|
|
this.comments.forEach((c) => {
|
|
|
|
this.$set(this.actions, c.id, [
|
|
|
|
{
|
|
|
|
action: () => this.toggleDelete(c.id),
|
2021-06-23 23:24:57 +00:00
|
|
|
title: this.$t('misc.delete'),
|
2021-01-17 17:57:57 +00:00
|
|
|
},
|
|
|
|
])
|
2020-11-15 17:17:08 +01:00
|
|
|
})
|
|
|
|
}
|
2021-01-17 17:57:57 +00:00
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
|
|
|
}
|
2020-02-25 20:11:36 +00:00
|
|
|
</script>
|