-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2119 from abpframework/feat/theme-shared/custom-e…
…rror Feat/theme shared/custom error
- Loading branch information
Showing
14 changed files
with
284 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 5 additions & 6 deletions
11
npm/ng-packs/packages/theme-shared/src/lib/components/error/error.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 51 additions & 9 deletions
60
npm/ng-packs/packages/theme-shared/src/lib/components/error/error.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,65 @@ | ||
import { Component, Renderer2, ElementRef } from '@angular/core'; | ||
import { Config } from '@abp/ng.core'; | ||
import { Config, takeUntilDestroy } from '@abp/ng.core'; | ||
import { | ||
AfterViewInit, | ||
Component, | ||
ComponentFactoryResolver, | ||
ElementRef, | ||
EmbeddedViewRef, | ||
OnDestroy, | ||
Type, | ||
ViewChild, | ||
} from '@angular/core'; | ||
import { fromEvent, Subject } from 'rxjs'; | ||
import { debounceTime, filter } from 'rxjs/operators'; | ||
|
||
@Component({ | ||
selector: 'abp-error', | ||
templateUrl: './error.component.html', | ||
styleUrls: ['error.component.scss'], | ||
}) | ||
export class ErrorComponent { | ||
title: string | Config.LocalizationWithDefault = 'Oops!'; | ||
export class ErrorComponent implements AfterViewInit, OnDestroy { | ||
cfRes: ComponentFactoryResolver; | ||
|
||
details: string | Config.LocalizationWithDefault = 'Sorry, an error has occured.'; | ||
status = 0; | ||
|
||
renderer: Renderer2; | ||
title: Config.LocalizationParam = 'Oops!'; | ||
|
||
elementRef: ElementRef; | ||
details: Config.LocalizationParam = 'Sorry, an error has occured.'; | ||
|
||
host: any; | ||
customComponent: Type<any> = null; | ||
|
||
destroy$: Subject<void>; | ||
|
||
@ViewChild('container', { static: false }) | ||
containerRef: ElementRef<HTMLDivElement>; | ||
|
||
get statusText(): string { | ||
return this.status ? `[${this.status}]` : ''; | ||
} | ||
|
||
ngAfterViewInit() { | ||
if (this.customComponent) { | ||
const customComponentRef = this.cfRes.resolveComponentFactory(this.customComponent).create(null); | ||
customComponentRef.instance.errorStatus = this.status; | ||
this.containerRef.nativeElement.appendChild((customComponentRef.hostView as EmbeddedViewRef<any>).rootNodes[0]); | ||
customComponentRef.changeDetectorRef.detectChanges(); | ||
} | ||
|
||
fromEvent(document, 'keyup') | ||
.pipe( | ||
takeUntilDestroy(this), | ||
debounceTime(150), | ||
filter((key: KeyboardEvent) => key && key.key === 'Escape'), | ||
) | ||
.subscribe(() => { | ||
this.destroy(); | ||
}); | ||
} | ||
|
||
ngOnDestroy() {} | ||
|
||
destroy() { | ||
this.renderer.removeChild(this.host, this.elementRef.nativeElement); | ||
this.destroy$.next(); | ||
this.destroy$.complete(); | ||
} | ||
} |
Oops, something went wrong.