From 897c98c53a2e9c6887d9f4fd3bba7699a4aa75bc Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Sat, 30 Jan 2021 08:38:44 +0100 Subject: [PATCH] [Vue3] Fixed users plugin and some basic stuff, still broken. --- quasar.conf.js | 2 +- src/boot/loading.ts | 5 +- src/boot/plugins.ts | 41 +++++----- src/components/navigation/EssentialLink.vue | 2 +- src/components/utils/IsoDateInput.vue | 10 +-- src/layouts/MainLayout.vue | 7 +- src/layouts/OutLayout.vue | 9 ++- src/pages/Dashboard.vue | 6 +- src/pages/Login.vue | 4 +- src/pages/Reset.vue | 2 +- src/plugins.d.ts | 1 + src/plugins/user/components/NewUser.vue | 11 +-- src/plugins/user/components/UpdateUser.vue | 12 +-- src/plugins/user/components/UserSelector.vue | 19 ++--- src/plugins/user/components/Widget.vue | 20 ++--- .../components/settings/MainUserSettings.vue | 74 ++++++++----------- .../user/components/settings/RoleSettings.vue | 22 +++--- .../user/components/settings/Sessions.vue | 28 ++++--- src/plugins/user/pages/AdminSettings.vue | 20 ++--- src/plugins/user/pages/MainPage.vue | 12 ++- src/plugins/user/pages/Settings.vue | 18 ++--- src/plugins/user/plugin.ts | 15 ++-- src/plugins/user/routes/index.ts | 2 +- src/plugins/user/store/session.ts | 29 ++++---- 24 files changed, 184 insertions(+), 187 deletions(-) diff --git a/quasar.conf.js b/quasar.conf.js index 24abfa1..5c1f04c 100644 --- a/quasar.conf.js +++ b/quasar.conf.js @@ -29,7 +29,7 @@ module.exports = configure(function (/* ctx */) { // app boot file (/src/boot) // --> boot files are part of "main.js" // https://quasar.dev/quasar-cli/boot-files - boot: ['axios', 'plugins', 'loading', 'filter', 'login'], + boot: ['axios', 'plugins', 'loading', 'login'], // https://quasar.dev/quasar-cli/quasar-conf-js#Property%3A-css css: ['app.scss'], diff --git a/src/boot/loading.ts b/src/boot/loading.ts index 56b4e14..1374164 100644 --- a/src/boot/loading.ts +++ b/src/boot/loading.ts @@ -1,6 +1,6 @@ import { boot } from 'quasar/wrappers'; import { Loading } from 'quasar'; -import DarkCircularProgress from 'components/loading/DarkCircularProgress.vue'; +//import DarkCircularProgress from 'components/loading/DarkCircularProgress.vue'; // "async" is optional; // more info on params: https://quasar.dev/quasar-cli/cli-documentation/boot-files#Anatomy-of-a-boot-file @@ -8,6 +8,7 @@ export default boot(() => { Loading.setDefaults({ // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - spinner: DarkCircularProgress, + // spinner: DarkCircularProgress, + // TODO : Das funktioniert wohl erstmal nicht mehr... gibt ne exception }); }); diff --git a/src/boot/plugins.ts b/src/boot/plugins.ts index bda6085..81e9f62 100644 --- a/src/boot/plugins.ts +++ b/src/boot/plugins.ts @@ -2,12 +2,12 @@ import { boot } from 'quasar/wrappers'; import { Store } from 'vuex'; import { FG_Plugin } from 'src/plugins'; import routes from 'src/router/routes'; -import { axios } from 'boot/axios'; +import { api } from 'boot/axios'; import { AxiosResponse } from 'axios'; import { Router, RouteRecordRaw } from 'vue-router'; import { UserSessionState } from 'src/plugins/user/store'; -const config = { +const config: { [key: string]: Array } = { // Do not change required Modules !! requiredModules: ['User'], // here you can import plugins. @@ -39,43 +39,49 @@ function setPermissions(object: FG_Plugin.PluginRouteConfig) { object.route.meta['permissions'] = object.permissions; } +function convertRoutes(parent: RouteRecordRaw, children?: FG_Plugin.PluginRouteConfig[]) { + if (children === undefined) return; + + children.forEach((child) => { + setPermissions(child); + convertRoutes(child.route, child.children); + if (parent.children === undefined) parent.children = []; + parent.children.push(child.route); + }); +} + function combineRoutes( target: RouteRecordRaw[], source: FG_Plugin.PluginRouteConfig[], mainPath: '/' | '/main' = '/' ): RouteRecordRaw[] { + // Search parent target.forEach((target) => { if (target.path === mainPath) { + // Parent found = target source.forEach((sourceMainConfig: FG_Plugin.PluginRouteConfig) => { + // Check if source is already in target const targetMainConfig = target.children?.find((targetMainConfig: RouteRecordRaw) => { return sourceMainConfig.route.path === targetMainConfig.path; }); + // Already in target routes, add only children if (targetMainConfig) { - const sourceChildren: RouteRecordRaw[] = []; - sourceMainConfig.children?.forEach((child) => { - setPermissions(child); - sourceChildren.push(child.route); - }); - if (targetMainConfig.children) { - targetMainConfig.children = Object.assign(targetMainConfig.children, sourceChildren); - } else { - targetMainConfig.children = sourceChildren; - } + convertRoutes(targetMainConfig, sourceMainConfig.children); } else { + // Append to target if (target.children === undefined) { target.children = []; } + convertRoutes(sourceMainConfig.route, sourceMainConfig.children); if ( sourceMainConfig.children && sourceMainConfig.children.length > 0 && !sourceMainConfig.route.component ) - target.children.push({ + Object.assign(sourceMainConfig.route, { component: () => import('src/components/navigation/EmptyParent.vue'), - name: sourceMainConfig.route.name, - path: sourceMainConfig.route.path, }); - else target.children.push(sourceMainConfig.route); + target.children.push(sourceMainConfig.route); } }); } @@ -168,6 +174,7 @@ function loadPlugin( loadedPlugins.mainLinks = combineMainLinks(loadedPlugins.mainLinks, route); }); loadedPlugins.shortcuts = loadShortCuts(loadedPlugins.shortcuts, plugin.mainRoutes); + console.log(loadedPlugins); } if (plugin.outRoutes) { loadedPlugins.routes = combineRoutes(loadedPlugins.routes, plugin.outRoutes); @@ -199,7 +206,7 @@ function loadPlugin( async function getBackend(): Promise { let backend: Backend | null = null; try { - const response: AxiosResponse = await axios.get('/'); + const response: AxiosResponse = await api.get('/'); backend = response.data; } catch (e) { console.log(e); diff --git a/src/components/navigation/EssentialLink.vue b/src/components/navigation/EssentialLink.vue index c870a7f..7bd4401 100644 --- a/src/components/navigation/EssentialLink.vue +++ b/src/components/navigation/EssentialLink.vue @@ -33,7 +33,7 @@ export default defineComponent({ link: { type: String, - default: 'home', + default: 'dashboard', }, icon: { diff --git a/src/components/utils/IsoDateInput.vue b/src/components/utils/IsoDateInput.vue index ea25661..95f44ce 100644 --- a/src/components/utils/IsoDateInput.vue +++ b/src/components/utils/IsoDateInput.vue @@ -38,14 +38,6 @@ diff --git a/src/pages/Dashboard.vue b/src/pages/Dashboard.vue index 74ebd1c..2ad758b 100644 --- a/src/pages/Dashboard.vue +++ b/src/pages/Dashboard.vue @@ -11,18 +11,18 @@