2021-05-21 15:04:29 +00:00
|
|
|
import type { RouteLocationRaw, RouteRecordRaw, RouteRecordName } from 'vue-router';
|
|
|
|
import type { Component } from '@vue/runtime-core';
|
2021-05-20 21:14:32 +00:00
|
|
|
|
2021-05-25 14:48:14 +00:00
|
|
|
/* This is some sort of PEP440 subset */
|
2021-05-21 15:04:29 +00:00
|
|
|
type Join<T extends unknown[], D extends string> =
|
|
|
|
T extends [] ? '' :
|
|
|
|
T extends [string | number | boolean | bigint] ? `${T[0]}` :
|
|
|
|
T extends [string | number | boolean | bigint, ...infer U] ? `${T[0]}${D}${Join<U, D>}` :
|
|
|
|
string;
|
2021-05-25 14:48:14 +00:00
|
|
|
type BaseVersion = Join<[number, number], '.'> | Join<[number, number, number], '.'>
|
|
|
|
type PreRelease = Join<[["a"|"b"|"rc"], number], ".">
|
|
|
|
type PRVersion = BaseVersion | `${BaseVersion}${PreRelease}`
|
|
|
|
/** A PEP440 subset used to describe backend module versions */
|
|
|
|
export type PEP440Version = PRVersion | `${PRVersion}.dev${number}`
|
2021-05-21 15:04:29 +00:00
|
|
|
|
|
|
|
export namespace FG_Plugin {
|
2021-05-20 21:14:32 +00:00
|
|
|
/**
|
|
|
|
* Interface defining a Flaschengeist plugin
|
|
|
|
*/
|
2021-05-21 15:04:29 +00:00
|
|
|
export interface Plugin {
|
|
|
|
/** Unique identifier for this plugin, we recommend using a FQN like com.example.my_plugin */
|
|
|
|
id: string,
|
|
|
|
/** Arbitrary name of the plugin used inside admin view etc */
|
2021-05-20 21:14:32 +00:00
|
|
|
name: string;
|
2021-05-21 15:04:29 +00:00
|
|
|
/** Version of this plugin, used for dependencies. MUST be semver parsable */
|
2021-05-20 21:14:32 +00:00
|
|
|
version: string;
|
2021-05-21 15:04:29 +00:00
|
|
|
/** Widgets provided by this plugin */
|
2021-05-20 21:14:32 +00:00
|
|
|
widgets: Widget[];
|
|
|
|
/** Backend modules needed for this plugin to work correctly */
|
2021-05-25 14:48:14 +00:00
|
|
|
requiredModules: [string, PEP440Version?][];
|
2021-05-20 21:14:32 +00:00
|
|
|
/** Menu entries for authenticated users */
|
|
|
|
innerRoutes?: MenuRoute[];
|
|
|
|
/** Public menu entries (without authentification) */
|
|
|
|
outerRoutes?: MenuRoute[];
|
|
|
|
/** Routes without menu links, for internal usage */
|
|
|
|
internalRoutes?: NamedRouteRecordRaw[];
|
|
|
|
/** Handle notifications, defaults to boot/plugins.ts:translateNotification() */
|
|
|
|
notification?(msg: FG.Notification): FG_Plugin.Notification;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Defines the loaded state of the Flaschengeist
|
|
|
|
*/
|
2021-05-21 15:04:29 +00:00
|
|
|
export interface Flaschengeist {
|
2021-05-20 21:14:32 +00:00
|
|
|
/** All loaded plugins */
|
|
|
|
plugins: LoadedPlugin[];
|
|
|
|
/** All routes, combined from all plugins */
|
|
|
|
routes: RouteRecordRaw[];
|
|
|
|
/** All menu entries */
|
|
|
|
menuLinks: MenuLink[];
|
|
|
|
/** All inner shortcuts */
|
|
|
|
shortcuts: Shortcut[];
|
|
|
|
/** All outer shortcuts */
|
|
|
|
outerShortcuts: Shortcut[];
|
|
|
|
/** All widgets */
|
|
|
|
widgets: Widget[];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Interface for a frontend notification
|
|
|
|
*/
|
2021-05-21 15:04:29 +00:00
|
|
|
export interface Notification extends FG.Notification {
|
2021-05-20 21:14:32 +00:00
|
|
|
/** If set a button for accepting will be shown, this function will get called before deleting the notification */
|
|
|
|
accept?(): Promise<void>;
|
|
|
|
/** If set this function is called before the notification gets deleted */
|
|
|
|
reject?(): Promise<void>;
|
|
|
|
/** If set the notification text is interpreted as a link to this location */
|
|
|
|
link?: RouteLocationRaw;
|
|
|
|
/** If set this icon is used */
|
|
|
|
icon?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loaded Flaschengeist plugin
|
|
|
|
*/
|
|
|
|
interface LoadedPlugin {
|
|
|
|
name: string;
|
|
|
|
version: string;
|
|
|
|
notification(msg: FG.Notification): FG_Plugin.Notification;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Defines a shortcut link
|
|
|
|
*/
|
2021-05-21 15:04:29 +00:00
|
|
|
export interface Shortcut {
|
2021-05-20 21:14:32 +00:00
|
|
|
link: RouteRecordName;
|
|
|
|
icon: string;
|
|
|
|
permissions?: string[];
|
|
|
|
}
|
|
|
|
|
2021-05-21 15:04:29 +00:00
|
|
|
type NamedRouteRecordRaw = RouteRecordRaw & {
|
|
|
|
name: RouteRecordName;
|
|
|
|
};
|
|
|
|
|
2021-05-20 21:14:32 +00:00
|
|
|
/**
|
|
|
|
* Defines a main menu entry along with the route
|
|
|
|
* Used when defining a plugin
|
|
|
|
*/
|
2021-05-21 15:04:29 +00:00
|
|
|
export interface MenuRoute extends MenuEntry {
|
2021-05-20 21:14:32 +00:00
|
|
|
route: NamedRouteRecordRaw;
|
|
|
|
shortcut?: boolean;
|
|
|
|
children?: this[];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Defines a menu entry in the main menu
|
|
|
|
*/
|
2021-05-21 15:04:29 +00:00
|
|
|
export interface MenuLink extends MenuEntry {
|
2021-05-20 21:14:32 +00:00
|
|
|
/** Name of the target route */
|
|
|
|
link: RouteRecordName;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base interface for internal use
|
|
|
|
*/
|
|
|
|
interface MenuEntry {
|
|
|
|
title: string | (() => string);
|
|
|
|
icon: string;
|
|
|
|
permissions?: string[];
|
|
|
|
children?: this[];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Widget object for the dashboard
|
|
|
|
*/
|
2021-05-21 15:04:29 +00:00
|
|
|
export interface Widget {
|
2021-05-20 21:14:32 +00:00
|
|
|
name: string;
|
|
|
|
priority: number;
|
|
|
|
permissions: FG.Permission[];
|
|
|
|
widget: Component;
|
|
|
|
}
|
|
|
|
}
|