From f28f21b2f67f5e152e6e9d13814150a4adf316c7 Mon Sep 17 00:00:00 2001
From: Udo Walter
Date: Wed, 27 Nov 2019 17:20:15 +0000
Subject: [configloader] bugfixes in the beta configloader: add hook sources
 correct handeling of multiple sources remove merging of multiple sources with
 the same config

---
 webapp/src/components/ConfigChip.vue | 47 ++++++++++++++++++++++++------------
 1 file changed, 32 insertions(+), 15 deletions(-)

(limited to 'webapp/src/components/ConfigChip.vue')

diff --git a/webapp/src/components/ConfigChip.vue b/webapp/src/components/ConfigChip.vue
index f278fe3..7ae0d08 100644
--- a/webapp/src/components/ConfigChip.vue
+++ b/webapp/src/components/ConfigChip.vue
@@ -27,25 +27,18 @@
     <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>
-      <div v-if="config.source">
-        <table>
-          <tr><td class="config-source-key">{{ $t('source') }}</td><td>{{ config.source.type }}</td></tr>
-          <tr v-if="config.source.id"><td class="config-source-key">{{ $t('id') }}</td><td>{{ config.source.id }}</td></tr>
-          <tr v-if="config.source.name"><td class="config-source-key">{{ $t('name') }}</td><td>{{ config.source.name }}</td></tr>
-        </table>
-      </div>
-      <div v-else-if="config.configs">
-        <div v-for="(subConfig, index) in config.configs" :key="subConfig.id">
+      <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;">[{{ subConfig.id}}] {{ subConfig.name }}</div>
+          <div style="text-align: center; font-weight: bold;">{{ source.title }}</div>
           <table>
-            <tr><td class="config-source-key">{{ $t('source') }}</td><td>{{ subConfig.source.type }}</td></tr>
-            <tr v-if="subConfig.source.id"><td class="config-source-key">{{ $t('id') }}</td><td>{{ subConfig.source.id }}</td></tr>
-            <tr v-if="subConfig.source.name"><td class="config-source-key">{{ $t('name') }}</td><td>{{ subConfig.source.name }}</td></tr>
+            <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>
-      <span v-else>{{ config.name || config.id }}</span>
     </div>
   </v-tooltip>
 </template>
@@ -79,10 +72,34 @@ export default {
       return ''
     },
     isEvent () {
-      return this.config.source && (this.config.source.type === 'IMPORTANT_EVENT' || this.config.source.type === 'EVENT')
+      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>
-- 
cgit v1.2.3-55-g7522

