|
|
@ -1,38 +1,40 @@ |
|
|
import { |
|
|
import { |
|
|
ApplicationRef, |
|
|
ApplicationRef, |
|
|
Component, |
|
|
Component, |
|
|
Injector, |
|
|
|
|
|
inject, |
|
|
inject, |
|
|
OnInit, |
|
|
OnInit, |
|
|
ComponentFactoryResolver, |
|
|
|
|
|
ElementRef, |
|
|
ElementRef, |
|
|
EmbeddedViewRef, |
|
|
EmbeddedViewRef, |
|
|
Type, |
|
|
Type, |
|
|
ViewChild, |
|
|
ViewChild, |
|
|
AfterViewInit, |
|
|
AfterViewInit, |
|
|
OnDestroy, |
|
|
OnDestroy, |
|
|
|
|
|
createComponent, |
|
|
|
|
|
EnvironmentInjector, |
|
|
|
|
|
DestroyRef, |
|
|
} from '@angular/core'; |
|
|
} from '@angular/core'; |
|
|
|
|
|
import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; |
|
|
import { DOCUMENT } from '@angular/common'; |
|
|
import { DOCUMENT } from '@angular/common'; |
|
|
|
|
|
import { Router } from '@angular/router'; |
|
|
import { fromEvent, Subject } from 'rxjs'; |
|
|
import { fromEvent, Subject } from 'rxjs'; |
|
|
import { debounceTime, filter } from 'rxjs/operators'; |
|
|
import { debounceTime, filter } from 'rxjs/operators'; |
|
|
import { LocalizationParam, SubscriptionService } from '@abp/ng.core'; |
|
|
import { LocalizationParam } from '@abp/ng.core'; |
|
|
import { ErrorScreenErrorCodes } from '../../models'; |
|
|
import { ErrorScreenErrorCodes } from '../../models'; |
|
|
|
|
|
|
|
|
@Component({ |
|
|
@Component({ |
|
|
selector: 'abp-http-error-wrapper', |
|
|
selector: 'abp-http-error-wrapper', |
|
|
templateUrl: './http-error-wrapper.component.html', |
|
|
templateUrl: './http-error-wrapper.component.html', |
|
|
styleUrls: ['http-error-wrapper.component.scss'], |
|
|
styleUrls: ['http-error-wrapper.component.scss'], |
|
|
providers: [SubscriptionService], |
|
|
|
|
|
}) |
|
|
}) |
|
|
export class HttpErrorWrapperComponent implements OnInit, AfterViewInit, OnDestroy { |
|
|
export class HttpErrorWrapperComponent implements OnInit, AfterViewInit, OnDestroy { |
|
|
|
|
|
protected readonly destroyRef = inject(DestroyRef); |
|
|
protected readonly document = inject(DOCUMENT); |
|
|
protected readonly document = inject(DOCUMENT); |
|
|
protected readonly window = this.document.defaultView; |
|
|
protected readonly window = this.document.defaultView; |
|
|
|
|
|
protected readonly router = inject(Router); |
|
|
|
|
|
|
|
|
appRef!: ApplicationRef; |
|
|
appRef!: ApplicationRef; |
|
|
|
|
|
|
|
|
cfRes!: ComponentFactoryResolver; |
|
|
environmentInjector!: EnvironmentInjector; |
|
|
|
|
|
|
|
|
injector!: Injector; |
|
|
|
|
|
|
|
|
|
|
|
status: ErrorScreenErrorCodes = 0; |
|
|
status: ErrorScreenErrorCodes = 0; |
|
|
|
|
|
|
|
|
@ -57,21 +59,23 @@ export class HttpErrorWrapperComponent implements OnInit, AfterViewInit, OnDestr |
|
|
return this.status ? `[${this.status}]` : ''; |
|
|
return this.status ? `[${this.status}]` : ''; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
constructor(private subscription: SubscriptionService) {} |
|
|
|
|
|
|
|
|
|
|
|
ngOnInit(): void { |
|
|
ngOnInit(): void { |
|
|
this.backgroundColor = |
|
|
const computedStyle = this.window.getComputedStyle(this.document.body); |
|
|
this.window.getComputedStyle(this.document.body)?.getPropertyValue('background-color') || '#fff'; |
|
|
const backgroundColor = computedStyle?.getPropertyValue('background-color'); |
|
|
|
|
|
this.backgroundColor = backgroundColor || '#fff'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
ngAfterViewInit(): void { |
|
|
ngAfterViewInit(): void { |
|
|
if (this.customComponent) { |
|
|
if (this.customComponent) { |
|
|
const customComponentRef = this.cfRes |
|
|
const customComponentRef = createComponent(this.customComponent, { |
|
|
.resolveComponentFactory(this.customComponent) |
|
|
environmentInjector: this.environmentInjector, |
|
|
.create(this.injector); |
|
|
}); |
|
|
|
|
|
|
|
|
customComponentRef.instance.errorStatus = this.status; |
|
|
customComponentRef.instance.errorStatus = this.status; |
|
|
customComponentRef.instance.destroy$ = this.destroy$; |
|
|
customComponentRef.instance.destroy$ = this.destroy$; |
|
|
|
|
|
|
|
|
this.appRef.attachView(customComponentRef.hostView); |
|
|
this.appRef.attachView(customComponentRef.hostView); |
|
|
|
|
|
|
|
|
if (this.containerRef) { |
|
|
if (this.containerRef) { |
|
|
this.containerRef.nativeElement.appendChild( |
|
|
this.containerRef.nativeElement.appendChild( |
|
|
(customComponentRef.hostView as EmbeddedViewRef<any>).rootNodes[0], |
|
|
(customComponentRef.hostView as EmbeddedViewRef<any>).rootNodes[0], |
|
|
@ -80,14 +84,17 @@ export class HttpErrorWrapperComponent implements OnInit, AfterViewInit, OnDestr |
|
|
customComponentRef.changeDetectorRef.detectChanges(); |
|
|
customComponentRef.changeDetectorRef.detectChanges(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const keyup$ = fromEvent<KeyboardEvent>(this.document, 'keyup').pipe( |
|
|
fromEvent<KeyboardEvent>(this.document, 'keyup') |
|
|
debounceTime(150), |
|
|
.pipe( |
|
|
filter((key: KeyboardEvent) => key && key.key === 'Escape'), |
|
|
debounceTime(150), |
|
|
); |
|
|
filter((key: KeyboardEvent) => key && key.key === 'Escape'), |
|
|
this.subscription.addOne(keyup$, () => this.destroy()); |
|
|
takeUntilDestroyed(this.destroyRef), |
|
|
|
|
|
) |
|
|
|
|
|
.subscribe(() => this.destroy()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
ngOnDestroy(): void { |
|
|
goHome(): void { |
|
|
|
|
|
this.router.navigateByUrl('/', { onSameUrlNavigation: 'reload' }); |
|
|
this.destroy(); |
|
|
this.destroy(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -95,4 +102,8 @@ export class HttpErrorWrapperComponent implements OnInit, AfterViewInit, OnDestr |
|
|
this.destroy$.next(); |
|
|
this.destroy$.next(); |
|
|
this.destroy$.complete(); |
|
|
this.destroy$.complete(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ngOnDestroy(): void { |
|
|
|
|
|
this.destroy(); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|