diff --git a/package.json b/package.json index 0661da1..5a07df1 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,6 @@ "test": "echo \"No test specified\" && exit 0" }, "dependencies": { - "@dreamonkey/vue-routes-flattener": "^0.1.0", "@quasar/extras": "^1.9.10", "@vue/composition-api": "^0.6.4", "axios": "^0.21.0", diff --git a/src/boot/plugins.ts b/src/boot/plugins.ts index d76f349..a5a198a 100644 --- a/src/boot/plugins.ts +++ b/src/boot/plugins.ts @@ -7,7 +7,6 @@ import { FG_Plugin } from 'src/plugins'; import routes from 'src/router/routes'; import { axios } from 'boot/axios'; import { AxiosResponse } from 'axios'; -import { flatRoutes } from '@dreamonkey/vue-routes-flattener'; const config = { // Do not change required Modules !! @@ -44,21 +43,16 @@ function combineRoutes( target.forEach(target => { if (target.path === mainPath) { source.forEach((sourceMainConfig: FG_Plugin.PluginRouteConfig) => { - const targetMainConfig = target.children?.find( - (targetMainConfig: RouteConfig) => { - return sourceMainConfig.path === targetMainConfig.path; - } - ); + const targetMainConfig = target.children?.find((targetMainConfig: RouteConfig) => { + return sourceMainConfig.path === targetMainConfig.path; + }); if (targetMainConfig) { const sourceChildren: RouteConfig[] = []; sourceMainConfig.children?.forEach(child => { sourceChildren.push(child); }); if (targetMainConfig.children) { - targetMainConfig.children = Object.assign( - targetMainConfig.children, - sourceChildren - ); + targetMainConfig.children = Object.assign(targetMainConfig.children, sourceChildren); } else { targetMainConfig.children = sourceChildren; } @@ -66,6 +60,12 @@ function combineRoutes( if (target.children === undefined) { target.children = []; } + if ( + sourceMainConfig.children && + sourceMainConfig.children.length > 0 && + !sourceMainConfig.component + ) + sourceMainConfig.component = () => import('src/components/navigation/EmptyParent.vue'); target.children.push(sourceMainConfig); } }); @@ -79,26 +79,22 @@ function combineMainLinks( target: FG_Plugin.PluginMainLink[], source: FG_Plugin.PluginRouteConfig ): FG_Plugin.PluginMainLink[] { - const targetPluginMainLink: - | FG_Plugin.PluginMainLink - | undefined = target.find( + const targetPluginMainLink: FG_Plugin.PluginMainLink | undefined = target.find( (targetPluginMainLink: FG_Plugin.PluginMainLink) => { console.log(targetPluginMainLink.title, source.title); return targetPluginMainLink.title == source.title; } ); if (targetPluginMainLink) { - source.children?.forEach( - (sourcePluginChildLink: FG_Plugin.PluginRouteConfig) => { - targetPluginMainLink.children.push({ - title: sourcePluginChildLink.title, - icon: sourcePluginChildLink.icon, - link: sourcePluginChildLink.name, - name: sourcePluginChildLink.name, - permissions: sourcePluginChildLink.meta?.permissions - }); - } - ); + source.children?.forEach((sourcePluginChildLink: FG_Plugin.PluginRouteConfig) => { + targetPluginMainLink.children.push({ + title: sourcePluginChildLink.title, + icon: sourcePluginChildLink.icon, + link: sourcePluginChildLink.name, + name: sourcePluginChildLink.name, + permissions: sourcePluginChildLink.meta?.permissions + }); + }); } else { const mainLink: FG_Plugin.PluginMainLink = { title: source.title, @@ -158,36 +154,18 @@ function loadPlugin( }); if (plugin) { if (plugin.mainRoutes) { - loadedPlugins.routes = combineRoutes( - loadedPlugins.routes, - plugin.mainRoutes, - '/main' - ); + loadedPlugins.routes = combineRoutes(loadedPlugins.routes, plugin.mainRoutes, '/main'); plugin.mainRoutes.forEach(route => { - loadedPlugins.mainLinks = combineMainLinks( - loadedPlugins.mainLinks, - route - ); + loadedPlugins.mainLinks = combineMainLinks(loadedPlugins.mainLinks, route); }); - loadedPlugins.shortcuts = loadShortCuts( - loadedPlugins.shortcuts, - plugin.mainRoutes - ); + loadedPlugins.shortcuts = loadShortCuts(loadedPlugins.shortcuts, plugin.mainRoutes); } if (plugin.outRoutes) { - loadedPlugins.routes = combineRoutes( - loadedPlugins.routes, - plugin.outRoutes - ); - loadedPlugins.shortcutsOut = loadShortCuts( - loadedPlugins.shortcutsOut, - plugin.outRoutes - ); + loadedPlugins.routes = combineRoutes(loadedPlugins.routes, plugin.outRoutes); + loadedPlugins.shortcutsOut = loadShortCuts(loadedPlugins.shortcutsOut, plugin.outRoutes); } if (plugin.widgets.length > 0) { - plugin.widgets.forEach( - widget => (widget.name = plugin.name + '_' + widget.name) - ); + plugin.widgets.forEach(widget => (widget.name = plugin.name + '_' + widget.name)); Array.prototype.push.apply(loadedPlugins.widgets, plugin.widgets); } if (plugin.store) { @@ -258,26 +236,22 @@ export default boot>(({ Vue, router, store }) => { config.loadModules.includes(requiredModule) ) ) { - console.error( - `Plugin ${plugin.name} need Plugin ${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); - }); - } + 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); + }); } - ); + }); }); } }) @@ -306,7 +280,7 @@ export default boot>(({ Vue, router, store }) => { loadedPlugins.widgets.sort((a, b) => b.priority - a.priority); // add new routes for plugins, flatten them to allow empty parent routes - router.addRoutes(flatRoutes(loadedPlugins.routes)); + router.addRoutes(loadedPlugins.routes); // save plugins in VM-variable // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access diff --git a/src/components/navigation/EmptyParent.vue b/src/components/navigation/EmptyParent.vue new file mode 100644 index 0000000..4dc75e8 --- /dev/null +++ b/src/components/navigation/EmptyParent.vue @@ -0,0 +1,14 @@ + + + diff --git a/yarn.lock b/yarn.lock index 5d1a863..6336b11 100644 --- a/yarn.lock +++ b/yarn.lock @@ -879,11 +879,6 @@ lodash "^4.17.19" to-fast-properties "^2.0.0" -"@dreamonkey/vue-routes-flattener@^0.1.0": - version "0.1.0" - resolved "https://registry.yarnpkg.com/@dreamonkey/vue-routes-flattener/-/vue-routes-flattener-0.1.0.tgz#cae01481f5c5e34669f700adebb6c34f0e88b0ed" - integrity sha512-kYs2P17btcXTAV6hPgJeuj11H2Hy4kHKroamED87H4RRYjTiA/d7PGixqIFL6631KiaDhUkiNEMhmWcWot/1BA== - "@electron/get@^1.3.1": version "1.12.2" resolved "https://registry.yarnpkg.com/@electron/get/-/get-1.12.2.tgz#6442066afb99be08cefb9a281e4b4692b33764f3"