GridEditorSourceDocuments.vue 2.63 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<template lang="pug">

  q-list.default-source-container

    q-list-header
      q-item
        small Documents

    q-item-separator

    template(v-for="(file, i) in images")
      template(v-if="i > 0")
        q-item-separator
      q-item
        q-item-side
          q-icon(
          draggable="true",
          @dragstart.native="event => {handleItemDragStart(event, file)}",
          :name="typeToIconName(getSimpleType(file.metaData['content-type']))", style="font-size: 1.8rem")
        q-item-main {{ file.name }}

</template>

<script>
  import { mapGetters } from 'vuex'

  const typeToIconName = {
Anton's avatar
Anton committed
28
    'image': 'photo'
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
  }

  export default {
    data () {
      return {
        files: []
      }
    },
    async mounted () {
      this.files = await this.$store.dispatch('files/list', this.bucketName)
    },
    computed: {
      ...mapGetters({
        user: 'auth/getUserState'
      }),
      bucketName () {
        return `user-${this.user.uuid}`
      },
      images () {
        return this.files.filter(file => this.getSimpleType(file.metaData['content-type']) === 'image')
      },
      types () {
        const _this = this
        return this.files.reduce((types, file) => {
          const mimetype = file.metaData && file.metaData['content-type'] ? file.metaData['content-type'] : undefined
          if (mimetype) {
            const type = _this.getSimpleType(mimetype)
            if (types.indexOf(type) === -1) types.push(type)
          }
          return types
        }, [])
      }
    },
    methods: {
      typeToIconName (type) {
        let iconName = typeToIconName[type.toLowerCase()]
        if (!iconName) {
          iconName = 'broken image'
        }
        return iconName
      },
Anton's avatar
Anton committed
70
71
72
73
74
75
76
      getSimpleType (mimetype, capitalize = false) {
        let type = mimetype
        if (mimetype.indexOf('/') !== -1) type = mimetype.split('/')[0]
        if (capitalize) {
          type = type.substr(0, 1).toUpperCase() + type.substr(1)
        }
        return type
77
78
79
      },
      handleItemDragStart (event, item) {
        const resourceCell = {
Anton's avatar
Anton committed
80
81
82
83
84
85
          data: {
            content: `${process.env.STORAGE_HOST}/files/${this.bucketName}/${item.name}`,
            type: this.getSimpleType(item.metaData['content-type'], true)
          },
          config: {},
          component: 'CellImage'
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
        }
        event.dataTransfer.setData('text/plain', JSON.stringify(resourceCell))
      }
    }
  }
</script>

<style scoped lang="stylus">

  .q-list-header
    padding-left 0

    .q-input
      padding-left 1em
      padding-right 1em

    .q-input:before
    .q-input:after
      display none

  .q-input
    padding-left 0

</style>