summaryrefslogtreecommitdiffstats
path: root/webapp/src/components/ConfigChip.vue
blob: 7ae0d08f0fcadc5e223ecee22cf685b9f21a784c (plain) (blame)
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
28
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<i18n>
{
  "en": {
    "assigned": "Assigned",
    "active": "Active",
    "source": "Source",
    "id": "ID",
    "name": "Name"
  },
  "de": {
    "assigned": "Zugewiesen",
    "active": "Aktiv",
    "source": "Quelle",
    "id": "ID",
    "name": "Name"
  }
}
</i18n>

<template>
  <v-tooltip top open-delay="200">
    <template #activator="{ on }">
      <v-chip v-on="on" small :color="color" :text-color="color ? 'white' : ''" :label="isEvent">
        <span class="chip-text">{{ config.name || config.id }}</span>
      </v-chip>
    </template>
    <div>
      <div v-if="active" class="success--text" style="text-align: center; font-weight: bold; font-size: 1.2em">{{ $t('active') }}</div>
      <div v-if="assigned" class="primary--text" style="text-align: center; font-weight: bold; font-size: 1.2em">{{ $t('assigned') }}</div>
      <v-divider v-if="active || assigned" style="margin-bottom: 4px"></v-divider>
      <div>
        <div v-for="(source, index) in sources" :key="source.data.id">
          <v-divider v-if="index > 0" style="margin-bottom: 4px"></v-divider>
          <div style="text-align: center; font-weight: bold;">{{ source.title }}</div>
          <table>
            <tr><td class="config-source-key">{{ $t('source') }}</td><td>{{ source.data.type }}</td></tr>
            <tr v-if="source.data.id"><td class="config-source-key">{{ $t('id') }}</td><td>{{ source.data.id }}</td></tr>
            <tr v-if="source.data.name"><td class="config-source-key">{{ $t('name') }}</td><td>{{ source.data.name }}</td></tr>
          </table>
        </div>
      </div>
    </div>
  </v-tooltip>
</template>

<script>

export default {
  name: 'ConfigChip',
  props: {
    config: {
      type: Object,
      default: () => {}
    },
    active: {
      type: Boolean,
      default: false
    },
    assigned: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
    }
  },
  computed: {
    color () {
      if (this.assigned) return 'primary'
      if (this.active) return 'success'
      return ''
    },
    isEvent () {
      return this.sources.some(source => (source.data.type === 'IMPORTANT_EVENT' || source.data.type === 'EVENT'))
    },
    sources () {
      return this.getSources(this.config)
    }
  },
  methods: {
    getSources (config) {
      const sources = []
      if (config.merged) {
        config.configs.forEach(c => {
          sources.push(...this.getSources(c))
        })
      } else {
        if (Array.isArray(config.source)) {
          sources.push(...config.source.map(source => ({
            title: '[' + config.id + '] ' + config.name,
            data: source
          })))
        } else {
          sources.push({
            title: '[' + config.id + '] ' + config.name,
            data: config.source
          })
        }
      }
      return sources
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.config-source-key {
  vertical-align: top;
  font-weight: bold;
  text-align: right;
  padding-right: 16px;
}
</style>