Add a button to copy an attachment url from the attachment overview

This commit is contained in:
kolaente 2021-07-07 22:13:21 +02:00
parent ac6082a670
commit b6bc410346
Signed by untrusted user: konrad
GPG Key ID: F40E70337AB24C9B
4 changed files with 24 additions and 5 deletions

View File

@ -1,5 +1,6 @@
import AttachmentModel from '../../../models/attachment' import AttachmentModel from '../../../models/attachment'
import AttachmentService from '../../../services/attachment' import AttachmentService from '../../../services/attachment'
import {generateAttachmentUrl} from '@/helpers/generateAttachmentUrl'
export default { export default {
methods: { methods: {
@ -21,7 +22,7 @@ export default {
taskId: this.taskId, taskId: this.taskId,
attachment: a, attachment: a,
}) })
onSuccess(`${window.API_URL}/tasks/${this.taskId}/attachments/${a.id}`) onSuccess(generateAttachmentUrl(this.taskId, a.id))
}) })
} }
if (r.errors !== null) { if (r.errors !== null) {

View File

@ -55,14 +55,20 @@
<p> <p>
<a <a
@click.prevent.stop="downloadAttachment(a)" @click.prevent.stop="downloadAttachment(a)"
v-tooltip="'Download this attachment'" v-tooltip="$t('task.attachment.downloadTooltip')"
> >
{{ $t('task.attachment.download') }} {{ $t('task.attachment.download') }}
</a> </a>
<a
@click.stop="copyUrl(a)"
v-tooltip="$t('task.attachment.copyUrlTooltip')"
>
{{ $t('task.attachment.copyUrl') }}
</a>
<a <a
@click.prevent.stop="() => {attachmentToDelete = a; showDeleteModal = true}" @click.prevent.stop="() => {attachmentToDelete = a; showDeleteModal = true}"
v-if="editEnabled" v-if="editEnabled"
v-tooltip="'Delete this attachment'" v-tooltip="$t('task.attachment.deleteTooltip')"
> >
{{ $t('misc.delete') }} {{ $t('misc.delete') }}
</a> </a>
@ -106,7 +112,7 @@
> >
<span slot="header">{{ $t('task.attachment.delete') }}</span> <span slot="header">{{ $t('task.attachment.delete') }}</span>
<p slot="text"> <p slot="text">
{{ $t('task.attachment.deleteText1', {filename: attachmentUpload.file.name}) }}<br/> {{ $t('task.attachment.deleteText1', {filename: attachmentToDelete.file.name}) }}<br/>
<strong>{{ $t('task.attachment.deleteText2') }}</strong> <strong>{{ $t('task.attachment.deleteText2') }}</strong>
</p> </p>
</modal> </modal>
@ -133,7 +139,9 @@ 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 attachmentUpload from '@/components/tasks/mixins/attachmentUpload'
import {generateAttachmentUrl} from '@/helpers/generateAttachmentUrl'
import {mapState} from 'vuex' import {mapState} from 'vuex'
import copy from 'copy-to-clipboard'
export default { export default {
name: 'attachments', name: 'attachments',
@ -247,6 +255,9 @@ export default {
this.downloadAttachment(attachment) this.downloadAttachment(attachment)
} }
}, },
copyUrl(attachment) {
copy(generateAttachmentUrl(this.taskId, attachment.id))
},
}, },
} }
</script> </script>

View File

@ -0,0 +1,3 @@
export const generateAttachmentUrl = (taskId, attachmentId) => {
return `${window.API_URL}/tasks/${taskId}/attachments/${attachmentId}`
}

View File

@ -529,11 +529,15 @@
"title": "Attachments", "title": "Attachments",
"createdBy": "created {0} by {1}", "createdBy": "created {0} by {1}",
"download": "Download", "download": "Download",
"downloadTooltip": "Download this attachment",
"upload": "Upload attachment", "upload": "Upload attachment",
"drop": "Drop files here to upload", "drop": "Drop files here to upload",
"delete": "Delete attachment", "delete": "Delete attachment",
"deleteTooltip": "Delete this attachment",
"deleteText1": "Are you sure you want to delete the attachment {filename}?", "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": { "comment": {
"title": "Comments", "title": "Comments",