Browse Source

feat(theme-shared): add http error config token

pull/2119/head
mehmet-erim 7 years ago
parent
commit
5809d1ba01
  1. 18
      npm/ng-packs/packages/theme-shared/src/lib/models/common.ts
  2. 9
      npm/ng-packs/packages/theme-shared/src/lib/models/confirmation.ts
  3. 1
      npm/ng-packs/packages/theme-shared/src/lib/models/index.ts
  4. 10
      npm/ng-packs/packages/theme-shared/src/lib/theme-shared.module.ts
  5. 15
      npm/ng-packs/packages/theme-shared/src/lib/tokens/error-pages.token.ts

18
npm/ng-packs/packages/theme-shared/src/lib/models/common.ts

@ -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];
};
}

9
npm/ng-packs/packages/theme-shared/src/lib/models/confirmation.ts

@ -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;
}
}

1
npm/ng-packs/packages/theme-shared/src/lib/models/index.ts

@ -1,3 +1,4 @@
export * from './common';
export * from './confirmation';
export * from './setting-management';
export * from './statistics';

10
npm/ng-packs/packages/theme-shared/src/lib/theme-shared.module.ts

@ -18,6 +18,8 @@ import styles from './contants/styles';
import { TableSortDirective } from './directives/table-sort.directive';
import { ErrorHandler } from './handlers/error.handler';
import { chartJsLoaded$ } from './utils/widget-utils';
import { RootParams } from './models/common';
import { HTTP_ERROR_CONFIG, httpErrorConfigFactory } from './tokens/error-pages.token';
export function appendScript(injector: Injector) {
const fn = () => {
@ -69,7 +71,7 @@ export function appendScript(injector: Injector) {
entryComponents: [ErrorComponent],
})
export class ThemeSharedModule {
static forRoot(): ModuleWithProviders {
static forRoot(options = {} as RootParams): ModuleWithProviders {
return {
ngModule: ThemeSharedModule,
providers: [
@ -80,6 +82,12 @@ export class ThemeSharedModule {
useFactory: appendScript,
},
{ provide: MessageService, useClass: MessageService },
{ provide: HTTP_ERROR_CONFIG, useValue: options.httpErrorConfig },
{
provide: 'HTTP_ERROR_CONFIG',
useFactory: httpErrorConfigFactory,
deps: [HTTP_ERROR_CONFIG],
},
],
};
}

15
npm/ng-packs/packages/theme-shared/src/lib/tokens/error-pages.token.ts

@ -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…
Cancel
Save