From d4795a549fea0d95d068f0ac5ac40607a45e1942 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Tue, 24 Nov 2020 17:35:11 +0100 Subject: [PATCH] Fixed interface for Backend, allow redirect mainLinks * Fixed the Backend interface to match the returned data structure * Allow empty parents in RouteConfig, use flatRoutes --- src/boot/plugins.ts | 107 +++++++++++++++----------- src/components/utils/IsoDateInput.vue | 1 - 2 files changed, 63 insertions(+), 45 deletions(-) diff --git a/src/boot/plugins.ts b/src/boot/plugins.ts index e38a70c..d76f349 100644 --- a/src/boot/plugins.ts +++ b/src/boot/plugins.ts @@ -1,12 +1,13 @@ -import {boot} from 'quasar/wrappers'; -import {RouteConfig} from 'vue-router'; -import {VueRouter} from 'vue-router/types/router'; -import {Store} from 'vuex'; -import {StateInterface} from 'src/store'; -import {FG_Plugin} from 'src/plugins'; +import { boot } from 'quasar/wrappers'; +import { RouteConfig } from 'vue-router'; +import { VueRouter } from 'vue-router/types/router'; +import { Store } from 'vuex'; +import { StateInterface } from 'src/store'; +import { FG_Plugin } from 'src/plugins'; import routes from 'src/router/routes'; -import {axios} from 'boot/axios'; -import {AxiosResponse} from 'axios'; +import { axios } from 'boot/axios'; +import { AxiosResponse } from 'axios'; +import { flatRoutes } from '@dreamonkey/vue-routes-flattener'; const config = { // Do not change required Modules !! @@ -25,15 +26,15 @@ interface BackendPlugin { } interface BackendPlugins { - [key: string]: BackendPlugin + [key: string]: BackendPlugin | null; } interface Backend { - plugins: [key: string]; + plugins: BackendPlugins[]; version: string; } -export {Backend} +export { Backend }; function combineRoutes( target: RouteConfig[], @@ -200,9 +201,9 @@ function loadPlugin( }); } else { console.exception(`Could not find required Plugin ${requiredModule}`); - router.push({name: 'error'}).catch((e) => { - console.warn(e) - }) + router.push({ name: 'error' }).catch(e => { + console.warn(e); + }); } }); return loadedPlugins; @@ -223,7 +224,7 @@ async function getBackend(): Promise { // "async" is optional; // more info on params: https://quasar.dev/quasar-cli/cli-documentation/boot-files#Anatomy-of-a-boot-file -export default boot>(({Vue, router, store}) => { +export default boot>(({ Vue, router, store }) => { const plugins: FG_Plugin.Plugin[] = []; const backendPromise = getBackend(); @@ -245,33 +246,44 @@ export default boot>(({Vue, router, store}) => { }); // check dependencies - backendPromise.then((backend) => { - console.log(backend) - if (backend) { - plugins.forEach((plugin: FG_Plugin.Plugin) => { - plugin.requiredModules.forEach((requiredModule: string) => { - if (!(config.requiredModules.includes(requiredModule) || config.loadModules.includes(requiredModule))) { - console.error(`Plugin ${plugin.name} need Plugin ${requiredModule}`) - router.push({name: 'error'}).catch((e) => { - console.warn(e) - }) - } - }) - plugin.requiredBackendModules.forEach((requiredBackendModule: string) => { - if (!(requiredBackendModule in backend.plugins)) { - console.error(`Plugin ${plugin.name} need Plugin ${requiredBackendModule} in backend.`) - router.push({name: 'error'}).catch(err => { - console.warn(err) - }) - } - }) - }) - } - }) - .catch(e => { - console.error(e) + backendPromise + .then(backend => { + console.log(backend); + if (backend) { + plugins.forEach((plugin: FG_Plugin.Plugin) => { + plugin.requiredModules.forEach((requiredModule: string) => { + if ( + !( + config.requiredModules.includes(requiredModule) || + config.loadModules.includes(requiredModule) + ) + ) { + console.error( + `Plugin ${plugin.name} need Plugin ${requiredModule}` + ); + router.push({ name: 'error' }).catch(e => { + console.warn(e); + }); + } + }); + plugin.requiredBackendModules.forEach( + (requiredBackendModule: string) => { + if (!(requiredBackendModule in backend.plugins)) { + console.error( + `Plugin ${plugin.name} need Plugin ${requiredBackendModule} in backend.` + ); + router.push({ name: 'error' }).catch(err => { + console.warn(err); + }); + } + } + ); + }); + } }) - + .catch(e => { + console.error(e); + }); // load plugins loadedPlugins = loadPlugin( @@ -282,12 +294,19 @@ export default boot>(({Vue, router, store}) => { store, router ); - loadedPlugins = loadPlugin(loadedPlugins, config.loadModules, backendPromise, plugins, store, router); + loadedPlugins = loadPlugin( + loadedPlugins, + config.loadModules, + backendPromise, + plugins, + store, + router + ); loadedPlugins.widgets.sort((a, b) => b.priority - a.priority); - // add new routes for plugins - router.addRoutes(loadedPlugins.routes); + // add new routes for plugins, flatten them to allow empty parent routes + router.addRoutes(flatRoutes(loadedPlugins.routes)); // save plugins in VM-variable // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access diff --git a/src/components/utils/IsoDateInput.vue b/src/components/utils/IsoDateInput.vue index d14bbea..5d9bd2a 100644 --- a/src/components/utils/IsoDateInput.vue +++ b/src/components/utils/IsoDateInput.vue @@ -1,6 +1,5 @@