mirror of https://github.com/abpframework/abp.git
committed by
GitHub
14 changed files with 284 additions and 118 deletions
@ -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(); |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,18 @@ |
|||
import { Type } from '@angular/core'; |
|||
|
|||
export interface RootParams { |
|||
httpErrorConfig: HttpErrorConfig; |
|||
} |
|||
|
|||
export type ErrorScreenErrorCodes = 401 | 403 | 404 | 500; |
|||
|
|||
export interface HttpErrorConfig { |
|||
errorScreen?: { |
|||
component: Type<any>; |
|||
forWhichErrors?: |
|||
| [ErrorScreenErrorCodes] |
|||
| [ErrorScreenErrorCodes, ErrorScreenErrorCodes] |
|||
| [ErrorScreenErrorCodes, ErrorScreenErrorCodes, ErrorScreenErrorCodes] |
|||
| [ErrorScreenErrorCodes, ErrorScreenErrorCodes, ErrorScreenErrorCodes, ErrorScreenErrorCodes]; |
|||
}; |
|||
} |
|||
@ -1,18 +1,19 @@ |
|||
import { Toaster } from './toaster'; |
|||
import { Config } from '@abp/ng.core'; |
|||
|
|||
export namespace Confirmation { |
|||
export interface Options extends Toaster.Options { |
|||
hideCancelBtn?: boolean; |
|||
hideYesBtn?: boolean; |
|||
cancelText?: string; |
|||
yesText?: string; |
|||
cancelText?: Config.LocalizationParam; |
|||
yesText?: Config.LocalizationParam; |
|||
/** |
|||
* @deprecated to be deleted in v2 |
|||
*/ |
|||
cancelCopy?: string; |
|||
cancelCopy?: Config.LocalizationParam; |
|||
/** |
|||
* @deprecated to be deleted in v2 |
|||
*/ |
|||
yesCopy?: string; |
|||
yesCopy?: Config.LocalizationParam; |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,15 @@ |
|||
import { InjectionToken } from '@angular/core'; |
|||
import { HttpErrorConfig } from '../models/common'; |
|||
|
|||
export function httpErrorConfigFactory(config = {} as HttpErrorConfig) { |
|||
if (config.errorScreen && config.errorScreen.component && !config.errorScreen.forWhichErrors) { |
|||
config.errorScreen.forWhichErrors = [401, 403, 404, 500]; |
|||
} |
|||
|
|||
return { |
|||
errorScreen: {}, |
|||
...config, |
|||
} as HttpErrorConfig; |
|||
} |
|||
|
|||
export const HTTP_ERROR_CONFIG = new InjectionToken('HTTP_ERROR_CONFIG'); |
|||
Loading…
Reference in new issue