provide validation tokens in forRoot of theme shared

pull/6966/head
Arman Ozak 5 years ago
parent af45dae2be
commit ca5e3a36b4

@ -1,7 +1,9 @@
import { Type } from '@angular/core';
import { Validation } from '@ngx-validate/core';
export interface RootParams {
httpErrorConfig: HttpErrorConfig;
validation?: Partial<Validation.Config>;
}
export type ErrorScreenErrorCodes = 401 | 403 | 404 | 500;

@ -2,7 +2,13 @@ import { CoreModule, noop } from '@abp/ng.core';
import { DatePipe } from '@angular/common';
import { APP_INITIALIZER, Injector, ModuleWithProviders, NgModule } from '@angular/core';
import { NgbDateParserFormatter, NgbPaginationModule } from '@ng-bootstrap/ng-bootstrap';
import { NgxValidateCoreModule } from '@ngx-validate/core';
import {
defaultMapErrorsFn,
NgxValidateCoreModule,
VALIDATION_BLUEPRINTS,
VALIDATION_MAP_ERRORS_FN,
VALIDATION_VALIDATE_ON_SUBMIT,
} from '@ngx-validate/core';
import { NgxDatatableModule } from '@swimlane/ngx-datatable';
import { BreadcrumbComponent } from './components/breadcrumb/breadcrumb.component';
import { ButtonComponent } from './components/button/button.component';
@ -18,6 +24,7 @@ import { TableEmptyMessageComponent } from './components/table-empty-message/tab
import { TableComponent } from './components/table/table.component';
import { ToastContainerComponent } from './components/toast-container/toast-container.component';
import { ToastComponent } from './components/toast/toast.component';
import { DEFAULT_VALIDATION_BLUEPRINTS } from './constants/validation';
import { LoadingDirective } from './directives/loading.directive';
import { NgxDatatableDefaultDirective } from './directives/ngx-datatable-default.directive';
import { NgxDatatableListDirective } from './directives/ngx-datatable-list.directive';
@ -69,7 +76,9 @@ export class BaseThemeSharedModule {}
exports: [BaseThemeSharedModule],
})
export class ThemeSharedModule {
static forRoot(options = {} as RootParams): ModuleWithProviders<ThemeSharedModule> {
static forRoot(
{ httpErrorConfig, validation = {} } = {} as RootParams,
): ModuleWithProviders<ThemeSharedModule> {
return {
ngModule: ThemeSharedModule,
providers: [
@ -92,13 +101,28 @@ export class ThemeSharedModule {
deps: [Injector],
useFactory: initLazyStyleHandler,
},
{ provide: HTTP_ERROR_CONFIG, useValue: options.httpErrorConfig },
{ provide: HTTP_ERROR_CONFIG, useValue: httpErrorConfig },
{
provide: 'HTTP_ERROR_CONFIG',
useFactory: httpErrorConfigFactory,
deps: [HTTP_ERROR_CONFIG],
},
{ provide: NgbDateParserFormatter, useClass: DateParserFormatter },
{
provide: VALIDATION_BLUEPRINTS,
useValue: {
...DEFAULT_VALIDATION_BLUEPRINTS,
...(validation.blueprints || {}),
},
},
{
provide: VALIDATION_MAP_ERRORS_FN,
useValue: validation.mapErrorsFn || defaultMapErrorsFn,
},
{
provide: VALIDATION_VALIDATE_ON_SUBMIT,
useValue: validation.validateOnSubmit,
},
],
};
}

Loading…
Cancel
Save