From fe1fae10f5d6e3a3520a2d828ce96be73f1cc311 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Thu, 29 Jul 2021 18:26:38 +0200 Subject: [PATCH] [plugins]: Allow ordering menu links, fixes #10 --- package.json | 10 +++++----- src/boot/plugins.ts | 39 +++++++++++++-------------------------- src/pages/Login.vue | 3 +-- src/pages/Offline.vue | 3 +-- 4 files changed, 20 insertions(+), 35 deletions(-) diff --git a/package.json b/package.json index 22f520d..f239571 100644 --- a/package.json +++ b/package.json @@ -19,13 +19,13 @@ "@flaschengeist/users": "^1.0.0-alpha.1", "axios": "^0.21.1", "cordova": "^10.0.0", - "pinia": "^2.0.0-beta.3", - "quasar": "^2.0.1" + "pinia": "2.0.0-beta.5", + "quasar": "^2.0.3" }, "devDependencies": { - "@flaschengeist/types": "^1.0.0-alpha.1", - "@quasar/app": "^3.0.1", - "@quasar/extras": "^1.10.7", + "@flaschengeist/types": "^1.0.0-alpha.2", + "@quasar/app": "^3.0.3", + "@quasar/extras": "^1.10.9", "@types/node": "^12.20.15", "@types/webpack": "^5.28.0", "@types/webpack-env": "^1.16.0", diff --git a/src/boot/plugins.ts b/src/boot/plugins.ts index fd649eb..5a467ca 100644 --- a/src/boot/plugins.ts +++ b/src/boot/plugins.ts @@ -118,11 +118,7 @@ function combineMenuRoutes( target.children = []; } convertRoutes(sourceMainConfig.route, sourceMainConfig.children); - if ( - sourceMainConfig.children && - sourceMainConfig.children.length > 0 && - !sourceMainConfig.route.component - ) + if (sourceMainConfig.children && sourceMainConfig.children.length > 0 && !sourceMainConfig.route.component) Object.assign(sourceMainConfig.route, { component: () => import('src/components/navigation/EmptyParent.vue'), }); @@ -134,20 +130,14 @@ function combineMenuRoutes( return target; } -function combineRoutes( - target: RouteRecordRaw[], - source: FG_Plugin.NamedRouteRecordRaw[], - mainPath: '/' | '/in' -) { +function combineRoutes(target: RouteRecordRaw[], source: FG_Plugin.NamedRouteRecordRaw[], mainPath: '/' | '/in') { // Search parent target.forEach((target) => { if (target.path === mainPath) { // Parent found = target source.forEach((sourceRoute) => { // Check if source is already in target - const targetRoot = target.children?.find( - (targetRoot) => sourceRoute.path === targetRoot.path - ); + const targetRoot = target.children?.find((targetRoot) => sourceRoute.path === targetRoot.path); // Already in target routes, add only children if (targetRoot) { if (targetRoot.children === undefined) targetRoot.children = []; @@ -155,11 +145,7 @@ function combineRoutes( } else { // Append to target if (target.children === undefined) target.children = []; - if ( - sourceRoute.children && - sourceRoute.children.length > 0 && - sourceRoute.component === undefined - ) + if (sourceRoute.children && sourceRoute.children.length > 0 && sourceRoute.component === undefined) Object.assign(sourceRoute, { component: () => import('src/components/navigation/EmptyParent.vue'), }); @@ -225,11 +211,7 @@ function combineShortcuts(target: FG_Plugin.Shortcut[], source: FG_Plugin.MenuRo * @param plugin Plugin to load * @param router VueRouter instance */ -function loadPlugin( - loadedPlugins: FG_Plugin.Flaschengeist, - plugin: FG_Plugin.Plugin, - backend: Backend -) { +function loadPlugin(loadedPlugins: FG_Plugin.Flaschengeist, plugin: FG_Plugin.Plugin, backend: Backend) { // Check if already loaded if (loadedPlugins.plugins.findIndex((p) => p.name === plugin.name) !== -1) return true; @@ -238,8 +220,7 @@ function loadPlugin( !plugin.requiredModules.every( (required) => backend.plugins[required[0]] !== undefined && - (required.length == 1 || - true) /* validate the version, semver440 from python is... tricky on node*/ + (required.length == 1 || true) /* validate the version, semver440 from python is... tricky on node*/ ) ) { console.error(`Plugin ${plugin.name}: Backend modules not satisfied`); @@ -333,7 +314,13 @@ export default boot(async ({ router, app }) => { } // Sort widgets by priority - loadedPlugins.widgets.sort((a, b) => b.priority - a.priority); + /** @todo Remove priority with first beta */ + loadedPlugins.widgets.sort((a, b) => (b.order || b.priority) - (a.order || a.priority)); + /** @todo Can be cleaned up with first beta */ + loadedPlugins.menuLinks.sort((a, b) => { + const diff = a.order && b.order ? b.order - a.order : 0; + return diff ? diff : a.title.toString().localeCompare(b.title.toString()); + }); // Add loaded routes to router loadedPlugins.routes.forEach((route) => router.addRoute(route)); diff --git a/src/pages/Login.vue b/src/pages/Login.vue index 302da91..ddf34f9 100644 --- a/src/pages/Login.vue +++ b/src/pages/Login.vue @@ -145,8 +145,7 @@ export default defineComponent({ Notify.create({ group: false, type: 'ongoing', - message: - 'Sollte der Benutzername korrekt und vorhanden sein, erhälst du jetzt eine E-Mail.', + message: 'Sollte der Benutzername korrekt und vorhanden sein, erhälst du jetzt eine E-Mail.', timeout: 10000, progress: true, actions: [{ icon: 'mdi-close', color: 'white' }], diff --git a/src/pages/Offline.vue b/src/pages/Offline.vue index f3a1ce4..85f3a72 100644 --- a/src/pages/Offline.vue +++ b/src/pages/Offline.vue @@ -46,8 +46,7 @@ export default defineComponent({ const ival = setInterval(() => { reload.value -= 1; if (reload.value <= 0) { - if (router.currentRoute.value.params && 'refresh' in router.currentRoute.value.params) - router.go(0); + if (router.currentRoute.value.params && 'refresh' in router.currentRoute.value.params) router.go(0); const path = router.currentRoute.value.query.redirect; void router.replace(path ? { path: path } : { name: 'login' }); }