From d63e6d4604dfbe4938c7d66832c9202364c5bb64 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 10 Dec 2021 15:01:12 +0100 Subject: Add ability for plugins to register client routes --- client/src/app/core/plugins/plugin.service.ts | 31 +++++++++++++++++++--- .../src/app/core/routing/custom-reuse-strategy.ts | 2 +- 2 files changed, 28 insertions(+), 5 deletions(-) (limited to 'client/src/app/core') diff --git a/client/src/app/core/plugins/plugin.service.ts b/client/src/app/core/plugins/plugin.service.ts index 89391c2c5..fdbbd2d56 100644 --- a/client/src/app/core/plugins/plugin.service.ts +++ b/client/src/app/core/plugins/plugin.service.ts @@ -20,7 +20,8 @@ import { PluginType, PublicServerSetting, RegisterClientFormFieldOptions, - RegisterClientSettingsScript, + RegisterClientSettingsScriptOptions, + RegisterClientRouteOptions, RegisterClientVideoFieldOptions, ServerConfigPlugin } from '@shared/models' @@ -48,7 +49,8 @@ export class PluginService implements ClientHook { private formFields: FormFields = { video: [] } - private settingsScripts: { [ npmName: string ]: RegisterClientSettingsScript } = {} + private settingsScripts: { [ npmName: string ]: RegisterClientSettingsScriptOptions } = {} + private clientRoutes: { [ route: string ]: RegisterClientRouteOptions } = {} private pluginsManager: PluginsManager @@ -67,7 +69,8 @@ export class PluginService implements ClientHook { this.pluginsManager = new PluginsManager({ peertubeHelpersFactory: this.buildPeerTubeHelpers.bind(this), onFormFields: this.onFormFields.bind(this), - onSettingsScripts: this.onSettingsScripts.bind(this) + onSettingsScripts: this.onSettingsScripts.bind(this), + onClientRoute: this.onClientRoute.bind(this) }) } @@ -123,6 +126,14 @@ export class PluginService implements ClientHook { return this.settingsScripts[npmName] } + getRegisteredClientRoute (route: string) { + return this.clientRoutes[route] + } + + getAllRegisteredClientRoutes () { + return Object.keys(this.clientRoutes) + } + translateBy (npmName: string, toTranslate: string) { const helpers = this.helpers[npmName] if (!helpers) { @@ -140,12 +151,20 @@ export class PluginService implements ClientHook { }) } - private onSettingsScripts (pluginInfo: PluginInfo, options: RegisterClientSettingsScript) { + private onSettingsScripts (pluginInfo: PluginInfo, options: RegisterClientSettingsScriptOptions) { const npmName = this.nameToNpmName(pluginInfo.plugin.name, pluginInfo.pluginType) this.settingsScripts[npmName] = options } + private onClientRoute (options: RegisterClientRouteOptions) { + const route = options.route.startsWith('/') + ? options.route + : `/${options.route}` + + this.clientRoutes[route] = options + } + private buildPeerTubeHelpers (pluginInfo: PluginInfo): RegisterClientHelpers { const { plugin } = pluginInfo const npmName = this.nameToNpmName(pluginInfo.plugin.name, pluginInfo.pluginType) @@ -161,6 +180,10 @@ export class PluginService implements ClientHook { return environment.apiUrl + `${pathPrefix}/${plugin.name}/${plugin.version}/router` }, + getBasePluginClientPath: () => { + return '/p' + }, + getSettings: () => { const path = PluginService.BASE_PLUGIN_API_URL + '/' + npmName + '/public-settings' diff --git a/client/src/app/core/routing/custom-reuse-strategy.ts b/client/src/app/core/routing/custom-reuse-strategy.ts index 1498e221f..5d3ad2e67 100644 --- a/client/src/app/core/routing/custom-reuse-strategy.ts +++ b/client/src/app/core/routing/custom-reuse-strategy.ts @@ -58,7 +58,7 @@ export class CustomReuseStrategy implements RouteReuseStrategy { // Reuse the route if we're going to and from the same route shouldReuseRoute (future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean { - return future.routeConfig === curr.routeConfig + return future.routeConfig === curr.routeConfig && future.routeConfig?.data?.reloadOnSameNavigation !== true } private gb () { -- cgit v1.2.3