Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
62 changes: 62 additions & 0 deletions src/components/AttachmentTag.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<!--
- SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
<div class="attachment-tag" :class="{ 'attachment-tag--remaing': remaining > 0 }" @click="$emit('open')">
<FileIcon v-if="remaining === 0" :file-name="fileName" :mime-type="mimeType" />
<p class="attachment-tag__filename">
{{ remaining > 0 ? `+${remaining}` : fileName }}
</p>
</div>
</template>

<script>
import FileIcon from './icons/FileIcon.vue'
export default {
name: 'AttachmentTag',
components: { FileIcon },
props: {
fileName: {
type: String,
default: '',
},

mimeType: {
type: String,
default: '',
},

remaining: {
type: Number,
default: 0,
},
},
}
</script>

<style lang="scss" scoped>
.attachment-tag {
height: 24px;
border: 1px solid var(--color-border-dark);
border-radius: var(--border-radius-element);
gap: 4px;
display: flex;
cursor: unset;
align-items: center;
max-width: 140px;
min-width: 60px;
margin-inline-end: 4px;
padding: 0 6px;

&__filename{
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
}

.attachment-tag--remaing{
min-width: unset;
}
</style>
37 changes: 37 additions & 0 deletions src/components/Envelope.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
-->
<template>
<EnvelopeSkeleton
ref="component"
v-draggable-envelope="{
accountId: data.accountId ? data.accountId : mailbox.accountId,
mailboxId: data.mailboxId,
Expand Down Expand Up @@ -421,6 +422,13 @@
{{ translateTagDisplayName(tag) }}
</span>
</div>
<div v-for="(attachment, idx) in attachments" :key="`attachement-${idx}`">
<AttachmentTag
:file-name="attachment.fileName"
:mime-type="attachment.mime"
@open="showViewer(fileInfos[idx])" />
</div>
<AttachmentTag v-if="remainingAttachements > 0" :remaining="remainingAttachements" />
<MoveModal
v-if="showMoveModal"
:account="account"
Expand Down Expand Up @@ -485,6 +493,7 @@ import StarOutline from 'vue-material-design-icons/StarOutline.vue'
import TagIcon from 'vue-material-design-icons/TagOutline.vue'
import DeleteIcon from 'vue-material-design-icons/TrashCanOutline.vue'
import DownloadIcon from 'vue-material-design-icons/TrayArrowDown.vue'
import AttachmentTag from './AttachmentTag.vue'
import Avatar from './Avatar.vue'
import EnvelopePrimaryActions from './EnvelopePrimaryActions.vue'
import EnvelopeSkeleton from './EnvelopeSkeleton.vue'
Expand All @@ -500,6 +509,7 @@ import { matchError } from '../errors/match.js'
import NoTrashMailboxConfiguredError
from '../errors/NoTrashMailboxConfiguredError.js'
import logger from '../logger.js'
import AttachementMixin from '../mixins/AttachementMixin.js'
import { buildRecipients as buildReplyRecipients } from '../ReplyBuilder.js'
import { FOLLOW_UP_TAG_LABEL } from '../store/constants.js'
import useMainStore from '../store/mainStore.js'
Expand All @@ -511,6 +521,7 @@ import { hiddenTags } from './tags.js'
export default {
name: 'Envelope',
components: {
AttachmentTag,
AlertOctagonIcon,
Avatar,
IconCreateEvent,
Expand Down Expand Up @@ -559,6 +570,8 @@ export default {
draggableEnvelope: DraggableEnvelopeDirective,
},
mixins: [AttachementMixin],
props: {
withReply: {
// "Reply" action should only appear in envelopes from the envelope list
Expand Down Expand Up @@ -612,6 +625,7 @@ export default {
overwriteOneLineMobile: false,
hoveringAvatar: false,
quickActionLoading: false,
possibleAttachementsCount: 0,
}
},
Expand Down Expand Up @@ -746,6 +760,14 @@ export default {
return tags
},
attachments() {
return this.data.attachments.filter((e) => e.fileName && e.fileName.length > 0).slice(0, this.possibleAttachementsCount)
},
remainingAttachements() {
return this.data.attachments.length - this.attachments.length
},
draggableLabel() {
let label = this.data.subject
const sender = this.data.from[0]?.label ?? this.data.from[0]?.email
Expand Down Expand Up @@ -923,6 +945,20 @@ export default {
return shortRelativeDatetime(new Date(this.data.dateInt * 1000))
},
countPossibleAttachements() {
const container = this.$refs.component?.$el?.querySelector('.list-item-content')
if (!container) {
return 0 // or a default value
}
const tagsWidth = Array.from(container.querySelectorAll('.tag-group') ?? [])
.reduce((total, tag) => total + tag.clientWidth, 0)
const detailsWidth = container.querySelector('.list-item-content__inner__details')?.clientWidth ?? 0
const availableWidth = (container.clientWidth ?? 0) - detailsWidth - tagsWidth - 30 // 30px for the extra (+n) indicator
const attachementSize = 140 + 4 // min-width + gap
this.possibleAttachementsCount = Math.min(3, Math.floor(availableWidth / attachementSize))
},
async executeQuickAction(action) {
this.closeQuickActionsMenu()
this.quickActionLoading = true
Expand Down Expand Up @@ -1343,6 +1379,7 @@ export default {
} else {
this.overwriteOneLineMobile = false
}
this.countPossibleAttachements()
},
},
}
Expand Down
5 changes: 4 additions & 1 deletion src/components/EnvelopeSkeleton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@
<!-- @slot Slot for the second line of the component -->
<slot name="subname" />
</div>
<div v-if="$slots.tags" class="list-item-content__inner__tags">
<div
v-if="$slots.tags"
class="list-item-content__inner__tags"
@click.prevent.stop>
<!-- @slot This slot is used for the third line of the component -->
<slot name="tags" />
</div>
Expand Down
39 changes: 3 additions & 36 deletions src/components/MessageAttachments.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
<script>
import { showError, showSuccess } from '@nextcloud/dialogs'
import { FilePickerVue as FilePicker } from '@nextcloud/dialogs/filepicker.js'
import { basename } from '@nextcloud/paths'
import { generateUrl } from '@nextcloud/router'
import { NcLoadingIcon as IconLoading } from '@nextcloud/vue'
import ChevronDown from 'vue-material-design-icons/ChevronDown.vue'
Expand All @@ -75,6 +74,7 @@ import CloudDownload from 'vue-material-design-icons/CloudDownloadOutline.vue'
import Download from 'vue-material-design-icons/TrayArrowDown.vue'
import MessageAttachment from './MessageAttachment.vue'
import Logger from '../logger.js'
import AttachementMixin from '../mixins/AttachementMixin.js'
import { saveAttachmentsToFiles } from '../service/AttachmentService.js'

export default {
Expand All @@ -89,6 +89,7 @@ export default {
FilePicker,
},

mixins: [AttachementMixin],
props: {
envelope: {
required: true,
Expand Down Expand Up @@ -122,25 +123,6 @@ export default {
},

computed: {
fileInfos() {
return this.attachments.map((attachment) => ({
filename: attachment.downloadUrl,
source: attachment.downloadUrl,
basename: basename(attachment.downloadUrl),
mime: attachment.mime,
etag: 'fixme',
hasPreview: false,
fileid: parseInt(attachment.id, 10),
}))
},

previewableFileInfos() {
return this.fileInfos.filter((fileInfo) => (fileInfo.mime.startsWith('image/')
|| fileInfo.mime.startsWith('video/')
|| fileInfo.mime.startsWith('audio/')
|| fileInfo.mime === 'application/pdf')
&& OCA.Viewer.mimetypes.includes(fileInfo.mime))
},

moreThanOne() {
return this.attachments.length > 1
Expand All @@ -154,6 +136,7 @@ export default {
},

mounted() {
console.log(this.attachments)
let prevTop = null
this.visible = 0
this.$nextTick(function() {
Expand All @@ -175,9 +158,6 @@ export default {
},

methods: {
canPreview(fileInfo) {
return this.previewableFileInfos.includes(fileInfo)
},

saveAll(dest) {
const path = dest[0].path
Expand All @@ -198,19 +178,6 @@ export default {
downloadZip() {
window.location = this.zipUrl
},

showViewer(fileInfo) {
if (!this.canPreview(fileInfo)) {
return
}

if (this.previewableFileInfos.includes(fileInfo)) {
OCA.Viewer.open({
fileInfo,
list: this.previewableFileInfos,
})
}
},
},
}
</script>
Expand Down
107 changes: 107 additions & 0 deletions src/components/icons/FileIcon.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<!--
- SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
<span class="file-icon" :style="{ color: `var(${color})` }">
<component :is="iconComponent" class="file-icon__svg" :size="16" />
</span>
</template>

<script>
import DocumentOutlineIcon from 'vue-material-design-icons/FileDocumentOutline.vue'
import MusicOutlineIcon from 'vue-material-design-icons/FileMusicOutline.vue'
import FileOutlineIcon from 'vue-material-design-icons/FileOutline.vue'
import FilePdfBox from 'vue-material-design-icons/FilePdfBox.vue'
import VideoOutlineIcon from 'vue-material-design-icons/FileVideoOutline.vue'
import ImageOutlineIcon from 'vue-material-design-icons/ImageOutline.vue'
import { FILE_EXTENSIONS_PRESENTATION, FILE_EXTENSIONS_SPREADSHEET, FILE_EXTENSIONS_WORD_PROCESSING } from '../../store/constants.js'

export default {
name: 'FileIcon',
props: {
fileName: {
type: String,
required: true,
},

mimeType: {
type: String,
required: true,
},
},

data() {
return {
extension: '',
icon: null,
color: '--color-text-maxcontrast',
}
},

computed: {
iconName() {
const type = this.mimeType.split('/')[0].toLowerCase()
if (this.extension === 'pdf') {
return 'pdf'
}
if ([...FILE_EXTENSIONS_WORD_PROCESSING, 'txt', 'md'].includes(this.extension)) {
return 'document'
}
if (type === 'image') {
return 'image'
}
if (type === 'video') {
return 'video'
}
if (type === 'audio') {
return 'music'
}
return 'file'
},

iconComponent() {
const map = {
file: FileOutlineIcon,
image: ImageOutlineIcon,
video: VideoOutlineIcon,
music: MusicOutlineIcon,
document: DocumentOutlineIcon,
pdf: FilePdfBox,
}
return map[this.iconName] || FileOutlineIcon
},
},

mounted() {
this.extension = this.fileName.split('.').pop().toLowerCase()
this.setColor()
},

methods: {
setColor() {
if (FILE_EXTENSIONS_WORD_PROCESSING.includes(this.extension)) {
this.color = '--color-info-text'
} else if (FILE_EXTENSIONS_SPREADSHEET.includes(this.extension)) {
this.color = '--color-border-success'
} else if (FILE_EXTENSIONS_PRESENTATION.includes(this.extension)) {
this.color = '--color-favorite'
} else if (this.extension === 'pdf') {
this.color = '--color-text-error'
}
},
},
}
</script>

<style scoped>
.file-icon {
display: inline-flex;
align-items: center;
justify-content: center;
width: 16px;
height: 16px;
border-radius: 4px;
padding: 0 4px;
}
</style>
Loading
Loading