From 0b23e91f8dc3565deaff8c55beba166e959da1a4 Mon Sep 17 00:00:00 2001
From: kolaente
Date: Mon, 18 Jan 2021 21:58:34 +0100
Subject: [PATCH] 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
---
src/components/input/multiselect.vue | 2 --
.../tasks/mixins/attachmentUpload.js | 9 ++++-
src/components/tasks/partials/attachments.vue | 36 ++++---------------
src/views/tasks/TaskDetailView.vue | 5 ++-
4 files changed, 19 insertions(+), 33 deletions(-)
diff --git a/src/components/input/multiselect.vue b/src/components/input/multiselect.vue
index 2e908b26d..7498b9b04 100644
--- a/src/components/input/multiselect.vue
+++ b/src/components/input/multiselect.vue
@@ -302,8 +302,6 @@ export default {
},
createOrSelectOnEnter() {
- console.log('enter', this.creatableAvailable, this.searchResults.length)
-
if (!this.creatableAvailable && this.searchResults.length === 1) {
this.select(this.searchResults[0])
return
diff --git a/src/components/tasks/mixins/attachmentUpload.js b/src/components/tasks/mixins/attachmentUpload.js
index 08580f62e..d08226f86 100644
--- a/src/components/tasks/mixins/attachmentUpload.js
+++ b/src/components/tasks/mixins/attachmentUpload.js
@@ -8,13 +8,20 @@ export default {
const attachmentService = new AttachmentService()
+ this.createAttachment(attachmentService, files, onSuccess)
+ },
+ createAttachment(attachmentService, files, onSuccess = () => {}) {
const attachmentModel = new AttachmentModel({taskId: this.taskId})
attachmentService.create(attachmentModel, files)
.then(r => {
if (r.success !== null) {
r.success.forEach(a => {
+ this.$store.commit('attachments/removeById', a.id)
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}`)
})
}
diff --git a/src/components/tasks/partials/attachments.vue b/src/components/tasks/partials/attachments.vue
index 1224a923b..519da02c5 100644
--- a/src/components/tasks/partials/attachments.vue
+++ b/src/components/tasks/partials/attachments.vue
@@ -56,18 +56,13 @@
Download
{
- attachmentToDelete = a
- showDeleteModal = true
- }
- "
+ @click.prevent.stop="() => {attachmentToDelete = a; showDeleteModal = true}"
v-if="editEnabled"
v-tooltip="'Delete this attachment'"
>
@@ -138,6 +133,7 @@
import AttachmentService from '../../../services/attachment'
import AttachmentModel from '../../../models/attachment'
import User from '../../misc/user'
+import attachmentUpload from '@/components/tasks/mixins/attachmentUpload'
import { mapState } from 'vuex'
export default {
@@ -145,6 +141,9 @@ export default {
components: {
User,
},
+ mixins: [
+ attachmentUpload,
+ ],
data() {
return {
attachmentService: AttachmentService,
@@ -215,28 +214,7 @@ export default {
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)
- })
+ this.createAttachment(this.attachmentService, files)
},
deleteAttachment() {
this.attachmentService
diff --git a/src/views/tasks/TaskDetailView.vue b/src/views/tasks/TaskDetailView.vue
index 854d4fc9b..9dd229eea 100644
--- a/src/views/tasks/TaskDetailView.vue
+++ b/src/views/tasks/TaskDetailView.vue
@@ -200,7 +200,7 @@
-
+
0
+ },
},
methods: {
loadTask() {