murph-skeleton/core/Resources/assets/js/components/file-manager/FileIcon.vue

87 lines
2.2 KiB
Vue
Raw Normal View History

2021-06-15 11:31:52 +02:00
<template>
<span>
<span v-if="!thumb || !thumbnail" v-bind:class="icon"></span>
<img v-if="thumb && thumbnail" v-bind:src="thumbnail">
</span>
2021-06-15 11:31:52 +02:00
</template>
<style scoped>
2021-06-22 11:37:39 +02:00
img {
max-width: 120px;
}
</style>
2021-06-15 11:31:52 +02:00
<script>
import Routing from '../../../../../../vendor/friendsofsymfony/jsrouting-bundle/Resources/public/js/router.min.js'
const routes = require('../../../../../../public/js/fos_js_routes.json')
Routing.setRoutingData(routes)
2021-06-15 11:31:52 +02:00
const map = {
'fa fa-file-pdf': ['application/pdf'],
'fa fa-file-image': ['image/png', 'image/jpg', 'image/jpeg', 'image/gif'],
'fa fa-file-audio': ['application/ogg', 'audio/mp3', 'audio/mpeg', 'audio/wav'],
'fa fa-file-archive': ['application/zip', 'multipart/x-zip', 'application/rar', 'application/x-rar-compressed', 'application/x-zip-compressed', 'application/tar', 'application/x-tar'],
'fa fa-file-alt': ['application/rtf'],
'fa fa-file-excel': ['application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'],
'fa fa-file-powerpoint': ['application/vnd.ms-powerpoint', 'application/vnd.openxmlformats-officedocument.presentationml.presentation'],
'fa fa-file-video': ['video/x-msvideo', 'video/mpeg']
2021-06-15 11:31:52 +02:00
}
export default {
2021-06-15 14:16:07 +02:00
name: 'FileIcon',
data () {
return {
icon: null,
thumbnail: null
}
},
2021-06-15 14:16:07 +02:00
methods: {
defineIcon () {
2021-06-15 14:16:07 +02:00
for (const icon in map) {
if (map[icon].indexOf(this.mime) !== -1) {
this.icon = icon
return
2021-06-15 14:16:07 +02:00
}
}
2021-06-15 11:31:52 +02:00
this.icon = 'fa fa-file'
},
defineThumbnail () {
2021-06-22 11:37:39 +02:00
if (['image/svg', 'image/svg+xml'].indexOf(this.mime) !== -1) {
this.thumbnail = '/' + this.path
return
}
if (['image/png', 'image/jpg', 'image/jpeg', 'image/gif'].indexOf(this.mime) === -1) {
2021-10-06 10:22:04 +02:00
this.thumbnail = null
return
2021-06-15 14:16:07 +02:00
}
2021-06-15 11:31:52 +02:00
this.thumbnail = Routing.generate('liip_imagine_filter', {
filter: 'file_manager_thumbnail_filter',
path: this.path
})
2021-06-15 14:16:07 +02:00
}
},
props: {
mime: {
type: String,
required: true
},
path: {
type: String,
required: true
},
thumb: {
type: Boolean,
required: true
2021-06-15 14:16:07 +02:00
}
},
mounted () {
this.defineIcon()
this.defineThumbnail()
2021-06-15 14:16:07 +02:00
}
2021-06-15 11:31:52 +02:00
}
</script>