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/+plugin-pages/index.ts | 3 +++ .../+plugin-pages/plugin-pages-routing.module.ts | 19 +++++++++++++ .../app/+plugin-pages/plugin-pages.component.html | 1 + .../app/+plugin-pages/plugin-pages.component.ts | 31 ++++++++++++++++++++++ .../src/app/+plugin-pages/plugin-pages.module.ts | 21 +++++++++++++++ 5 files changed, 75 insertions(+) create mode 100644 client/src/app/+plugin-pages/index.ts create mode 100644 client/src/app/+plugin-pages/plugin-pages-routing.module.ts create mode 100644 client/src/app/+plugin-pages/plugin-pages.component.html create mode 100644 client/src/app/+plugin-pages/plugin-pages.component.ts create mode 100644 client/src/app/+plugin-pages/plugin-pages.module.ts (limited to 'client/src/app/+plugin-pages') diff --git a/client/src/app/+plugin-pages/index.ts b/client/src/app/+plugin-pages/index.ts new file mode 100644 index 000000000..b988f13f6 --- /dev/null +++ b/client/src/app/+plugin-pages/index.ts @@ -0,0 +1,3 @@ +export * from './plugin-pages-routing.module' +export * from './plugin-pages.component' +export * from './plugin-pages.module' diff --git a/client/src/app/+plugin-pages/plugin-pages-routing.module.ts b/client/src/app/+plugin-pages/plugin-pages-routing.module.ts new file mode 100644 index 000000000..b47a787e0 --- /dev/null +++ b/client/src/app/+plugin-pages/plugin-pages-routing.module.ts @@ -0,0 +1,19 @@ +import { NgModule } from '@angular/core' +import { RouterModule, Routes } from '@angular/router' +import { PluginPagesComponent } from './plugin-pages.component' + +const pluginPagesRoutes: Routes = [ + { + path: '**', + component: PluginPagesComponent, + data: { + reloadOnSameNavigation: true + } + } +] + +@NgModule({ + imports: [ RouterModule.forChild(pluginPagesRoutes) ], + exports: [ RouterModule ] +}) +export class PluginPagesRoutingModule {} diff --git a/client/src/app/+plugin-pages/plugin-pages.component.html b/client/src/app/+plugin-pages/plugin-pages.component.html new file mode 100644 index 000000000..cf62d1bd7 --- /dev/null +++ b/client/src/app/+plugin-pages/plugin-pages.component.html @@ -0,0 +1 @@ +
diff --git a/client/src/app/+plugin-pages/plugin-pages.component.ts b/client/src/app/+plugin-pages/plugin-pages.component.ts new file mode 100644 index 000000000..5f294ee13 --- /dev/null +++ b/client/src/app/+plugin-pages/plugin-pages.component.ts @@ -0,0 +1,31 @@ +import { AfterViewInit, Component, ElementRef, ViewChild } from '@angular/core' +import { ActivatedRoute, Router } from '@angular/router' +import { PluginService } from '@app/core' + +@Component({ + templateUrl: './plugin-pages.component.html' +}) +export class PluginPagesComponent implements AfterViewInit { + @ViewChild('root') root: ElementRef + + constructor ( + private route: ActivatedRoute, + private router: Router, + private pluginService: PluginService + ) { + + } + + ngAfterViewInit () { + const path = '/' + this.route.snapshot.url.map(u => u.path).join('/') + + const registered = this.pluginService.getRegisteredClientRoute(path) + if (!registered) { + console.log('Could not find registered route %s.', path, this.pluginService.getAllRegisteredClientRoutes()) + + return this.router.navigate([ '/404' ], { skipLocationChange: true }) + } + + registered.onMount({ rootEl: this.root.nativeElement }) + } +} diff --git a/client/src/app/+plugin-pages/plugin-pages.module.ts b/client/src/app/+plugin-pages/plugin-pages.module.ts new file mode 100644 index 000000000..86f86c752 --- /dev/null +++ b/client/src/app/+plugin-pages/plugin-pages.module.ts @@ -0,0 +1,21 @@ +import { NgModule } from '@angular/core' +import { PluginPagesRoutingModule } from './plugin-pages-routing.module' +import { PluginPagesComponent } from './plugin-pages.component' + +@NgModule({ + imports: [ + PluginPagesRoutingModule + ], + + declarations: [ + PluginPagesComponent + ], + + exports: [ + PluginPagesComponent + ], + + providers: [ + ] +}) +export class PluginPagesModule { } -- cgit v1.2.3