|
|
@ -1,32 +1,29 @@ |
|
|
import { |
|
|
import { Component, inject, input, isDevMode, Type } from '@angular/core'; |
|
|
Component, |
|
|
import { NgComponentOutlet } from '@angular/common'; |
|
|
inject, |
|
|
|
|
|
input, |
|
|
|
|
|
isDevMode, |
|
|
|
|
|
Type, |
|
|
|
|
|
} from '@angular/core'; |
|
|
|
|
|
import { ActivatedRoute, Router } from '@angular/router'; |
|
|
import { ActivatedRoute, Router } from '@angular/router'; |
|
|
|
|
|
import { startWith } from 'rxjs/operators'; |
|
|
|
|
|
|
|
|
import { eLayoutType } from '../enums/common'; |
|
|
import { eLayoutType } from '../enums/common'; |
|
|
import { ABP } from '../models'; |
|
|
import { ABP } from '../models'; |
|
|
import { ReplaceableComponents } from '../models/replaceable-components'; |
|
|
import { ReplaceableComponents } from '../models/replaceable-components'; |
|
|
|
|
|
|
|
|
import { LocalizationService } from '../services/localization.service'; |
|
|
import { LocalizationService } from '../services/localization.service'; |
|
|
import { ReplaceableComponentsService } from '../services/replaceable-components.service'; |
|
|
import { ReplaceableComponentsService } from '../services/replaceable-components.service'; |
|
|
import { RouterEvents } from '../services/router-events.service'; |
|
|
import { RouterEvents } from '../services/router-events.service'; |
|
|
import { RoutesService } from '../services/routes.service'; |
|
|
import { RoutesService } from '../services/routes.service'; |
|
|
import { SubscriptionService } from '../services/subscription.service'; |
|
|
import { SubscriptionService } from '../services/subscription.service'; |
|
|
|
|
|
|
|
|
import { RouteBasedCultureUrlService } from '../services/route-based-culture-url.service'; |
|
|
import { RouteBasedCultureUrlService } from '../services/route-based-culture-url.service'; |
|
|
import { findRoute } from '../utils/route-utils'; |
|
|
import { findRoute } from '../utils/route-utils'; |
|
|
import { TreeNode } from '../utils/tree-utils'; |
|
|
import { TreeNode } from '../utils/tree-utils'; |
|
|
|
|
|
|
|
|
import { DYNAMIC_LAYOUTS_TOKEN } from '../tokens/dynamic-layout.token'; |
|
|
import { DYNAMIC_LAYOUTS_TOKEN } from '../tokens/dynamic-layout.token'; |
|
|
import { EnvironmentService } from '../services'; |
|
|
|
|
|
import { NgComponentOutlet } from '@angular/common'; |
|
|
|
|
|
import { filter, take } from 'rxjs'; |
|
|
|
|
|
|
|
|
|
|
|
@Component({ |
|
|
@Component({ |
|
|
selector: 'abp-dynamic-layout', |
|
|
selector: 'abp-dynamic-layout', |
|
|
template: ` |
|
|
template: ` |
|
|
@if (isLayoutVisible) { |
|
|
@if (isLayoutVisible) { |
|
|
<ng-container [ngComponentOutlet]="layout"></ng-container> |
|
|
<ng-container [ngComponentOutlet]="layout" /> |
|
|
} |
|
|
} |
|
|
`,
|
|
|
`,
|
|
|
providers: [SubscriptionService], |
|
|
providers: [SubscriptionService], |
|
|
@ -46,24 +43,25 @@ export class DynamicLayoutComponent { |
|
|
protected readonly replaceableComponents = inject(ReplaceableComponentsService); |
|
|
protected readonly replaceableComponents = inject(ReplaceableComponentsService); |
|
|
protected readonly subscription = inject(SubscriptionService); |
|
|
protected readonly subscription = inject(SubscriptionService); |
|
|
protected readonly routerEvents = inject(RouterEvents); |
|
|
protected readonly routerEvents = inject(RouterEvents); |
|
|
protected readonly environment = inject(EnvironmentService); |
|
|
|
|
|
protected readonly routeCultureUrl = inject(RouteBasedCultureUrlService); |
|
|
protected readonly routeCultureUrl = inject(RouteBasedCultureUrlService); |
|
|
|
|
|
|
|
|
constructor() { |
|
|
constructor() { |
|
|
const dynamicLayoutComponent = inject(DynamicLayoutComponent, { optional: true, skipSelf: true }); |
|
|
const dynamicLayoutComponent = inject(DynamicLayoutComponent, { |
|
|
|
|
|
optional: true, |
|
|
|
|
|
skipSelf: true, |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
if (dynamicLayoutComponent) { |
|
|
if (dynamicLayoutComponent) { |
|
|
if (isDevMode()) console.warn('DynamicLayoutComponent must be used only in AppComponent.'); |
|
|
if (isDevMode()) console.warn('DynamicLayoutComponent must be used only in AppComponent.'); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
this.checkLayoutOnNavigationEnd(); |
|
|
this.listenToLayoutChanges(); |
|
|
this.listenToLanguageChange(); |
|
|
this.listenToLanguageChange(); |
|
|
this.listenToEnvironmentChange(); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private checkLayoutOnNavigationEnd() { |
|
|
private listenToLayoutChanges() { |
|
|
const navigationEnd$ = this.routerEvents.getNavigationEvents('End'); |
|
|
const navigationEnd$ = this.routerEvents.getNavigationEvents('End'); |
|
|
this.subscription.addOne(navigationEnd$, () => this.getLayout()); |
|
|
this.subscription.addOne(navigationEnd$.pipe(startWith(null)), () => this.getLayout()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private getLayout() { |
|
|
private getLayout() { |
|
|
@ -120,19 +118,4 @@ export class DynamicLayoutComponent { |
|
|
private getComponent(key: string): ReplaceableComponents.ReplaceableComponent | undefined { |
|
|
private getComponent(key: string): ReplaceableComponents.ReplaceableComponent | undefined { |
|
|
return this.replaceableComponents.get(key); |
|
|
return this.replaceableComponents.get(key); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private listenToEnvironmentChange() { |
|
|
|
|
|
this.environment |
|
|
|
|
|
.createOnUpdateStream(x => x.oAuthConfig) |
|
|
|
|
|
.pipe( |
|
|
|
|
|
take(1), |
|
|
|
|
|
filter(config => config.responseType === 'code'), |
|
|
|
|
|
) |
|
|
|
|
|
.subscribe(() => { |
|
|
|
|
|
if (this.layout) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
this.getLayout(); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|