[Plugin] Notification, wenn Plugin im Backend nicht verfügbar.
Fixed Typo
This commit is contained in:
		
							parent
							
								
									fde2682681
								
							
						
					
					
						commit
						5f7c515228
					
				|  | @ -1,4 +1,4 @@ | |||
| module.exports = { | ||||
|   singleQuote: true, | ||||
|   semi: false | ||||
| } | ||||
|   semi: true | ||||
| }; | ||||
|  |  | |||
|  | @ -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
 | ||||
|  |  | |||
|  | @ -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<Backend | null>, | ||||
|   plugins: Plugin[], | ||||
|   store: Store<any> | ||||
| ): 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<Backend | null> { | ||||
|   let backend: Backend | null = null; | ||||
|   try { | ||||
|     const response: AxiosResponse<Backend> = 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<Store<StateInterface>>(({ Vue, router, store }) => { | ||||
| export default boot<Store<StateInterface>>(({Vue, router, store}) => { | ||||
|   const plugins: Plugin[] = []; | ||||
| 
 | ||||
|   const backendPromise = getBackend(); | ||||
| 
 | ||||
|   let loadedPlugins: FG_Plugin.LoadedPlugins = { | ||||
|     routes, | ||||
|     plugins: [], | ||||
|  | @ -208,10 +267,11 @@ export default boot<Store<StateInterface>>(({ 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); | ||||
| 
 | ||||
|  |  | |||
|  | @ -30,6 +30,7 @@ declare namespace FG_Plugin { | |||
|     version: string; | ||||
|     widgets: Widget[]; | ||||
|     requiredModules: string[]; | ||||
|     requiredBackendModules: string[]; | ||||
|     mainRoutes?: PluginRouteConfig[]; | ||||
|     outRoutes?: PluginRouteConfig[]; | ||||
|     store?: Map<string, Module<any, StateInterface>>; | ||||
|  |  | |||
|  | @ -8,6 +8,7 @@ const plugin: FG_Plugin.Plugin = { | |||
|   name: 'Balance', | ||||
|   mainRoutes, | ||||
|   requiredModules: ['User'], | ||||
|   requiredBackendModules: ['balance'], | ||||
|   version: '0.0.1', | ||||
|   store: new Map<string, Module<BalanceInterface, StateInterface>>([ | ||||
|     ['balance', balance] | ||||
|  |  | |||
|  | @ -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: [ | ||||
|     { | ||||
|  |  | |||
|  | @ -9,6 +9,7 @@ const plugin: FG_Plugin.Plugin = { | |||
|   name: 'User', | ||||
|   mainRoutes: routes, | ||||
|   requiredModules: [], | ||||
|   requiredBackendModules: ['auth'], | ||||
|   version: '0.0.1', | ||||
|   store: new Map<string, Module<any, StateInterface>>([ | ||||
|     ['user', userStore], | ||||
|  |  | |||
|  | @ -113,7 +113,7 @@ const actions: ActionTree<UserStateInterface, StateInterface> = { | |||
|   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<UserStateInterface, StateInterface> = { | |||
|       .finally(() => commit('setLoading', false)); | ||||
|   }, | ||||
| 
 | ||||
|   updateRole({ commit, state }, data: FG.Role) { | ||||
|   updateRole({ commit }, data: FG.Role) { | ||||
|     commit('setLoading'); | ||||
|     axios | ||||
|       .put(`/roles/${data.id}`, data) | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue