|
| 1 | +<!-- |
| 2 | + - @copyright Copyright (c) 2022 Julius Härtl <jus@bitgrid.net> |
| 3 | + - |
| 4 | + - @author Julius Härtl <jus@bitgrid.net> |
| 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 | +<template> |
| 23 | + <div v-if="!accessible" class="widget-file widget-file--no-access"> |
| 24 | + <div class="widget-file--image widget-file--image--icon icon-folder" /> |
| 25 | + <div class="widget-file--details"> |
| 26 | + <p class="widget-file--title"> |
| 27 | + {{ t('files', 'File cannot be accessed') }} |
| 28 | + </p> |
| 29 | + <p class="widget-file--description"> |
| 30 | + {{ t('files', 'You might not have have permissions to view it, ask the sender to share it') }} |
| 31 | + </p> |
| 32 | + </div> |
| 33 | + </div> |
| 34 | + <a v-else |
| 35 | + class="widget-file" |
| 36 | + :href="richObject.link" |
| 37 | + @click.prevent="navigate"> |
| 38 | + <div class="widget-file--image" :class="filePreviewClass" :style="filePreview" /> |
| 39 | + <div class="widget-file--details"> |
| 40 | + <p class="widget-file--title">{{ richObject.name }}</p> |
| 41 | + <p class="widget-file--description">{{ fileSize }}<br>{{ fileMtime }}</p> |
| 42 | + <p class="widget-file--link">{{ filePath }}</p> |
| 43 | + </div> |
| 44 | + </a> |
| 45 | +</template> |
| 46 | +<script> |
| 47 | +import { generateUrl } from '@nextcloud/router' |
| 48 | +import path from 'path' |
| 49 | + |
| 50 | +export default { |
| 51 | + name: 'ReferenceFileWidget', |
| 52 | + props: { |
| 53 | + richObject: { |
| 54 | + type: Object, |
| 55 | + required: true, |
| 56 | + }, |
| 57 | + accessible: { |
| 58 | + type: Boolean, |
| 59 | + default: true, |
| 60 | + }, |
| 61 | + }, |
| 62 | + data() { |
| 63 | + return { |
| 64 | + previewUrl: window.OC.MimeType.getIconUrl(this.richObject.mimetype), |
| 65 | + } |
| 66 | + }, |
| 67 | + computed: { |
| 68 | + fileSize() { |
| 69 | + return window.OC.Util.humanFileSize(this.richObject.size) |
| 70 | + }, |
| 71 | + fileMtime() { |
| 72 | + return window.OC.Util.relativeModifiedDate(this.richObject.mtime * 1000) |
| 73 | + }, |
| 74 | + filePath() { |
| 75 | + return path.dirname(this.richObject.path) |
| 76 | + }, |
| 77 | + filePreview() { |
| 78 | + if (this.previewUrl) { |
| 79 | + return { |
| 80 | + backgroundImage: 'url(' + this.previewUrl + ')', |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + return { |
| 85 | + backgroundImage: 'url(' + window.OC.MimeType.getIconUrl(this.richObject.mimetype) + ')', |
| 86 | + } |
| 87 | + |
| 88 | + }, |
| 89 | + filePreviewClass() { |
| 90 | + if (this.previewUrl) { |
| 91 | + return 'widget-file--image--preview' |
| 92 | + } |
| 93 | + return 'widget-file--image--icon' |
| 94 | + |
| 95 | + }, |
| 96 | + }, |
| 97 | + mounted() { |
| 98 | + if (this.richObject['preview-available']) { |
| 99 | + const previewUrl = generateUrl('/core/preview?fileId={fileId}&x=250&y=250', { |
| 100 | + fileId: this.richObject.id, |
| 101 | + }) |
| 102 | + const img = new Image() |
| 103 | + img.onload = () => { |
| 104 | + this.previewUrl = previewUrl |
| 105 | + } |
| 106 | + img.onerror = err => { |
| 107 | + console.error('could not load recommendation preview', err) |
| 108 | + } |
| 109 | + img.src = previewUrl |
| 110 | + } |
| 111 | + }, |
| 112 | + methods: { |
| 113 | + navigate() { |
| 114 | + if (OCA.Viewer && OCA.Viewer.mimetypes.indexOf(this.richObject.mimetype) !== -1) { |
| 115 | + OCA.Viewer.open({ path: this.richObject.path }) |
| 116 | + return |
| 117 | + } |
| 118 | + window.location = generateUrl('/f/' + this.id) |
| 119 | + }, |
| 120 | + }, |
| 121 | +} |
| 122 | +</script> |
| 123 | +<style lang="scss" scoped> |
| 124 | +.widget-file { |
| 125 | + display: flex; |
| 126 | + |
| 127 | + &--image { |
| 128 | + min-width: 40%; |
| 129 | + background-position: center; |
| 130 | + background-size: cover; |
| 131 | + background-repeat: no-repeat; |
| 132 | + |
| 133 | + &.widget-file--image--icon { |
| 134 | + min-width: 88px; |
| 135 | + background-size: 44px; |
| 136 | + } |
| 137 | + } |
| 138 | + |
| 139 | + &--title { |
| 140 | + overflow: hidden; |
| 141 | + text-overflow: ellipsis; |
| 142 | + white-space: nowrap; |
| 143 | + font-weight: bold; |
| 144 | + } |
| 145 | + |
| 146 | + &--details { |
| 147 | + padding: 12px; |
| 148 | + flex-grow: 1; |
| 149 | + display: flex; |
| 150 | + flex-direction: column; |
| 151 | + |
| 152 | + p { |
| 153 | + margin: 0; |
| 154 | + padding: 0; |
| 155 | + } |
| 156 | + } |
| 157 | + |
| 158 | + &--description { |
| 159 | + overflow: hidden; |
| 160 | + text-overflow: ellipsis; |
| 161 | + display: -webkit-box; |
| 162 | + -webkit-line-clamp: 3; |
| 163 | + line-clamp: 3; |
| 164 | + -webkit-box-orient: vertical; |
| 165 | + } |
| 166 | + |
| 167 | + &--link { |
| 168 | + color: var(--color-text-maxcontrast); |
| 169 | + } |
| 170 | + |
| 171 | + &.widget-file--no-access { |
| 172 | + padding: 12px; |
| 173 | + |
| 174 | + .widget-file--details { |
| 175 | + padding: 0; |
| 176 | + } |
| 177 | + } |
| 178 | +} |
| 179 | +</style> |
0 commit comments