Properly insert files to description

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2020-12-30 07:23:05 +01:00
parent 32b2823538
commit 82e2621eb1
2 changed files with 21 additions and 5 deletions

View File

@@ -69,7 +69,7 @@
</ActionButton> </ActionButton>
</Actions> </Actions>
<Actions v-if="removable" :force-menu="true"> <Actions v-if="removable" :force-menu="true">
<ActionLink v-if="attachment.extendedData.fileid" icon="icon-folder" :href="'/index.php/f/'+attachment.extendedData.fileid"> <ActionLink v-if="attachment.extendedData.fileid" icon="icon-folder" :href="internalLink(attachment)">
{{ t('deck', 'Show in files') }} {{ t('deck', 'Show in files') }}
</ActionLink> </ActionLink>
<ActionButton v-if="attachment.extendedData.fileid" icon="icon-delete"> <ActionButton v-if="attachment.extendedData.fileid" icon="icon-delete">
@@ -160,6 +160,9 @@ export default {
attachmentUrl() { attachmentUrl() {
return (attachment) => generateUrl(`/apps/deck/cards/${attachment.cardId}/attachment/${attachment.id}`) return (attachment) => generateUrl(`/apps/deck/cards/${attachment.cardId}/attachment/${attachment.id}`)
}, },
internalLink() {
return (attachment) => generateUrl('/index.php/f/' + attachment.extendedData.fileid)
},
formattedFileSize() { formattedFileSize() {
return (filesize) => formatFileSize(filesize) return (filesize) => formatFileSize(filesize)
}, },

View File

@@ -140,7 +140,17 @@ export default {
} }
}, },
attachmentUrl() { attachmentUrl() {
return (attachment) => generateUrl(`/apps/deck/cards/${attachment.cardId}/attachment/${attachment.id}`) return (attachment) => {
if (attachment.extendedData.fileid) {
return generateUrl('/f/' + attachment.extendedData.fileid)
}
return generateUrl(`/apps/deck/cards/${attachment.cardId}/attachment/${attachment.id}`)
}
},
attachmentPreview() {
return (attachment) => (attachment.extendedData.fileid
? generateUrl(`/core/preview?fileId=${attachment.extendedData.fileid}&x=600&y=600&a=true`)
: generateUrl(`/apps/deck/cards/${attachment.cardId}/attachment/${attachment.id}`))
}, },
formattedFileSize() { formattedFileSize() {
return (filesize) => formatFileSize(filesize) return (filesize) => formatFileSize(filesize)
@@ -169,12 +179,15 @@ export default {
addAttachment(attachment) { addAttachment(attachment) {
const descString = this.$refs.markdownEditor.easymde.value() const descString = this.$refs.markdownEditor.easymde.value()
let embed = '' let embed = ''
if (attachment.extendedData.mimetype.includes('image')) { if ((attachment.type === 'file' && attachment.extendedData.hasPreview) || attachment.extendedData.mimetype.includes('image')) {
embed = '!' embed = '!'
} }
const attachmentString = embed + '[📎 ' + attachment.data + '](' + this.attachmentUrl(attachment) + ')' const attachmentString = embed + '[📎 ' + attachment.data + '](' + this.attachmentPreview(attachment) + ')'
this.$refs.markdownEditor.easymde.value(descString + '\n' + attachmentString) const newContent = descString + '\n' + attachmentString
this.$refs.markdownEditor.easymde.value(newContent)
this.description = newContent
this.modalShow = false this.modalShow = false
this.updateDescription()
}, },
clickedPreview(e) { clickedPreview(e) {
if (e.target.getAttribute('type') === 'checkbox') { if (e.target.getAttribute('type') === 'checkbox') {