deblan.io-murph/assets/js/admin/components/file-manager/FileIcon.vue

78 lines
2 KiB
Vue
Raw Normal View History

2021-06-15 11:49:44 +02:00
<template>
2021-06-22 11:06:05 +02:00
<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:49:44 +02:00
</template>
2021-06-22 11:06:05 +02:00
<style scoped>
</style>
2021-06-15 11:49:44 +02:00
<script>
2021-06-22 11:06:05 +02:00
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:49:44 +02:00
const map = {
2021-06-22 11:06:05 +02:00
'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:49:44 +02:00
}
export default {
2021-06-15 14:26:20 +02:00
name: 'FileIcon',
2021-06-22 11:06:05 +02:00
data () {
return {
icon: null,
thumbnail: null
}
},
2021-06-15 14:26:20 +02:00
methods: {
2021-06-22 11:06:05 +02:00
defineIcon () {
2021-06-15 14:26:20 +02:00
for (const icon in map) {
2021-06-22 11:06:05 +02:00
if (map[icon].indexOf(this.mime) !== -1) {
this.icon = icon
return
2021-06-15 14:26:20 +02:00
}
}
2021-06-15 11:49:44 +02:00
2021-06-22 11:06:05 +02:00
this.icon = 'fa fa-file'
},
defineThumbnail () {
if (['image/png', 'image/jpg', 'image/jpeg', 'image/gif'].indexOf(this.mime) === -1) {
return
2021-06-15 14:26:20 +02:00
}
2021-06-15 11:49:44 +02:00
2021-06-22 11:06:05 +02:00
this.thumbnail = Routing.generate('liip_imagine_filter', {
filter: 'file_manager_thumbnail_filter',
path: this.path
})
2021-06-15 14:26:20 +02:00
}
},
props: {
mime: {
type: String,
required: true
2021-06-22 11:06:05 +02:00
},
path: {
type: String,
required: true
},
thumb: {
type: Boolean,
required: true
2021-06-15 14:26:20 +02:00
}
2021-06-22 11:06:05 +02:00
},
mounted () {
this.defineIcon()
this.defineThumbnail()
2021-06-15 14:26:20 +02:00
}
2021-06-15 11:49:44 +02:00
}
</script>