2019-11-24 14:16:24 +01:00
|
|
|
<template>
|
|
|
|
<div class="attachments">
|
|
|
|
<h3>
|
|
|
|
<span class="icon is-grey">
|
|
|
|
<icon icon="paperclip"/>
|
|
|
|
</span>
|
|
|
|
Attachments
|
|
|
|
<a
|
2020-09-05 22:35:52 +02:00
|
|
|
:disabled="attachmentService.loading"
|
|
|
|
@click="$refs.files.click()"
|
|
|
|
class="button is-primary is-outlined is-small noshadow"
|
|
|
|
v-if="editEnabled">
|
2019-11-24 14:16:24 +01:00
|
|
|
<span class="icon is-small"><icon icon="cloud-upload-alt"/></span>
|
|
|
|
Upload attachment
|
|
|
|
</a>
|
|
|
|
</h3>
|
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
<input
|
|
|
|
:disabled="attachmentService.loading"
|
|
|
|
@change="uploadNewAttachment()"
|
|
|
|
id="files"
|
|
|
|
multiple
|
|
|
|
ref="files"
|
|
|
|
type="file"
|
|
|
|
v-if="editEnabled"/>
|
|
|
|
<progress
|
|
|
|
:value="attachmentService.uploadProgress"
|
|
|
|
class="progress is-primary"
|
|
|
|
max="100"
|
|
|
|
v-if="attachmentService.uploadProgress > 0">
|
|
|
|
{{ attachmentService.uploadProgress }}%
|
|
|
|
</progress>
|
2019-11-24 14:16:24 +01:00
|
|
|
|
|
|
|
<table>
|
|
|
|
<tr>
|
|
|
|
<th>Name</th>
|
|
|
|
<th>Size</th>
|
|
|
|
<th>Type</th>
|
|
|
|
<th>Date</th>
|
2020-03-04 20:35:00 +01:00
|
|
|
<th>Created By</th>
|
2019-11-24 14:16:24 +01:00
|
|
|
<th>Action</th>
|
|
|
|
</tr>
|
2020-09-05 22:35:52 +02:00
|
|
|
<tr :key="a.id" class="attachment" v-for="a in attachments">
|
2019-11-24 14:16:24 +01:00
|
|
|
<td>
|
|
|
|
{{ a.file.name }}
|
|
|
|
</td>
|
|
|
|
<td>{{ a.file.getHumanSize() }}</td>
|
|
|
|
<td>{{ a.file.mime }}</td>
|
2020-01-30 21:49:00 +01:00
|
|
|
<td v-tooltip="formatDate(a.created)">{{ formatDateSince(a.created) }}</td>
|
2020-09-05 22:35:52 +02:00
|
|
|
<td>
|
|
|
|
<user :avatar-size="30" :user="a.createdBy"/>
|
|
|
|
</td>
|
2019-11-24 14:16:24 +01:00
|
|
|
<td>
|
|
|
|
<div class="buttons has-addons">
|
2020-09-05 22:35:52 +02:00
|
|
|
<a
|
|
|
|
@click="downloadAttachment(a)"
|
|
|
|
class="button is-primary noshadow"
|
|
|
|
v-tooltip="'Download this attachment'">
|
2019-11-24 14:16:24 +01:00
|
|
|
<span class="icon">
|
|
|
|
<icon icon="cloud-download-alt"/>
|
|
|
|
</span>
|
|
|
|
</a>
|
2020-09-05 22:35:52 +02:00
|
|
|
<a
|
|
|
|
@click="() => {attachmentToDelete = a; showDeleteModal = true}"
|
|
|
|
class="button is-danger noshadow" v-if="editEnabled"
|
|
|
|
v-tooltip="'Delete this attachment'">
|
2019-11-24 14:16:24 +01:00
|
|
|
<span class="icon">
|
|
|
|
<icon icon="trash-alt"/>
|
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
|
|
|
|
<!-- Dropzone -->
|
2020-09-05 22:35:52 +02: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">
|
|
|
|
<icon icon="cloud-upload-alt"/>
|
|
|
|
</div>
|
|
|
|
<div class="hint">
|
|
|
|
Drop files here to upload
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- Delete modal -->
|
|
|
|
<modal
|
2020-09-05 22:35:52 +02:00
|
|
|
@close="showDeleteModal = false"
|
|
|
|
v-if="showDeleteModal"
|
|
|
|
v-on:submit="deleteAttachment()">
|
2019-11-24 14:16:24 +01:00
|
|
|
<span slot="header">Delete attachment</span>
|
|
|
|
<p slot="text">Are you sure you want to delete the attachment {{ attachmentToDelete.file.name }}?<br/>
|
|
|
|
<b>This CANNOT BE UNDONE!</b></p>
|
|
|
|
</modal>
|
|
|
|
</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'
|
|
|
|
import {mapState} from 'vuex'
|
2019-11-24 14:16:24 +01:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
export default {
|
|
|
|
name: 'attachments',
|
|
|
|
components: {
|
|
|
|
User,
|
|
|
|
},
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
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({
|
|
|
|
attachments: state => state.attachments.attachments,
|
|
|
|
}),
|
|
|
|
mounted() {
|
|
|
|
document.addEventListener('dragenter', e => {
|
|
|
|
e.stopPropagation()
|
|
|
|
e.preventDefault()
|
|
|
|
this.showDropzone = true
|
|
|
|
})
|
2019-11-24 14:16:24 +01:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
window.addEventListener('dragleave', e => {
|
|
|
|
e.stopPropagation()
|
|
|
|
e.preventDefault()
|
|
|
|
this.showDropzone = false
|
|
|
|
})
|
2019-11-24 14:16:24 +01:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
document.addEventListener('dragover', e => {
|
|
|
|
e.stopPropagation()
|
|
|
|
e.preventDefault()
|
|
|
|
this.showDropzone = true
|
|
|
|
})
|
2019-11-24 14:16:24 +01:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
document.addEventListener('drop', e => {
|
|
|
|
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) {
|
|
|
|
const attachmentModel = new AttachmentModel({taskId: this.taskId})
|
|
|
|
this.attachmentService.create(attachmentModel, files)
|
|
|
|
.then(r => {
|
|
|
|
if (r.success !== null) {
|
|
|
|
r.success.forEach(a => {
|
|
|
|
this.$store.commit('attachments/add', a)
|
|
|
|
this.$store.dispatch('tasks/addTaskAttachment', {taskId: this.taskId, attachment: a})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if (r.errors !== null) {
|
|
|
|
r.errors.forEach(m => {
|
|
|
|
this.error(m)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(e => {
|
|
|
|
this.error(e, this)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
deleteAttachment() {
|
|
|
|
this.attachmentService.delete(this.attachmentToDelete)
|
|
|
|
.then(r => {
|
|
|
|
this.$store.commit('attachments/removeById', this.attachmentToDelete.id)
|
|
|
|
this.success(r, this)
|
|
|
|
})
|
|
|
|
.catch(e => {
|
|
|
|
this.error(e, this)
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.showDeleteModal = false
|
|
|
|
})
|
2019-11-24 14:16:24 +01:00
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
|
|
|
}
|
2019-11-24 14:16:24 +01:00
|
|
|
</script>
|