From 09304b7fe7011c468bb518867d3c45850f961aa3 Mon Sep 17 00:00:00 2001 From: Dominik Pschenitschni Date: Fri, 27 Aug 2021 15:55:09 +0200 Subject: [PATCH] feat: remove attachmentUpload mixin replaced instead with a helper. preparation for possible future use of composition api --- .../tasks/mixins/attachmentUpload.js | 39 ------------------- src/components/tasks/partials/attachments.vue | 9 ++--- src/components/tasks/partials/comments.vue | 7 +++- src/helpers/attachments.ts | 36 +++++++++++++++++ src/helpers/generateAttachmentUrl.js | 3 -- src/store/modules/tasks.js | 9 ++--- src/views/tasks/TaskDetailView.vue | 10 +++-- 7 files changed, 54 insertions(+), 59 deletions(-) delete mode 100644 src/components/tasks/mixins/attachmentUpload.js create mode 100644 src/helpers/attachments.ts delete mode 100644 src/helpers/generateAttachmentUrl.js diff --git a/src/components/tasks/mixins/attachmentUpload.js b/src/components/tasks/mixins/attachmentUpload.js deleted file mode 100644 index 4ba368822..000000000 --- a/src/components/tasks/mixins/attachmentUpload.js +++ /dev/null @@ -1,39 +0,0 @@ -import AttachmentModel from '../../../models/attachment' -import AttachmentService from '../../../services/attachment' -import {generateAttachmentUrl} from '@/helpers/generateAttachmentUrl' - -export default { - methods: { - attachmentUpload(file, onSuccess) { - const files = [file] - - 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 => { - console.debug(`Uploaded attachments for task ${this.taskId}, response was`, r) - if (r.success !== null) { - r.success.forEach(a => { - this.$store.dispatch('tasks/addTaskAttachment', { - taskId: this.taskId, - attachment: a, - }) - onSuccess(generateAttachmentUrl(this.taskId, a.id)) - }) - } - if (r.errors !== null) { - r.errors.forEach(m => { - this.error(m) - }) - } - }) - .catch(e => { - this.error(e) - }) - }, - }, -} \ No newline at end of file diff --git a/src/components/tasks/partials/attachments.vue b/src/components/tasks/partials/attachments.vue index aa93494f7..1e6e82b10 100644 --- a/src/components/tasks/partials/attachments.vue +++ b/src/components/tasks/partials/attachments.vue @@ -138,19 +138,16 @@ import AttachmentService from '../../../services/attachment' import AttachmentModel from '../../../models/attachment' import User from '../../misc/user' -import attachmentUpload from '@/components/tasks/mixins/attachmentUpload' -import {generateAttachmentUrl} from '@/helpers/generateAttachmentUrl' import {mapState} from 'vuex' import copy from 'copy-to-clipboard' +import { uploadFiles, generateAttachmentUrl } from '@/helpers/attachments' + export default { name: 'attachments', components: { User, }, - mixins: [ - attachmentUpload, - ], data() { return { attachmentService: AttachmentService, @@ -221,7 +218,7 @@ export default { this.uploadFiles(this.$refs.files.files) }, uploadFiles(files) { - this.createAttachment(this.attachmentService, files) + uploadFiles(this.attachmentService, this.taskId, files) }, deleteAttachment() { this.attachmentService diff --git a/src/components/tasks/partials/comments.vue b/src/components/tasks/partials/comments.vue index e0379c1e4..433e362a9 100644 --- a/src/components/tasks/partials/comments.vue +++ b/src/components/tasks/partials/comments.vue @@ -151,9 +151,9 @@