|
|
|
@ -1,4 +1,4 @@ |
|
|
|
import { Component, Input, OnDestroy, Type } from '@angular/core'; |
|
|
|
import { Component, Input, OnDestroy, Type, Injector } from '@angular/core'; |
|
|
|
import { ActivatedRoute, NavigationEnd, Router, UrlSegment } from '@angular/router'; |
|
|
|
import { Select, Store } from '@ngxs/store'; |
|
|
|
import { Observable } from 'rxjs'; |
|
|
|
@ -14,8 +14,10 @@ import { takeUntilDestroy } from '../utils/rxjs-utils'; |
|
|
|
template: ` |
|
|
|
<ng-container *ngTemplateOutlet="layout ? componentOutlet : routerOutlet"></ng-container> |
|
|
|
<ng-template #routerOutlet><router-outlet></router-outlet></ng-template> |
|
|
|
<ng-template #componentOutlet><ng-container *ngComponentOutlet="layout"></ng-container></ng-template> |
|
|
|
` |
|
|
|
<ng-template #componentOutlet |
|
|
|
><ng-container *ngComponentOutlet="layout"></ng-container |
|
|
|
></ng-template> |
|
|
|
`,
|
|
|
|
}) |
|
|
|
export class DynamicLayoutComponent implements OnDestroy { |
|
|
|
@Select(ConfigState.getOne('requirements')) requirements$: Observable<Config.Requirements>; |
|
|
|
@ -25,18 +27,23 @@ export class DynamicLayoutComponent implements OnDestroy { |
|
|
|
constructor(private router: Router, private route: ActivatedRoute, private store: Store) { |
|
|
|
const { |
|
|
|
requirements: { layouts }, |
|
|
|
routes |
|
|
|
routes, |
|
|
|
} = this.store.selectSnapshot(ConfigState.getAll); |
|
|
|
|
|
|
|
if ((this.route.snapshot.data || {}).layout) { |
|
|
|
this.layout = layouts |
|
|
|
.filter(l => !!l) |
|
|
|
.find((l: any) => snq(() => l.type.toLowerCase().indexOf(this.route.snapshot.data.layout), -1) > -1); |
|
|
|
.find( |
|
|
|
(l: any) => |
|
|
|
snq(() => l.type.toLowerCase().indexOf(this.route.snapshot.data.layout), -1) > -1, |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
this.router.events.pipe(takeUntilDestroy(this)).subscribe(event => { |
|
|
|
router.events.pipe(takeUntilDestroy(this)).subscribe(event => { |
|
|
|
if (event instanceof NavigationEnd) { |
|
|
|
const { segments } = this.router.parseUrl(event.url).root.children.primary; |
|
|
|
const segments = snq(() => router.parseUrl(event.url).root.children.primary.segments, [ |
|
|
|
{ path: router.url.replace('/', '') }, |
|
|
|
] as any); |
|
|
|
|
|
|
|
const layout = (this.route.snapshot.data || {}).layout || findLayout(segments, routes); |
|
|
|
|
|
|
|
|