[plugins]: Allow ordering menu links, fixes #10
This commit is contained in:
parent
1c36399ac0
commit
fe1fae10f5
10
package.json
10
package.json
|
@ -19,13 +19,13 @@
|
||||||
"@flaschengeist/users": "^1.0.0-alpha.1",
|
"@flaschengeist/users": "^1.0.0-alpha.1",
|
||||||
"axios": "^0.21.1",
|
"axios": "^0.21.1",
|
||||||
"cordova": "^10.0.0",
|
"cordova": "^10.0.0",
|
||||||
"pinia": "^2.0.0-beta.3",
|
"pinia": "2.0.0-beta.5",
|
||||||
"quasar": "^2.0.1"
|
"quasar": "^2.0.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@flaschengeist/types": "^1.0.0-alpha.1",
|
"@flaschengeist/types": "^1.0.0-alpha.2",
|
||||||
"@quasar/app": "^3.0.1",
|
"@quasar/app": "^3.0.3",
|
||||||
"@quasar/extras": "^1.10.7",
|
"@quasar/extras": "^1.10.9",
|
||||||
"@types/node": "^12.20.15",
|
"@types/node": "^12.20.15",
|
||||||
"@types/webpack": "^5.28.0",
|
"@types/webpack": "^5.28.0",
|
||||||
"@types/webpack-env": "^1.16.0",
|
"@types/webpack-env": "^1.16.0",
|
||||||
|
|
|
@ -118,11 +118,7 @@ function combineMenuRoutes(
|
||||||
target.children = [];
|
target.children = [];
|
||||||
}
|
}
|
||||||
convertRoutes(sourceMainConfig.route, sourceMainConfig.children);
|
convertRoutes(sourceMainConfig.route, sourceMainConfig.children);
|
||||||
if (
|
if (sourceMainConfig.children && sourceMainConfig.children.length > 0 && !sourceMainConfig.route.component)
|
||||||
sourceMainConfig.children &&
|
|
||||||
sourceMainConfig.children.length > 0 &&
|
|
||||||
!sourceMainConfig.route.component
|
|
||||||
)
|
|
||||||
Object.assign(sourceMainConfig.route, {
|
Object.assign(sourceMainConfig.route, {
|
||||||
component: () => import('src/components/navigation/EmptyParent.vue'),
|
component: () => import('src/components/navigation/EmptyParent.vue'),
|
||||||
});
|
});
|
||||||
|
@ -134,20 +130,14 @@ function combineMenuRoutes(
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
function combineRoutes(
|
function combineRoutes(target: RouteRecordRaw[], source: FG_Plugin.NamedRouteRecordRaw[], mainPath: '/' | '/in') {
|
||||||
target: RouteRecordRaw[],
|
|
||||||
source: FG_Plugin.NamedRouteRecordRaw[],
|
|
||||||
mainPath: '/' | '/in'
|
|
||||||
) {
|
|
||||||
// Search parent
|
// Search parent
|
||||||
target.forEach((target) => {
|
target.forEach((target) => {
|
||||||
if (target.path === mainPath) {
|
if (target.path === mainPath) {
|
||||||
// Parent found = target
|
// Parent found = target
|
||||||
source.forEach((sourceRoute) => {
|
source.forEach((sourceRoute) => {
|
||||||
// Check if source is already in target
|
// Check if source is already in target
|
||||||
const targetRoot = target.children?.find(
|
const targetRoot = target.children?.find((targetRoot) => sourceRoute.path === targetRoot.path);
|
||||||
(targetRoot) => sourceRoute.path === targetRoot.path
|
|
||||||
);
|
|
||||||
// Already in target routes, add only children
|
// Already in target routes, add only children
|
||||||
if (targetRoot) {
|
if (targetRoot) {
|
||||||
if (targetRoot.children === undefined) targetRoot.children = [];
|
if (targetRoot.children === undefined) targetRoot.children = [];
|
||||||
|
@ -155,11 +145,7 @@ function combineRoutes(
|
||||||
} else {
|
} else {
|
||||||
// Append to target
|
// Append to target
|
||||||
if (target.children === undefined) target.children = [];
|
if (target.children === undefined) target.children = [];
|
||||||
if (
|
if (sourceRoute.children && sourceRoute.children.length > 0 && sourceRoute.component === undefined)
|
||||||
sourceRoute.children &&
|
|
||||||
sourceRoute.children.length > 0 &&
|
|
||||||
sourceRoute.component === undefined
|
|
||||||
)
|
|
||||||
Object.assign(sourceRoute, {
|
Object.assign(sourceRoute, {
|
||||||
component: () => import('src/components/navigation/EmptyParent.vue'),
|
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 plugin Plugin to load
|
||||||
* @param router VueRouter instance
|
* @param router VueRouter instance
|
||||||
*/
|
*/
|
||||||
function loadPlugin(
|
function loadPlugin(loadedPlugins: FG_Plugin.Flaschengeist, plugin: FG_Plugin.Plugin, backend: Backend) {
|
||||||
loadedPlugins: FG_Plugin.Flaschengeist,
|
|
||||||
plugin: FG_Plugin.Plugin,
|
|
||||||
backend: Backend
|
|
||||||
) {
|
|
||||||
// Check if already loaded
|
// Check if already loaded
|
||||||
if (loadedPlugins.plugins.findIndex((p) => p.name === plugin.name) !== -1) return true;
|
if (loadedPlugins.plugins.findIndex((p) => p.name === plugin.name) !== -1) return true;
|
||||||
|
|
||||||
|
@ -238,8 +220,7 @@ function loadPlugin(
|
||||||
!plugin.requiredModules.every(
|
!plugin.requiredModules.every(
|
||||||
(required) =>
|
(required) =>
|
||||||
backend.plugins[required[0]] !== undefined &&
|
backend.plugins[required[0]] !== undefined &&
|
||||||
(required.length == 1 ||
|
(required.length == 1 || true) /* validate the version, semver440 from python is... tricky on node*/
|
||||||
true) /* validate the version, semver440 from python is... tricky on node*/
|
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
console.error(`Plugin ${plugin.name}: Backend modules not satisfied`);
|
console.error(`Plugin ${plugin.name}: Backend modules not satisfied`);
|
||||||
|
@ -333,7 +314,13 @@ export default boot(async ({ router, app }) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort widgets by priority
|
// Sort widgets by priority
|
||||||
loadedPlugins.widgets.sort((a, b) => b.priority - a.priority);
|
/** @todo Remove priority with first beta */
|
||||||
|
loadedPlugins.widgets.sort((a, b) => <number>(b.order || b.priority) - <number>(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
|
// Add loaded routes to router
|
||||||
loadedPlugins.routes.forEach((route) => router.addRoute(route));
|
loadedPlugins.routes.forEach((route) => router.addRoute(route));
|
||||||
|
|
|
@ -145,8 +145,7 @@ export default defineComponent({
|
||||||
Notify.create({
|
Notify.create({
|
||||||
group: false,
|
group: false,
|
||||||
type: 'ongoing',
|
type: 'ongoing',
|
||||||
message:
|
message: 'Sollte der Benutzername korrekt und vorhanden sein, erhälst du jetzt eine E-Mail.',
|
||||||
'Sollte der Benutzername korrekt und vorhanden sein, erhälst du jetzt eine E-Mail.',
|
|
||||||
timeout: 10000,
|
timeout: 10000,
|
||||||
progress: true,
|
progress: true,
|
||||||
actions: [{ icon: 'mdi-close', color: 'white' }],
|
actions: [{ icon: 'mdi-close', color: 'white' }],
|
||||||
|
|
|
@ -46,8 +46,7 @@ export default defineComponent({
|
||||||
const ival = setInterval(() => {
|
const ival = setInterval(() => {
|
||||||
reload.value -= 1;
|
reload.value -= 1;
|
||||||
if (reload.value <= 0) {
|
if (reload.value <= 0) {
|
||||||
if (router.currentRoute.value.params && 'refresh' in router.currentRoute.value.params)
|
if (router.currentRoute.value.params && 'refresh' in router.currentRoute.value.params) router.go(0);
|
||||||
router.go(0);
|
|
||||||
const path = router.currentRoute.value.query.redirect;
|
const path = router.currentRoute.value.query.redirect;
|
||||||
void router.replace(path ? { path: <string>path } : { name: 'login' });
|
void router.replace(path ? { path: <string>path } : { name: 'login' });
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue