From 5f7c5152284a86977afbe0a2b6ae5b28b4b22285 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Fri, 13 Nov 2020 13:42:15 +0100 Subject: [PATCH] =?UTF-8?q?[Plugin]=20Notification,=20wenn=20Plugin=20im?= =?UTF-8?q?=20Backend=20nicht=20verf=C3=BCgbar.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed Typo --- .prettierrc.js | 4 +- quasar.conf.js | 6 +-- src/boot/plugins.ts | 74 ++++++++++++++++++++++++++++++---- src/plugins.d.ts | 1 + src/plugins/balance/plugin.ts | 1 + src/plugins/schedule/plugin.ts | 1 + src/plugins/user/plugin.ts | 1 + src/plugins/user/store/user.ts | 4 +- 8 files changed, 78 insertions(+), 14 deletions(-) diff --git a/.prettierrc.js b/.prettierrc.js index a6b80c2..6013476 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -1,4 +1,4 @@ module.exports = { singleQuote: true, - semi: false -} + semi: true +}; diff --git a/quasar.conf.js b/quasar.conf.js index 06d833d..65dde83 100644 --- a/quasar.conf.js +++ b/quasar.conf.js @@ -24,7 +24,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: ['composition-api', 'axios', 'filter', 'login', 'plugins', 'loading'], + boot: ['composition-api', 'axios', 'plugins', 'loading', 'filter', 'login'], // https://quasar.dev/quasar-cli/quasar-conf-js#Property%3A-css css: ['app.scss'], @@ -89,7 +89,7 @@ module.exports = configure(function(ctx) { iconSet: 'material-icons', // Quasar icon set lang: 'de', // Quasar language pack config: { - dark: 'auto' + dark: 'auto' }, // Possible values for "importStrategy": @@ -105,7 +105,7 @@ module.exports = configure(function(ctx) { // directives: [], // Quasar plugins - plugins: ['LocalStorage', 'SessionStorage', 'Loading'] + plugins: ['LocalStorage', 'SessionStorage', 'Loading', 'Notify'] }, // animations: 'all', // --- includes all animations diff --git a/src/boot/plugins.ts b/src/boot/plugins.ts index 3b3f2dc..382a85f 100644 --- a/src/boot/plugins.ts +++ b/src/boot/plugins.ts @@ -1,9 +1,12 @@ -import { boot } from 'quasar/wrappers'; -import { RouteConfig } from 'vue-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 {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 {Notify} from 'quasar'; const config = { // Do not change required Modules !! @@ -16,6 +19,22 @@ const config = { // combine routes from source to target +interface BackendPlugin { + permissions: string[]; + version: string; +} + +interface BackendPlugins { + [key: string]: BackendPlugin +} + +interface Backend { + plugins: [key: string]; + version: string; +} + +export {Backend} + function combineRoutes( target: RouteConfig[], source: FG_Plugin.PluginRouteConfig[], @@ -127,6 +146,7 @@ function loadShortCuts( function loadPlugin( loadedPlugins: FG_Plugin.LoadedPlugins, modules: string[], + backendpromise: Promise, plugins: Plugin[], store: Store ): FG_Plugin.LoadedPlugins { @@ -135,6 +155,29 @@ function loadPlugin( return plugin.name == requiredModule; }); if (plugin) { + backendpromise.then((backend) => { + console.log(backend) + if (backend) { + const missedPlugins: string[] = [] + plugin.requiredBackendModules.every(requiredBackendModule => { + if (!(requiredBackendModule in backend.plugins)) { + missedPlugins.push(requiredBackendModule) + console.error(`Plugin ${requiredBackendModule} not activated in backend.`) + Notify.create({ + message: `Plugin ${requiredBackendModule} not activated in backend.`, + position: 'bottom', + timeout: 5000, + type: 'negative' + }) + } + return requiredBackendModule in backend.plugins + }) + + } + }) + .catch(e => { + console.error(e) + }) if (plugin.mainRoutes) { loadedPlugins.routes = combineRoutes( loadedPlugins.routes, @@ -184,10 +227,26 @@ function loadPlugin( return loadedPlugins; } +async function getBackend(): Promise { + let backend: Backend | null = null; + try { + const response: AxiosResponse = await axios.get('/'); + backend = response.data; + } catch (e) { + console.log(e); + return null; + } finally { + return backend; + } +} + // "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: Plugin[] = []; + + const backendPromise = getBackend(); + let loadedPlugins: FG_Plugin.LoadedPlugins = { routes, plugins: [], @@ -208,10 +267,11 @@ export default boot>(({ Vue, router, store }) => { loadedPlugins = loadPlugin( loadedPlugins, config.requiredModules, + backendPromise, plugins, store ); - loadedPlugins = loadPlugin(loadedPlugins, config.loadModules, plugins, store); + loadedPlugins = loadPlugin(loadedPlugins, config.loadModules, backendPromise, plugins, store); loadedPlugins.widgets.sort((a, b) => b.priority - a.priority); diff --git a/src/plugins.d.ts b/src/plugins.d.ts index a446976..15b7087 100644 --- a/src/plugins.d.ts +++ b/src/plugins.d.ts @@ -30,6 +30,7 @@ declare namespace FG_Plugin { version: string; widgets: Widget[]; requiredModules: string[]; + requiredBackendModules: string[]; mainRoutes?: PluginRouteConfig[]; outRoutes?: PluginRouteConfig[]; store?: Map>; diff --git a/src/plugins/balance/plugin.ts b/src/plugins/balance/plugin.ts index 31a0f2d..b411f8c 100644 --- a/src/plugins/balance/plugin.ts +++ b/src/plugins/balance/plugin.ts @@ -8,6 +8,7 @@ const plugin: FG_Plugin.Plugin = { name: 'Balance', mainRoutes, requiredModules: ['User'], + requiredBackendModules: ['balance'], version: '0.0.1', store: new Map>([ ['balance', balance] diff --git a/src/plugins/schedule/plugin.ts b/src/plugins/schedule/plugin.ts index 124ee48..8565d4c 100644 --- a/src/plugins/schedule/plugin.ts +++ b/src/plugins/schedule/plugin.ts @@ -3,6 +3,7 @@ import { FG_Plugin } from 'src/plugins'; const plugin: FG_Plugin.Plugin = { name: 'Schedule', requiredModules: [], + requiredBackendModules: ['schedule'], version: '0.0.1', widgets: [ { diff --git a/src/plugins/user/plugin.ts b/src/plugins/user/plugin.ts index d6767a8..1f5e3b8 100644 --- a/src/plugins/user/plugin.ts +++ b/src/plugins/user/plugin.ts @@ -9,6 +9,7 @@ const plugin: FG_Plugin.Plugin = { name: 'User', mainRoutes: routes, requiredModules: [], + requiredBackendModules: ['auth'], version: '0.0.1', store: new Map>([ ['user', userStore], diff --git a/src/plugins/user/store/user.ts b/src/plugins/user/store/user.ts index 26569ea..7c3699b 100644 --- a/src/plugins/user/store/user.ts +++ b/src/plugins/user/store/user.ts @@ -113,7 +113,7 @@ const actions: ActionTree = { setUser({ commit, state, dispatch }, data: FG.User) { commit('setLoading'); axios - .post(`users`, data) + .post('users', data) .then(() => { if (state.currentUser && state.currentUser.userid === data.userid) void dispatch('getCurrentUser'); @@ -138,7 +138,7 @@ const actions: ActionTree = { .finally(() => commit('setLoading', false)); }, - updateRole({ commit, state }, data: FG.Role) { + updateRole({ commit }, data: FG.Role) { commit('setLoading'); axios .put(`/roles/${data.id}`, data)