Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
271a59a
refactor(AttachmentService): Some code style cleanup
mejo- Oct 25, 2023
df3e4df
chore(attachments): Remove support for obsolete `text://` format
mejo- Oct 31, 2023
8c1c6e8
feat(attachments): API endpoint to get list of attachments for a docu…
mejo- Oct 25, 2023
73cb49b
chore(attachments): Remove obsolete metadata API endpoint
mejo- Nov 15, 2023
153a85f
feat(attachments): Use getAttachmentList API endpoint in resolver
mejo- Oct 31, 2023
680ca1d
fix(attachment): Remove candidate logic from ImageView node
mejo- Nov 15, 2023
86e2b97
fix(attachments): Fix some issues with the showimage modal
mejo- Nov 21, 2023
b274e37
chore(attachments): Remove obsolete code
mejo- Nov 21, 2023
a2813ae
feat(editor): Allow to pass fileId to MarkdownContentEditor
mejo- Nov 21, 2023
bd54a68
feat(attachments): Allow to get attachments without document session
mejo- Nov 22, 2023
d15781c
chore(attachments): Remove special-handling for preview URLs
mejo- Nov 22, 2023
e4108d4
fix(attachments): Open non-image attachments in viewer or download
mejo- Nov 22, 2023
98ba0de
fix(AttachmentController): Set fileName of returned attachments
mejo- Nov 27, 2023
dade37e
chore(composer): Update autoloader maps
mejo- Nov 27, 2023
7743591
fix(attachments): Fix encoding of attachment URI component
mejo- Nov 27, 2023
ec91074
test(cy): Test to open image in modal and download attachment
mejo- Nov 28, 2023
b01c547
chore(middleware): Rename to RequireDocumentSessionOrUserOrShareToken
mejo- Nov 28, 2023
a1f8308
fix(attachments): use `getRelativePath` from userFolder for `davPath`
mejo- Nov 28, 2023
3ce2e44
test(AttachmentResolver): Refactor jest tests after parent class refa…
mejo- Nov 28, 2023
6796170
fix(attachments): Show all loaded images in ShowImageModal
mejo- Nov 28, 2023
c7e0cf0
fix(SessionMiddleware): Check if user/share have access to document
mejo- Nov 29, 2023
978cbc6
fix(AttachmentResolver): Require either fileId or session
mejo- Nov 29, 2023
77a0d4a
reactor(ImageView): Simplify attachmentType/isMediaAttachment logic
mejo- Nov 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(attachments): Fix some issues with the showimage modal
* Only open images from native attachments list
* Only open images, non-image attachments are not supported anyway
* Fix watcher for `startIndex`
* Don't set computed property `currentImage`
* Show error if image cannot be found in attachments

Signed-off-by: Jonas <[email protected]>
  • Loading branch information
