|
| 1 | +<!-- |
| 2 | + - @copyright Copyright (c) 2023 Johannes Szeibert <johannes@szeibert.de> |
| 3 | + - |
| 4 | + - @author Johannes Szeibert <johannes@szeibert.de> |
| 5 | + - |
| 6 | + - @license GNU AGPL version 3 or any later version |
| 7 | + - |
| 8 | + - This program is free software: you can redistribute it and/or modify |
| 9 | + - it under the terms of the GNU Affero General Public License as |
| 10 | + - published by the Free Software Foundation, either version 3 of the |
| 11 | + - License, or (at your option) any later version. |
| 12 | + - |
| 13 | + - This program is distributed in the hope that it will be useful, |
| 14 | + - but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | + - GNU Affero General Public License for more details. |
| 17 | + - |
| 18 | + - You should have received a copy of the GNU Affero General Public License |
| 19 | + - along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | + - |
| 21 | + --> |
| 22 | + |
| 23 | +<template> |
| 24 | + <div v-if="cardId && ( attachments.length > 0 )" class="card-cover"> |
| 25 | + <div v-for="(attachment, index) in attachments" |
| 26 | + :key="attachment.id" |
| 27 | + :class="['image-wrapper', { 'rounded-left': index === 0 }, { 'rounded-right': index === attachments.length - 1 }]" |
| 28 | + :style="{ backgroundImage: `url(${attachmentPreview(attachment)})` }" /> |
| 29 | + </div> |
| 30 | +</template> |
| 31 | +<script> |
| 32 | +import { mapActions } from 'vuex' |
| 33 | +import { generateUrl } from '@nextcloud/router' |
| 34 | +export default { |
| 35 | + name: 'CardCover', |
| 36 | + props: { |
| 37 | + cardId: { |
| 38 | + type: Number, |
| 39 | + required: true, |
| 40 | + }, |
| 41 | + }, |
| 42 | + computed: { |
| 43 | + attachments() { |
| 44 | + return [...this.$store.getters.attachmentsByCard(this.cardId)] |
| 45 | + // Filter deleted and hasPreview |
| 46 | + .filter(attachment => attachment.deletedAt >= 0 && attachment.extendedData.hasPreview) |
| 47 | + // sort by id (same as in AttachmentList) to get Newest |
| 48 | + .sort((a, b) => b.id - a.id) |
| 49 | + // limit to 3 like with android Deck app |
| 50 | + .slice(0, 3) |
| 51 | + }, |
| 52 | + attachmentPreview() { |
| 53 | + // FIXME find a better way to get the stack-width |
| 54 | + const stackWidth = getComputedStyle(document.documentElement).getPropertyValue('--stack-width').trim() |
| 55 | + const x = Math.ceil(parseInt(stackWidth) / this.attachments.length) | 260 |
| 56 | + const y = 100 |
| 57 | + return attachment => ( |
| 58 | + // The core preview provider is a bit strange at times, providing much larger than needed images |
| 59 | + // when cropping is enabled. Therefore use a=1 to not crop the image and let css handle the overflow |
| 60 | + attachment.extendedData.fileid ? generateUrl(`/core/preview?fileId=${attachment.extendedData.fileid}&x=${x}&y=${y}&a=1`) : null |
| 61 | + ) |
| 62 | + }, |
| 63 | + }, |
| 64 | + watch: { |
| 65 | + cardId: { |
| 66 | + immediate: true, |
| 67 | + handler() { |
| 68 | + if (this.$store.getters.cardById(this.cardId)?.attachmentCount > 0) { |
| 69 | + this.fetchAttachments(this.cardId) |
| 70 | + } |
| 71 | + }, |
| 72 | + }, |
| 73 | + }, |
| 74 | + methods: { |
| 75 | + ...mapActions([ |
| 76 | + 'fetchAttachments', |
| 77 | + ]), |
| 78 | + }, |
| 79 | +} |
| 80 | +</script> |
| 81 | +
|
| 82 | +<style lang="scss" scoped> |
| 83 | +@import '../../css/variables'; |
| 84 | +
|
| 85 | +.card-cover { |
| 86 | + height: 100px; |
| 87 | + display: flex; |
| 88 | + .image-wrapper { |
| 89 | + flex: 1; |
| 90 | + position: relative; |
| 91 | + background-size: cover; |
| 92 | + background-repeat: no-repeat; |
| 93 | + background-position: center center; |
| 94 | + &.rounded-left { |
| 95 | + border-top-left-radius: 10px; |
| 96 | + } |
| 97 | + &.rounded-right { |
| 98 | + border-top-right-radius: 10px; |
| 99 | + } |
| 100 | + } |
| 101 | +} |
| 102 | +</style> |
0 commit comments