diff --git a/public/js/components/Tabs.js b/public/js/components/Tabs.js index 7d2cf0500..1e77fa996 100644 --- a/public/js/components/Tabs.js +++ b/public/js/components/Tabs.js @@ -11,9 +11,14 @@ export default { 'changed' ], props: { - configUrl: String, + // TODO(chris): rename to config? + configUrl: { + type: [String, Object], + required: true + }, default: String, - modelValue: [String, Number, Boolean, Array, Object, Date, Function, Symbol] + modelValue: [String, Number, Boolean, Array, Object, Date, Function, Symbol], + vertical: Boolean }, data() { return { @@ -37,60 +42,70 @@ export default { } } }, + watch: { + configUrl(n) { + this.initConfig(n); + } + }, methods: { change(key) { this.$emit("change", key) this.current = key; this.$nextTick(() => this.$emit("changed", key)); - } - }, - created() { - CoreRESTClient - .get(this.configUrl) - .then(result => CoreRESTClient.getData(result.data)) - .then(result => { - if (!result) - return; + }, + initConfig(config) { + if (!config) + return; + if (typeof config === 'string' || config instanceof String) + return CoreRESTClient.get(config) + .then(result => CoreRESTClient.getData(result.data)) + .then(this.initConfig) + .catch(this.$fhcAlert.handleSystemError); - const tabs = {}; + console.log(config); + const tabs = {}; - if (Array.isArray(result)) { - result.forEach((config, key) => { - if (!config.component) - return console.error('Component missing for ' + key); + if (Array.isArray(config)) { + config.forEach((item, key) => { + if (!item.component) + return console.error('Component missing for ' + key); - tabs[key] = { - component: Vue.markRaw(Vue.defineAsyncComponent(() => import(config.component))), - title: config.title || key, - config: config.config, - 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); - } else { - Object.entries(result).forEach(([key, config]) => { - if (!config.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(config.component))), - title: config.title || key, - config: config.config, - key - } - }); - } + if (this.current === null || !tabs[this.current]) { if (tabs[this.default]) this.current = this.default; else this.current = Object.keys(tabs)[0]; - this.tabs = tabs; - }) - .catch(this.$fhcAlert.handleSystemError); + } + this.tabs = tabs; + } + }, + created() { + this.initConfig(this.configUrl); }, template: ` -
-