2019-11-24 14:16:24 +01:00
|
|
|
<template>
|
|
|
|
<div class="attachments">
|
|
|
|
<h3>
|
|
|
|
<span class="icon is-grey">
|
2021-01-23 18:54:22 +01:00
|
|
|
<icon icon="paperclip"/>
|
2019-11-24 14:16:24 +01:00
|
|
|
</span>
|
2021-06-24 01:24:57 +02:00
|
|
|
{{ $t('task.attachment.title') }}
|
2019-11-24 14:16:24 +01:00
|
|
|
</h3>
|
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
<input
|
|
|
|
:disabled="attachmentService.loading"
|
|
|
|
@change="uploadNewAttachment()"
|
|
|
|
id="files"
|
|
|
|
multiple
|
|
|
|
ref="files"
|
|
|
|
type="file"
|
2021-01-17 18:57:57 +01:00
|
|
|
v-if="editEnabled"
|
|
|
|
/>
|
2020-09-05 22:35:52 +02:00
|
|
|
<progress
|
|
|
|
:value="attachmentService.uploadProgress"
|
|
|
|
class="progress is-primary"
|
|
|
|
max="100"
|
2021-01-17 18:57:57 +01:00
|
|
|
v-if="attachmentService.uploadProgress > 0"
|
|
|
|
>
|
2020-09-05 22:35:52 +02:00
|
|
|
{{ attachmentService.uploadProgress }}%
|
|
|
|
</progress>
|
2019-11-24 14:16:24 +01:00
|
|
|
|
2021-01-15 23:33:43 +01:00
|
|
|
<div class="files" v-if="attachments.length > 0">
|
2021-01-16 22:15:48 +01:00
|
|
|
<a
|
|
|
|
class="attachment"
|
|
|
|
v-for="a in attachments"
|
|
|
|
:key="a.id"
|
2021-01-17 18:57:57 +01:00
|
|
|
@click="viewOrDownload(a)"
|
|
|
|
>
|
2021-01-15 23:33:43 +01:00
|
|
|
<div class="filename">{{ a.file.name }}</div>
|
|
|
|
<div class="info">
|
|
|
|
<p class="collapses">
|
2021-06-24 01:24:57 +02:00
|
|
|
<i18n path="task.attachment.createdBy">
|
|
|
|
<span v-tooltip="formatDate(a.created)">
|
|
|
|
{{ formatDateSince(a.created) }}
|
|
|
|
</span>
|
2021-01-17 18:57:57 +01:00
|
|
|
<user
|
|
|
|
:avatar-size="24"
|
|
|
|
:user="a.createdBy"
|
|
|
|
:is-inline="true"
|
|
|
|
/>
|
2021-06-24 01:24:57 +02:00
|
|
|
</i18n>
|
2021-01-15 23:33:43 +01:00
|
|
|
<span>
|
|
|
|
{{ a.file.getHumanSize() }}
|
|
|
|
</span>
|
|
|
|
<span v-if="a.file.mime">
|
|
|
|
{{ a.file.mime }}
|
|
|
|
</span>
|
|
|
|
</p>
|
|
|
|
<p>
|
2020-09-05 22:35:52 +02:00
|
|
|
<a
|
2021-01-18 21:58:34 +01:00
|
|
|
@click.prevent.stop="downloadAttachment(a)"
|
2021-07-07 22:13:21 +02:00
|
|
|
v-tooltip="$t('task.attachment.downloadTooltip')"
|
2021-01-17 18:57:57 +01:00
|
|
|
>
|
2021-06-24 01:24:57 +02:00
|
|
|
{{ $t('task.attachment.download') }}
|
2019-11-24 14:16:24 +01:00
|
|
|
</a>
|
2021-07-07 22:13:21 +02:00
|
|
|
<a
|
|
|
|
@click.stop="copyUrl(a)"
|
|
|
|
v-tooltip="$t('task.attachment.copyUrlTooltip')"
|
|
|
|
>
|
|
|
|
{{ $t('task.attachment.copyUrl') }}
|
|
|
|
</a>
|
2020-09-05 22:35:52 +02:00
|
|
|
<a
|
2021-01-18 21:58:34 +01:00
|
|
|
@click.prevent.stop="() => {attachmentToDelete = a; showDeleteModal = true}"
|
2021-01-15 23:33:43 +01:00
|
|
|
v-if="editEnabled"
|
2021-07-07 22:13:21 +02:00
|
|
|
v-tooltip="$t('task.attachment.deleteTooltip')"
|
2021-01-17 18:57:57 +01:00
|
|
|
>
|
2021-06-24 01:24:57 +02:00
|
|
|
{{ $t('misc.delete') }}
|
2019-11-24 14:16:24 +01:00
|
|
|
</a>
|
2021-01-15 23:33:43 +01:00
|
|
|
</p>
|
|
|
|
</div>
|
2021-01-16 22:15:48 +01:00
|
|
|
</a>
|
2021-01-15 23:33:43 +01:00
|
|
|
</div>
|
|
|
|
|
2021-01-17 18:57:57 +01:00
|
|
|
<x-button
|
|
|
|
v-if="editEnabled"
|
2021-01-15 23:33:43 +01:00
|
|
|
:disabled="attachmentService.loading"
|
|
|
|
@click="$refs.files.click()"
|
2021-01-17 18:57:57 +01:00
|
|
|
class="mb-4"
|
|
|
|
icon="cloud-upload-alt"
|
|
|
|
type="secondary"
|
|
|
|
:shadow="false"
|
|
|
|
>
|
2021-06-24 01:24:57 +02:00
|
|
|
{{ $t('task.attachment.upload') }}
|
2021-01-17 18:57:57 +01:00
|
|
|
</x-button>
|
2019-11-24 14:16:24 +01:00
|
|
|
|
|
|
|
<!-- Dropzone -->
|
2021-01-17 18:57:57 +01:00
|
|
|
<div
|
|
|
|
:class="{ hidden: !showDropzone }"
|
|
|
|
class="dropzone"
|
|
|
|
v-if="editEnabled"
|
|
|
|
>
|
2019-11-24 14:16:24 +01:00
|
|
|
<div class="drop-hint">
|
|
|
|
<div class="icon">
|
2021-01-23 18:54:22 +01:00
|
|
|
<icon icon="cloud-upload-alt"/>
|
2019-11-24 14:16:24 +01:00
|
|
|
</div>
|
2021-06-24 01:24:57 +02:00
|
|
|
<div class="hint">{{ $t('task.attachment.drop') }}</div>
|
2019-11-24 14:16:24 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- Delete modal -->
|
2021-01-23 18:54:22 +01:00
|
|
|
<transition name="modal">
|
|
|
|
<modal
|
|
|
|
@close="showDeleteModal = false"
|
|
|
|
v-if="showDeleteModal"
|
|
|
|
@submit="deleteAttachment()"
|
|
|
|
>
|
2021-06-24 01:24:57 +02:00
|
|
|
<span slot="header">{{ $t('task.attachment.delete') }}</span>
|
2021-01-23 18:54:22 +01:00
|
|
|
<p slot="text">
|
2021-07-07 22:13:21 +02:00
|
|
|
{{ $t('task.attachment.deleteText1', {filename: attachmentToDelete.file.name}) }}<br/>
|
2021-06-24 01:24:57 +02:00
|
|
|
<strong>{{ $t('task.attachment.deleteText2') }}</strong>
|
2021-01-23 18:54:22 +01:00
|
|
|
</p>
|
|
|
|
</modal>
|
|
|
|
</transition>
|
2021-01-16 22:15:48 +01:00
|
|
|
|
|
|
|
<transition name="modal">
|
|
|
|
<modal
|
2021-01-17 18:57:57 +01:00
|
|
|
@close="
|
|
|
|
() => {
|
|
|
|
showImageModal = false
|
|
|
|
attachmentImageBlobUrl = null
|
|
|
|
}
|
|
|
|
"
|
2021-01-16 22:15:48 +01:00
|
|
|
v-if="showImageModal"
|
|
|
|
>
|
2021-01-23 18:54:22 +01:00
|
|
|
<img :src="attachmentImageBlobUrl" alt=""/>
|
2021-01-16 22:15:48 +01:00
|
|
|
</modal>
|
|
|
|
</transition>
|
2019-11-24 14:16:24 +01:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-09-05 22:35:52 +02:00
|
|
|
import AttachmentService from '../../../services/attachment'
|
|
|
|
import AttachmentModel from '../../../models/attachment'
|
|
|
|
import User from '../../misc/user'
|
2021-01-18 21:58:34 +01:00
|
|
|
import attachmentUpload from '@/components/tasks/mixins/attachmentUpload'
|
2021-07-07 22:13:21 +02:00
|
|
|
import {generateAttachmentUrl} from '@/helpers/generateAttachmentUrl'
|
2021-01-23 18:54:22 +01:00
|
|
|
import {mapState} from 'vuex'
|
2021-07-07 22:13:21 +02:00
|
|
|
import copy from 'copy-to-clipboard'
|
2019-11-24 14:16:24 +01:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
export default {
|
|
|
|
name: 'attachments',
|
|
|
|
components: {
|
|
|
|
User,
|
|
|
|
},
|
2021-01-18 21:58:34 +01:00
|
|
|
mixins: [
|
|
|
|
attachmentUpload,
|
|
|
|
],
|
2020-09-05 22:35:52 +02:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
attachmentService: AttachmentService,
|
|
|
|
showDropzone: false,
|
2019-11-24 14:16:24 +01:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
showDeleteModal: false,
|
|
|
|
attachmentToDelete: AttachmentModel,
|
2021-01-16 22:15:48 +01:00
|
|
|
|
|
|
|
showImageModal: false,
|
|
|
|
attachmentImageBlobUrl: null,
|
2020-09-05 22:35:52 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
taskId: {
|
|
|
|
required: true,
|
|
|
|
type: Number,
|
2019-11-24 14:16:24 +01:00
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
initialAttachments: {
|
|
|
|
type: Array,
|
2019-11-24 14:16:24 +01:00
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
editEnabled: {
|
|
|
|
default: true,
|
2019-11-24 14:16:24 +01:00
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
|
|
|
created() {
|
|
|
|
this.attachmentService = new AttachmentService()
|
|
|
|
},
|
|
|
|
computed: mapState({
|
2021-01-17 18:57:57 +01:00
|
|
|
attachments: (state) => state.attachments.attachments,
|
2020-09-05 22:35:52 +02:00
|
|
|
}),
|
|
|
|
mounted() {
|
2021-01-17 18:57:57 +01:00
|
|
|
document.addEventListener('dragenter', (e) => {
|
2020-09-05 22:35:52 +02:00
|
|
|
e.stopPropagation()
|
|
|
|
e.preventDefault()
|
|
|
|
this.showDropzone = true
|
|
|
|
})
|
2019-11-24 14:16:24 +01:00
|
|
|
|
2021-01-17 18:57:57 +01:00
|
|
|
window.addEventListener('dragleave', (e) => {
|
2020-09-05 22:35:52 +02:00
|
|
|
e.stopPropagation()
|
|
|
|
e.preventDefault()
|
|
|
|
this.showDropzone = false
|
|
|
|
})
|
2019-11-24 14:16:24 +01:00
|
|
|
|
2021-01-17 18:57:57 +01:00
|
|
|
document.addEventListener('dragover', (e) => {
|
2020-09-05 22:35:52 +02:00
|
|
|
e.stopPropagation()
|
|
|
|
e.preventDefault()
|
|
|
|
this.showDropzone = true
|
|
|
|
})
|
2019-11-24 14:16:24 +01:00
|
|
|
|
2021-01-17 18:57:57 +01:00
|
|
|
document.addEventListener('drop', (e) => {
|
2020-09-05 22:35:52 +02:00
|
|
|
e.stopPropagation()
|
|
|
|
e.preventDefault()
|
2019-11-24 14:16:24 +01:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
let files = e.dataTransfer.files
|
|
|
|
this.uploadFiles(files)
|
|
|
|
this.showDropzone = false
|
|
|
|
})
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
downloadAttachment(attachment) {
|
|
|
|
this.attachmentService.download(attachment)
|
2019-11-24 14:16:24 +01:00
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
uploadNewAttachment() {
|
|
|
|
if (this.$refs.files.files.length === 0) {
|
|
|
|
return
|
|
|
|
}
|
2019-11-24 14:16:24 +01:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
this.uploadFiles(this.$refs.files.files)
|
|
|
|
},
|
|
|
|
uploadFiles(files) {
|
2021-01-18 21:58:34 +01:00
|
|
|
this.createAttachment(this.attachmentService, files)
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
|
|
|
deleteAttachment() {
|
2021-01-17 18:57:57 +01:00
|
|
|
this.attachmentService
|
|
|
|
.delete(this.attachmentToDelete)
|
|
|
|
.then((r) => {
|
|
|
|
this.$store.commit(
|
|
|
|
'attachments/removeById',
|
2021-07-17 23:21:46 +02:00
|
|
|
this.attachmentToDelete.id,
|
2021-01-17 18:57:57 +01:00
|
|
|
)
|
2021-06-22 22:07:57 +02:00
|
|
|
this.success(r)
|
2020-09-05 22:35:52 +02:00
|
|
|
})
|
2021-01-17 18:57:57 +01: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
|
|
|
|
})
|
2019-11-24 14:16:24 +01:00
|
|
|
},
|
2021-01-16 22:15:48 +01:00
|
|
|
viewOrDownload(attachment) {
|
2021-01-17 18:57:57 +01:00
|
|
|
if (
|
|
|
|
attachment.file.name.endsWith('.jpg') ||
|
2021-01-16 22:15:48 +01:00
|
|
|
attachment.file.name.endsWith('.png') ||
|
|
|
|
attachment.file.name.endsWith('.bmp') ||
|
2021-01-17 18:57:57 +01:00
|
|
|
attachment.file.name.endsWith('.gif')
|
|
|
|
) {
|
2021-01-16 22:15:48 +01:00
|
|
|
this.showImageModal = true
|
2021-01-17 18:57:57 +01:00
|
|
|
this.attachmentService.getBlobUrl(attachment).then((url) => {
|
|
|
|
this.attachmentImageBlobUrl = url
|
|
|
|
})
|
2021-01-16 22:15:48 +01:00
|
|
|
} else {
|
|
|
|
this.downloadAttachment(attachment)
|
|
|
|
}
|
|
|
|
},
|
2021-07-07 22:13:21 +02:00
|
|
|
copyUrl(attachment) {
|
|
|
|
copy(generateAttachmentUrl(this.taskId, attachment.id))
|
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
|
|
|
}
|
2019-11-24 14:16:24 +01:00
|
|
|
</script>
|