mejo- committed Nov 29, 2023
commit 86e2b97255da6c717bfd5e1bc45ec1356dc55177
17 changes: 4 additions & 13 deletions src/components/ImageView/ShowImageModal.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<NcModal v-if="show"
size="large"
:name="currentImage.basename"
:name="currentImage.name"
:out-transition="true"
:has-next="true"
:has-previous="true"
Expand All @@ -11,7 +11,7 @@
@previous="showPreviousImage"
@close="$emit('close')">
<div class="modal__content">
<img :src="currentImage.source">
<img :src="currentImage.previewUrl">
</div>
</NcModal>
</template>
Expand All @@ -27,14 +27,7 @@ export default {
props: {
images: {
type: Array,
default() {
return []
},
validator(imagesList) {
return (imagesList.length === 0)
? true
: imagesList.every(image => image.basename && image.source)
},
required: true,
},
startIndex: {
type: Number,
Expand All @@ -56,20 +49,18 @@ export default {
},
},
watch: {
startIndex(val) {
'startIndex'(val) {
this.currentImageIndex = val
},
},
methods: {
showNextImage() {
this.currentImageIndex = (this.currentImageIndex + 1) % this.images.length
this.currentImage = this.images[this.currentImageIndex]
},
showPreviousImage() {
this.currentImageIndex = this.currentImageIndex <= 0
? this.images.length - 1
: this.currentImageIndex - 1
this.currentImage = this.images[this.currentImageIndex]
},
},
}
Expand Down
50 changes: 23 additions & 27 deletions src/nodes/ImageView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<div v-if="isMediaAttachment"
contenteditable="false"
class="media"
@click="handleImageClick(src)">
@click="handleImageClick">
<div class="media__wrapper">
<img v-show="loaded"
:src="imageUrl"
Expand All @@ -62,7 +62,7 @@
<img v-show="loaded"
:src="imageUrl"
class="image__main"
@click="handleImageClick(src)"
@click="handleImageClick"
@load="onLoaded">
</div>
</template>
Expand Down Expand Up @@ -101,7 +101,7 @@
</div>
</transition>
<div class="image__modal">
<ShowImageModal :images="embeddedImagesList"
<ShowImageModal :images="imageAttachments"
:start-index="imageIndex"
:show="showImageModal"
@close="showImageModal=false" />
Expand Down Expand Up @@ -135,7 +135,9 @@

<script>
import ClickOutside from 'vue-click-outside'
import { mapGetters } from 'vuex'
import { NcButton } from '@nextcloud/vue'
import { showError } from '@nextcloud/dialogs'
import ShowImageModal from '../components/ImageView/ShowImageModal.vue'
import store from '../mixins/store.js'
import { useAttachmentResolver } from '../components/Editor.provider.js'
Expand Down Expand Up @@ -191,6 +193,7 @@ export default {
props: ['editor', 'node', 'extension', 'updateAttributes', 'deleteNode'], // eslint-disable-line
data() {
return {
attachment: null,
imageLoaded: false,
loaded: false,
failed: false,
Expand All @@ -200,12 +203,14 @@ export default {
attachmentType: null,
attachmentSize: null,
showImageModal: false,
embeddedImagesList: [],
imageIndex: null,
isEditable: false,
}
},
computed: {
...mapGetters({
imageAttachments: 'text/imageAttachments',
}),
isMediaAttachment() {
return this.attachmentType === this.$attachmentResolver.ATTACHMENT_TYPE_MEDIA
},
Expand Down Expand Up @@ -282,21 +287,21 @@ export default {
},
methods: {
async loadPreview() {
const attachment = await this.$attachmentResolver.resolve(this.src)
this.attachment = await this.$attachmentResolver.resolve(this.src)
return new Promise((resolve, reject) => {
const img = new Image()
img.onload = async () => {
this.imageUrl = attachment.previewUrl
this.imageUrl = this.attachment.previewUrl
this.imageLoaded = true
this.loaded = true
this.attachmentType = attachment.isImage ? this.$attachmentResolver.ATTACHMENT_TYPE_IMAGE : this.$attachmentResolver.ATTACHMENT_TYPE_MEDIA
this.attachmentSize = attachment.size
resolve(attachment.previewUrl)
this.attachmentType = this.attachment.isImage ? this.$attachmentResolver.ATTACHMENT_TYPE_IMAGE : this.$attachmentResolver.ATTACHMENT_TYPE_MEDIA
this.attachmentSize = this.attachment.size
resolve(this.attachment.previewUrl)
}
img.onerror = (e) => {
reject(new LoadImageError(e, attachment.previewUrl))
reject(new LoadImageError(e, this.attachment.previewUrl))
}
img.src = attachment.previewUrl
img.src = this.attachment.previewUrl
})
},
onImageLoadFailure(err) {
Expand All @@ -319,23 +324,14 @@ export default {
onLoaded() {
this.loaded = true
},
async handleImageClick(src) {
const imageViews = Array.from(document.querySelectorAll('figure[data-component="image-view"].image-view'))
let basename, relativePath

for (const imgv of imageViews) {
relativePath = imgv.getAttribute('data-src')
basename = relativePath.split('/').slice(-1).join()
const response = await this.$attachmentResolver.resolve(relativePath, true)
const { url: source } = response.shift()
this.embeddedImagesList.push({
source,
basename,
relativePath,
})
async handleImageClick() {
this.imageIndex = this.imageAttachments.findIndex(i => (i.isImage && i.fileId === this.attachment.fileId))
if (this.imageIndex !== -1) {
this.showImageModal = true
} else {
console.error('Could not find image in attachments list', this.attachment)
showError(t('text', 'Could not find image in attachments list.'))
}
this.imageIndex = this.embeddedImagesList.findIndex(image => image.relativePath === src)
this.showImageModal = true
},
onDelete() {
emit('text:image-node:delete', this.imageUrl)
Expand Down
1 change: 1 addition & 0 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const textModule = {
attachmentList: [],
},
getters: {
imageAttachments: (state) => state.attachmentList.filter(a => a.isImage),
findAttachment: (state) => (fileName) => state.attachmentList.find(a => a.name === fileName),
},
mutations: {
Expand Down