From 368ca23c568597c9fb89d00f8019fc0f8309345c Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Sat, 27 Nov 2021 00:49:12 +0100 Subject: [PATCH] General cleanup of unused code and small fixes --- package.json | 4 ++-- quasar.conf.js | 2 +- src/boot/axios.ts | 27 +++++++++++++++++++-------- src/boot/loading.ts | 14 -------------- src/boot/login.ts | 8 +++++++- src/boot/plugins.ts | 14 ++++++-------- src/pages/Backend.vue | 2 +- 7 files changed, 36 insertions(+), 35 deletions(-) delete mode 100644 src/boot/loading.ts diff --git a/package.json b/package.json index 8a68f8e..c7fc570 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,6 @@ "lint": "eslint --ext .js,.ts,.vue ./src ./api" }, "dependencies": { - "@capacitor/storage": "^1.2.3", "@flaschengeist/api": "file:./api", "@flaschengeist/users": "^1.0.0-alpha.1", "axios": "^0.24.0", @@ -23,7 +22,8 @@ "quasar": "^2.3.3" }, "devDependencies": { - "@flaschengeist/types": "^1.0.0-alpha.6", + "@capacitor/core": "^3.3.2", + "@capacitor/storage": "^1.2.3", "@quasar/app": "^3.2.3", "@quasar/extras": "^1.12.1", "@types/node": "^14.17.34", diff --git a/quasar.conf.js b/quasar.conf.js index 62796ac..e981046 100644 --- a/quasar.conf.js +++ b/quasar.conf.js @@ -31,7 +31,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', 'store', 'plugins', 'loading', 'login'], + boot: ['axios', 'store', 'plugins', 'login'], // https://quasar.dev/quasar-cli/quasar-conf-js#Property%3A-css css: ['app.scss'], diff --git a/src/boot/axios.ts b/src/boot/axios.ts index 403ea59..0e0ba44 100644 --- a/src/boot/axios.ts +++ b/src/boot/axios.ts @@ -1,18 +1,31 @@ +/** + * This boot file registers interceptors for axios + */ import { useMainStore, api } from '@flaschengeist/api'; import { AxiosError } from 'axios'; import { boot } from 'quasar/wrappers'; import config from 'src/config'; import { clone } from '@flaschengeist/api'; -function minify(o: unknown, cloned = false) { - if (!cloned) o = clone(o); +/** + * Minify data sent to backend server + * + * Drop unneeded entities which can be identified by ID. + * + * @param obj Object to minify + * @param cloned If this entity is already cloned (JSON En+Decoded) + * @returns Minified object (some types are converted, like a Date object is now a ISO string) + */ +function minify(entity: unknown, cloned = false) { + if (!cloned) entity = clone(entity); - if (typeof o === 'object') { - const obj = o as { [index: string]: unknown }; + if (typeof entity === 'object') { + const obj = entity as { [index: string]: unknown }; for (const prop in obj) { if (obj.hasOwnProperty(prop) && !!obj[prop]) { if (Array.isArray(obj[prop])) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-return obj[prop] = (>obj[prop]).map((v) => minify(v, true)); } else if ( typeof obj[prop] === 'object' && @@ -26,12 +39,12 @@ function minify(o: unknown, cloned = false) { } return obj; } - return o; + return entity; } export default boot(({ router }) => { // Persisted value is read in plugins.ts boot file! - api.defaults.baseURL = config.baseURL; + if (api.defaults.baseURL === undefined) api.defaults.baseURL = config.baseURL; /*** * Intercept requests @@ -93,5 +106,3 @@ export default boot(({ router }) => { } ); }); - -export { api }; diff --git a/src/boot/loading.ts b/src/boot/loading.ts deleted file mode 100644 index 1374164..0000000 --- a/src/boot/loading.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { boot } from 'quasar/wrappers'; -import { Loading } from 'quasar'; -//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 -export default boot(() => { - Loading.setDefaults({ - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - // spinner: DarkCircularProgress, - // TODO : Das funktioniert wohl erstmal nicht mehr... gibt ne exception - }); -}); diff --git a/src/boot/login.ts b/src/boot/login.ts index 7695575..1f4e7a7 100644 --- a/src/boot/login.ts +++ b/src/boot/login.ts @@ -1,3 +1,6 @@ +/** + * This boot file registers login / authentification related axios interceptors + */ import { useMainStore, hasPermissions } from '@flaschengeist/api'; import { boot } from 'quasar/wrappers'; import { RouteRecord } from 'vue-router'; @@ -6,9 +9,11 @@ export default boot(({ router }) => { router.beforeResolve((to, from, next) => { const store = useMainStore(); + // Skip if same path if (to.path == from.path) return next(); - if (to.path.startsWith('/main')) { + // Check if secured area or public + if (to.path.startsWith('/in')) { // Secured area (LOGIN REQUIRED) // Check login is ok if (!store.session || store.session.expires <= new Date()) { @@ -30,6 +35,7 @@ export default boot(({ router }) => { return next({ name: 'login', query: { redirect: to.fullPath } }); } } else { + // Public space just handle login loops if (to.name == 'login' && store.user && !to.params['logout']) { // Called login while already logged in return next({ name: 'dashboard' }); diff --git a/src/boot/plugins.ts b/src/boot/plugins.ts index ab7f195..d89cb20 100644 --- a/src/boot/plugins.ts +++ b/src/boot/plugins.ts @@ -1,10 +1,9 @@ +import { FG_Plugin } from '@flaschengeist/types'; +import { api, PersistentStorage } from '@flaschengeist/api'; +import { RouteRecordRaw } from 'vue-router'; import { Notify, Platform } from 'quasar'; -import { api } from 'src/boot/axios'; import { boot } from 'quasar/wrappers'; import routes from 'src/router/routes'; -import { RouteRecordRaw } from 'vue-router'; -import { FG_Plugin } from '@flaschengeist/types'; -import { PersistentStorage } from '@flaschengeist/api'; /**************************************************** ******** Internal area for some magic ************** @@ -265,10 +264,9 @@ function loadPlugin( } async function loadBaseUrl() { - return PersistentStorage.get('baseURL').then((url) => { - if (url !== null) api.defaults.baseURL = url; - console.log('loaded: ', url, api.defaults.baseURL); - }); + const url = await PersistentStorage.get('baseURL'); + if (url !== null) api.defaults.baseURL = url; + return url; } /** * Loading backend information diff --git a/src/pages/Backend.vue b/src/pages/Backend.vue index 6214b46..a5e6413 100644 --- a/src/pages/Backend.vue +++ b/src/pages/Backend.vue @@ -18,7 +18,7 @@ import { useRouter } from 'vue-router'; import { notEmpty, PersistentStorage } from '@flaschengeist/api'; import { defineComponent, ref } from 'vue'; -import { api } from 'boot/axios'; +import { api } from '@flaschengeist/api'; export default defineComponent({ name: 'PageBackend',