From 291f32bfe22c03de57ded6d9b8a85a971e4deb8d Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Thu, 7 Mar 2024 14:35:29 +0100 Subject: [PATCH] Tabs => FhcApi --- public/js/components/Tabs.js | 50 +++++++++++++++++------------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/public/js/components/Tabs.js b/public/js/components/Tabs.js index 8090a9d29..49d3fabf7 100644 --- a/public/js/components/Tabs.js +++ b/public/js/components/Tabs.js @@ -1,4 +1,3 @@ -import {CoreRESTClient} from '../RESTClient.js'; import accessibility from "../directives/accessibility.js"; export default { @@ -12,7 +11,7 @@ export default { ], props: { config: { - type: [String, Object], + type: [String, Array, Object, Promise], required: true }, default: String, @@ -56,40 +55,37 @@ export default { initConfig(config) { if (!config) return; + if (config instanceof Promise) + return config + .then(result => result.data) + .then(this.initConfig) + .catch(this.$fhcAlert.handleSystemError); if (typeof config === 'string' || config instanceof String) - return CoreRESTClient.get(config) - .then(result => CoreRESTClient.getData(result.data)) + return this.$fhcApi + .get(config) + .then(result => result.data) .then(this.initConfig) .catch(this.$fhcAlert.handleSystemError); const tabs = {}; - if (Array.isArray(config)) { - config.forEach((item, key) => { - if (!item.component) - return console.error('Component missing for ' + key); + function _addToTabs(key, item) { + if (!item.component) + return console.error('Component missing for ' + key); - tabs[key] = { - component: Vue.markRaw(Vue.defineAsyncComponent(() => import(item.component))), - title: item.title || key, - config: item.config, - key - } - }); - } else { - Object.entries(config).forEach(([key, item]) => { - if (!item.component) - return console.error('Component missing for ' + key); - - tabs[key] = { - component: Vue.markRaw(Vue.defineAsyncComponent(() => import(item.component))), - title: item.title || key, - config: item.config, - key - } - }); + tabs[key] = { + component: Vue.markRaw(Vue.defineAsyncComponent(() => import(item.component))), + title: item.title || key, + config: item.config, + key + } } + if (Array.isArray(config)) + config.forEach((item, key) => _addToTabs(key, item)); + else + Object.entries(config).forEach(([key, item]) => _addToTabs(key, item)); + if (this.current === null || !tabs[this.current]) { if (tabs[this.default]) this.current = this.default;