Make sure attachements are only added once to the list after uploading

+ Make sure the attachment list shows up every time after adding an attachment
This commit is contained in:
kolaente 2021-01-18 21:58:34 +01:00
parent a0664ecb29
commit 0b23e91f8d
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B
4 changed files with 19 additions and 33 deletions

View file

@ -302,8 +302,6 @@ export default {
}, },
createOrSelectOnEnter() { createOrSelectOnEnter() {
console.log('enter', this.creatableAvailable, this.searchResults.length)
if (!this.creatableAvailable && this.searchResults.length === 1) { if (!this.creatableAvailable && this.searchResults.length === 1) {
this.select(this.searchResults[0]) this.select(this.searchResults[0])
return return

View file

@ -8,13 +8,20 @@ export default {
const attachmentService = new AttachmentService() const attachmentService = new AttachmentService()
this.createAttachment(attachmentService, files, onSuccess)
},
createAttachment(attachmentService, files, onSuccess = () => {}) {
const attachmentModel = new AttachmentModel({taskId: this.taskId}) const attachmentModel = new AttachmentModel({taskId: this.taskId})
attachmentService.create(attachmentModel, files) attachmentService.create(attachmentModel, files)
.then(r => { .then(r => {
if (r.success !== null) { if (r.success !== null) {
r.success.forEach(a => { r.success.forEach(a => {
this.$store.commit('attachments/removeById', a.id)
this.$store.commit('attachments/add', a) this.$store.commit('attachments/add', a)
this.$store.dispatch('tasks/addTaskAttachment', {taskId: this.taskId, attachment: a}) this.$store.dispatch('tasks/addTaskAttachment', {
taskId: this.taskId,
attachment: a,
})
onSuccess(`${window.API_URL}/tasks/${this.taskId}/attachments/${a.id}`) onSuccess(`${window.API_URL}/tasks/${this.taskId}/attachments/${a.id}`)
}) })
} }

View file

@ -56,18 +56,13 @@
</p> </p>
<p> <p>
<a <a
@click="downloadAttachment(a)" @click.prevent.stop="downloadAttachment(a)"
v-tooltip="'Download this attachment'" v-tooltip="'Download this attachment'"
> >
Download Download
</a> </a>
<a <a
@click=" @click.prevent.stop="() => {attachmentToDelete = a; showDeleteModal = true}"
() => {
attachmentToDelete = a
showDeleteModal = true
}
"
v-if="editEnabled" v-if="editEnabled"
v-tooltip="'Delete this attachment'" v-tooltip="'Delete this attachment'"
> >
@ -138,6 +133,7 @@
import AttachmentService from '../../../services/attachment' import AttachmentService from '../../../services/attachment'
import AttachmentModel from '../../../models/attachment' import AttachmentModel from '../../../models/attachment'
import User from '../../misc/user' import User from '../../misc/user'
import attachmentUpload from '@/components/tasks/mixins/attachmentUpload'
import { mapState } from 'vuex' import { mapState } from 'vuex'
export default { export default {
@ -145,6 +141,9 @@ export default {
components: { components: {
User, User,
}, },
mixins: [
attachmentUpload,
],
data() { data() {
return { return {
attachmentService: AttachmentService, attachmentService: AttachmentService,
@ -215,28 +214,7 @@ export default {
this.uploadFiles(this.$refs.files.files) this.uploadFiles(this.$refs.files.files)
}, },
uploadFiles(files) { uploadFiles(files) {
const attachmentModel = new AttachmentModel({ taskId: this.taskId }) this.createAttachment(this.attachmentService, files)
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() { deleteAttachment() {
this.attachmentService this.attachmentService

View file

@ -200,7 +200,7 @@
</div> </div>
<!-- Attachments --> <!-- Attachments -->
<div class="content attachments" v-if="activeFields.attachments"> <div class="content attachments" v-if="activeFields.attachments || hasAttachments">
<attachments <attachments
:edit-enabled="canWrite" :edit-enabled="canWrite"
:task-id="taskId" :task-id="taskId"
@ -524,6 +524,9 @@ export default {
doneFormatted() { doneFormatted() {
return this.formatDate(this.task.doneAt) return this.formatDate(this.task.doneAt)
}, },
hasAttachments() {
return this.$store.state.attachments.attachments.length > 0
},
}, },
methods: { methods: {
loadTask() { loadTask() {