[Plugin] Notification, wenn Plugin im Backend nicht verfügbar.

Fixed Typo
This commit is contained in:
Tim Gröger 2020-11-13 13:42:15 +01:00
parent fde2682681
commit 5f7c515228
8 changed files with 78 additions and 14 deletions

View File

@ -1,4 +1,4 @@
module.exports = { module.exports = {
singleQuote: true, singleQuote: true,
semi: false semi: true
} };

View File

@ -24,7 +24,7 @@ module.exports = configure(function(ctx) {
// app boot file (/src/boot) // app boot file (/src/boot)
// --> boot files are part of "main.js" // --> boot files are part of "main.js"
// https://quasar.dev/quasar-cli/boot-files // 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 // https://quasar.dev/quasar-cli/quasar-conf-js#Property%3A-css
css: ['app.scss'], css: ['app.scss'],
@ -89,7 +89,7 @@ module.exports = configure(function(ctx) {
iconSet: 'material-icons', // Quasar icon set iconSet: 'material-icons', // Quasar icon set
lang: 'de', // Quasar language pack lang: 'de', // Quasar language pack
config: { config: {
dark: 'auto' dark: 'auto'
}, },
// Possible values for "importStrategy": // Possible values for "importStrategy":
@ -105,7 +105,7 @@ module.exports = configure(function(ctx) {
// directives: [], // directives: [],
// Quasar plugins // Quasar plugins
plugins: ['LocalStorage', 'SessionStorage', 'Loading'] plugins: ['LocalStorage', 'SessionStorage', 'Loading', 'Notify']
}, },
// animations: 'all', // --- includes all animations // animations: 'all', // --- includes all animations

View File

@ -1,9 +1,12 @@
import { boot } from 'quasar/wrappers'; import {boot} from 'quasar/wrappers';
import { RouteConfig } from 'vue-router'; import {RouteConfig} from 'vue-router';
import { Store } from 'vuex'; import {Store} from 'vuex';
import { StateInterface } from 'src/store'; import {StateInterface} from 'src/store';
import { FG_Plugin } from 'src/plugins'; import {FG_Plugin} from 'src/plugins';
import routes from 'src/router/routes'; import routes from 'src/router/routes';
import {axios} from 'boot/axios';
import {AxiosResponse} from 'axios';
import {Notify} from 'quasar';
const config = { const config = {
// Do not change required Modules !! // Do not change required Modules !!
@ -16,6 +19,22 @@ const config = {
// combine routes from source to target // 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( function combineRoutes(
target: RouteConfig[], target: RouteConfig[],
source: FG_Plugin.PluginRouteConfig[], source: FG_Plugin.PluginRouteConfig[],
@ -127,6 +146,7 @@ function loadShortCuts(
function loadPlugin( function loadPlugin(
loadedPlugins: FG_Plugin.LoadedPlugins, loadedPlugins: FG_Plugin.LoadedPlugins,
modules: string[], modules: string[],
backendpromise: Promise<Backend | null>,
plugins: Plugin[], plugins: Plugin[],
store: Store<any> store: Store<any>
): FG_Plugin.LoadedPlugins { ): FG_Plugin.LoadedPlugins {
@ -135,6 +155,29 @@ function loadPlugin(
return plugin.name == requiredModule; return plugin.name == requiredModule;
}); });
if (plugin) { 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) { if (plugin.mainRoutes) {
loadedPlugins.routes = combineRoutes( loadedPlugins.routes = combineRoutes(
loadedPlugins.routes, loadedPlugins.routes,
@ -184,10 +227,26 @@ function loadPlugin(
return loadedPlugins; 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; // "async" is optional;
// more info on params: https://quasar.dev/quasar-cli/cli-documentation/boot-files#Anatomy-of-a-boot-file // 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 plugins: Plugin[] = [];
const backendPromise = getBackend();
let loadedPlugins: FG_Plugin.LoadedPlugins = { let loadedPlugins: FG_Plugin.LoadedPlugins = {
routes, routes,
plugins: [], plugins: [],
@ -208,10 +267,11 @@ export default boot<Store<StateInterface>>(({ Vue, router, store }) => {
loadedPlugins = loadPlugin( loadedPlugins = loadPlugin(
loadedPlugins, loadedPlugins,
config.requiredModules, config.requiredModules,
backendPromise,
plugins, plugins,
store 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); loadedPlugins.widgets.sort((a, b) => b.priority - a.priority);

1
src/plugins.d.ts vendored
View File

@ -30,6 +30,7 @@ declare namespace FG_Plugin {
version: string; version: string;
widgets: Widget[]; widgets: Widget[];
requiredModules: string[]; requiredModules: string[];
requiredBackendModules: string[];
mainRoutes?: PluginRouteConfig[]; mainRoutes?: PluginRouteConfig[];
outRoutes?: PluginRouteConfig[]; outRoutes?: PluginRouteConfig[];
store?: Map<string, Module<any, StateInterface>>; store?: Map<string, Module<any, StateInterface>>;

View File

@ -8,6 +8,7 @@ const plugin: FG_Plugin.Plugin = {
name: 'Balance', name: 'Balance',
mainRoutes, mainRoutes,
requiredModules: ['User'], requiredModules: ['User'],
requiredBackendModules: ['balance'],
version: '0.0.1', version: '0.0.1',
store: new Map<string, Module<BalanceInterface, StateInterface>>([ store: new Map<string, Module<BalanceInterface, StateInterface>>([
['balance', balance] ['balance', balance]

View File

@ -3,6 +3,7 @@ import { FG_Plugin } from 'src/plugins';
const plugin: FG_Plugin.Plugin = { const plugin: FG_Plugin.Plugin = {
name: 'Schedule', name: 'Schedule',
requiredModules: [], requiredModules: [],
requiredBackendModules: ['schedule'],
version: '0.0.1', version: '0.0.1',
widgets: [ widgets: [
{ {

View File

@ -9,6 +9,7 @@ const plugin: FG_Plugin.Plugin = {
name: 'User', name: 'User',
mainRoutes: routes, mainRoutes: routes,
requiredModules: [], requiredModules: [],
requiredBackendModules: ['auth'],
version: '0.0.1', version: '0.0.1',
store: new Map<string, Module<any, StateInterface>>([ store: new Map<string, Module<any, StateInterface>>([
['user', userStore], ['user', userStore],

View File

@ -113,7 +113,7 @@ const actions: ActionTree<UserStateInterface, StateInterface> = {
setUser({ commit, state, dispatch }, data: FG.User) { setUser({ commit, state, dispatch }, data: FG.User) {
commit('setLoading'); commit('setLoading');
axios axios
.post(`users`, data) .post('users', data)
.then(() => { .then(() => {
if (state.currentUser && state.currentUser.userid === data.userid) if (state.currentUser && state.currentUser.userid === data.userid)
void dispatch('getCurrentUser'); void dispatch('getCurrentUser');
@ -138,7 +138,7 @@ const actions: ActionTree<UserStateInterface, StateInterface> = {
.finally(() => commit('setLoading', false)); .finally(() => commit('setLoading', false));
}, },
updateRole({ commit, state }, data: FG.Role) { updateRole({ commit }, data: FG.Role) {
commit('setLoading'); commit('setLoading');
axios axios
.put(`/roles/${data.id}`, data) .put(`/roles/${data.id}`, data)