From b6bc410346e05c0e002d5fb7e19438518ba85b17 Mon Sep 17 00:00:00 2001 From: kolaente Date: Wed, 7 Jul 2021 22:13:21 +0200 Subject: [PATCH] Add a button to copy an attachment url from the attachment overview --- src/components/tasks/mixins/attachmentUpload.js | 3 ++- src/components/tasks/partials/attachments.vue | 17 ++++++++++++++--- src/helpers/generateAttachmentUrl.js | 3 +++ src/i18n/lang/en.json | 6 +++++- 4 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 src/helpers/generateAttachmentUrl.js diff --git a/src/components/tasks/mixins/attachmentUpload.js b/src/components/tasks/mixins/attachmentUpload.js index 1e08e0fc..4ba36882 100644 --- a/src/components/tasks/mixins/attachmentUpload.js +++ b/src/components/tasks/mixins/attachmentUpload.js @@ -1,5 +1,6 @@ import AttachmentModel from '../../../models/attachment' import AttachmentService from '../../../services/attachment' +import {generateAttachmentUrl} from '@/helpers/generateAttachmentUrl' export default { methods: { @@ -21,7 +22,7 @@ export default { taskId: this.taskId, attachment: a, }) - onSuccess(`${window.API_URL}/tasks/${this.taskId}/attachments/${a.id}`) + onSuccess(generateAttachmentUrl(this.taskId, a.id)) }) } if (r.errors !== null) { diff --git a/src/components/tasks/partials/attachments.vue b/src/components/tasks/partials/attachments.vue index 2f76ae3c..52f49fa6 100644 --- a/src/components/tasks/partials/attachments.vue +++ b/src/components/tasks/partials/attachments.vue @@ -55,14 +55,20 @@

{{ $t('task.attachment.download') }} + + {{ $t('task.attachment.copyUrl') }} + {{ $t('misc.delete') }} @@ -106,7 +112,7 @@ > {{ $t('task.attachment.delete') }}

- {{ $t('task.attachment.deleteText1', {filename: attachmentUpload.file.name}) }}
+ {{ $t('task.attachment.deleteText1', {filename: attachmentToDelete.file.name}) }}
{{ $t('task.attachment.deleteText2') }}

@@ -133,7 +139,9 @@ 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' export default { name: 'attachments', @@ -247,6 +255,9 @@ export default { this.downloadAttachment(attachment) } }, + copyUrl(attachment) { + copy(generateAttachmentUrl(this.taskId, attachment.id)) + }, }, } diff --git a/src/helpers/generateAttachmentUrl.js b/src/helpers/generateAttachmentUrl.js new file mode 100644 index 00000000..40c1e1ef --- /dev/null +++ b/src/helpers/generateAttachmentUrl.js @@ -0,0 +1,3 @@ +export const generateAttachmentUrl = (taskId, attachmentId) => { + return `${window.API_URL}/tasks/${taskId}/attachments/${attachmentId}` +} \ No newline at end of file diff --git a/src/i18n/lang/en.json b/src/i18n/lang/en.json index fdebc189..fe007a66 100644 --- a/src/i18n/lang/en.json +++ b/src/i18n/lang/en.json @@ -529,11 +529,15 @@ "title": "Attachments", "createdBy": "created {0} by {1}", "download": "Download", + "downloadTooltip": "Download this attachment", "upload": "Upload attachment", "drop": "Drop files here to upload", "delete": "Delete attachment", + "deleteTooltip": "Delete this attachment", "deleteText1": "Are you sure you want to delete the attachment {filename}?", - "deleteText2": "This cannot be undone!" + "deleteText2": "This cannot be undone!", + "copyUrl": "Copy URL", + "copyUrlTooltip": "Copy the url of this attachment for usage in text" }, "comment": { "title": "Comments",