diff --git a/src/nodes/ImageView.vue b/src/nodes/ImageView.vue index 81eef78057d..1b67db3a8cb 100644 --- a/src/nodes/ImageView.vue +++ b/src/nodes/ImageView.vue @@ -24,6 +24,7 @@
- @@ -179,6 +180,7 @@ export default { showImageModal: false, imageIndex: null, isEditable: false, + embeddedImageList: [], } }, computed: { @@ -241,7 +243,6 @@ export default { this.loaded = true 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, this.attachment.previewUrl)) @@ -269,7 +270,23 @@ export default { onLoaded() { this.loaded = true }, - async handleAttachmentClick() { + async updateEmbeddedImageList() { + this.embeddedImageList = [] + // Get all images that succeeded to load + const imageViews = Array.from(document.querySelectorAll('figure[data-component="image-view"][data-attachment-type="image"]:not(.image-view--failed).image-view')) + for (const imgv of imageViews) { + const src = imgv.getAttribute('data-src') + if(!this.embeddedImageList.find(i => i.src === src)) { + // Don't add duplicates (e.g. when several editors are loaded in HTML document) + const attachment = await this.$attachmentResolver.resolve(imgv.getAttribute('data-src')) + this.embeddedImageList.push({ + src, + ...attachment, + }) + } + } + }, + handleAttachmentClick() { // Open in viewer if possible if (OCA.Viewer // Viewer is not in use @@ -288,7 +305,8 @@ export default { window.location.assign(this.attachment.fullUrl) }, async handleImageClick() { - this.imageIndex = this.imageAttachments.findIndex(i => (i.isImage && i.fileId === this.attachment.fileId)) + await this.updateEmbeddedImageList() + this.imageIndex = this.embeddedImageList.findIndex(i => (i.src === this.src)) if (this.imageIndex !== -1) { this.showImageModal = true } else { diff --git a/src/services/AttachmentResolver.js b/src/services/AttachmentResolver.js index 704422b2e2d..b4f3ad84b3c 100644 --- a/src/services/AttachmentResolver.js +++ b/src/services/AttachmentResolver.js @@ -86,6 +86,7 @@ export default class AttachmentResolver { if (isDirectUrl(src)) { return { isImage: true, + name: this.#name(src), previewUrl: src, fullUrl: src, } @@ -94,11 +95,16 @@ export default class AttachmentResolver { // Fallback: Return DAV url (e.g. for relative paths to images) return { isImage: true, + name: this.#name(src), previewUrl: this.#davUrl(src), fullUrl: this.#davUrl(src), } } + #name(src) { + return src.split('/').pop() + } + #davUrl(src) { if (this.#user) { const uid = this.#user.uid