Add view image modal for image attachments

This commit is contained in:
kolaente 2021-01-16 22:15:48 +01:00
parent e473a6b70b
commit b644c00f59
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B
3 changed files with 45 additions and 4 deletions

View file

@ -1,8 +1,9 @@
<template> <template>
<transition name="modal"> <transition name="modal">
<div class="modal-mask"> <div class="modal-mask">
<div class="modal-container"> <div class="modal-container" @click.prevent.stop="$emit('close')">
<div class="modal-content"> <div class="modal-content">
<slot>
<div class="header"> <div class="header">
<slot name="header"></slot> <slot name="header"></slot>
</div> </div>
@ -13,6 +14,7 @@
<button @click="$emit('close')" class="button is-danger is-inverted noshadow">Cancel</button> <button @click="$emit('close')" class="button is-danger is-inverted noshadow">Cancel</button>
<button @click="$emit('submit')" class="button is-success noshadow">Do it!</button> <button @click="$emit('submit')" class="button is-success noshadow">Do it!</button>
</div> </div>
</slot>
</div> </div>
</div> </div>
</div> </div>

View file

@ -24,7 +24,11 @@
</progress> </progress>
<div class="files" v-if="attachments.length > 0"> <div class="files" v-if="attachments.length > 0">
<div :key="a.id" class="attachment" v-for="a in attachments"> <a
class="attachment"
v-for="a in attachments"
:key="a.id"
@click="viewOrDownload(a)">
<div class="filename">{{ a.file.name }}</div> <div class="filename">{{ a.file.name }}</div>
<div class="info"> <div class="info">
<p class="collapses"> <p class="collapses">
@ -53,7 +57,7 @@
</a> </a>
</p> </p>
</div> </div>
</div> </a>
</div> </div>
<a <a
@ -86,6 +90,15 @@
<p slot="text">Are you sure you want to delete the attachment {{ attachmentToDelete.file.name }}?<br/> <p slot="text">Are you sure you want to delete the attachment {{ attachmentToDelete.file.name }}?<br/>
<b>This CANNOT BE UNDONE!</b></p> <b>This CANNOT BE UNDONE!</b></p>
</modal> </modal>
<transition name="modal">
<modal
@close="() => {showImageModal = false; attachmentImageBlobUrl = null}"
v-if="showImageModal"
>
<img :src="attachmentImageBlobUrl" alt=""/>
</modal>
</transition>
</div> </div>
</template> </template>
@ -107,6 +120,9 @@ export default {
showDeleteModal: false, showDeleteModal: false,
attachmentToDelete: AttachmentModel, attachmentToDelete: AttachmentModel,
showImageModal: false,
attachmentImageBlobUrl: null,
} }
}, },
props: { props: {
@ -199,6 +215,20 @@ export default {
this.showDeleteModal = false this.showDeleteModal = false
}) })
}, },
viewOrDownload(attachment) {
if (attachment.file.name.endsWith('.jpg') ||
attachment.file.name.endsWith('.png') ||
attachment.file.name.endsWith('.bmp') ||
attachment.file.name.endsWith('.gif')) {
this.showImageModal = true
this.attachmentService.getBlobUrl(attachment)
.then(url => {
this.attachmentImageBlobUrl = url
})
} else {
this.downloadAttachment(attachment)
}
},
}, },
} }
</script> </script>

View file

@ -7,11 +7,20 @@
margin-bottom: 1rem; margin-bottom: 1rem;
.attachment { .attachment {
margin-bottom: .75rem; margin-bottom: .5rem;
display: block;
transition: background-color $transition;
border-radius: $radius;
padding: .5rem;
&:hover {
background-color: $grey-lightest;
}
.filename { .filename {
font-weight: bold; font-weight: bold;
margin-bottom: .25rem; margin-bottom: .25rem;
color: $dark;
} }
.info { .info {