Newer
Older
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgModule, APP_INITIALIZER } from '@angular/core';
FORESTIER Fabien
committed
import { HttpClientModule, HttpClientXsrfModule } from '@angular/common/http';
import { AppComponent } from './app.component';
FORESTIER Fabien
committed
import { AppRoutingModule } from './app-routing.module';
import { CoreModule } from './core/core.module';
ncastejon
committed
import { EditorialisationModule } from './editorialisation/editorialisation.module';
import { UserModule } from './user/user.module';
import { UserService } from './user/services';
import { AppConfigService, NotificationService, TarteAuCitronService } from './core/services';
import { timeout } from 'rxjs/operators';
import { notificationMessages } from '../i18n/traductions';
// Function used by APP_INITIALIZER before the app start: init user info / statut (expect a promise)
export function initUserService(authService: UserService, notificationService: NotificationService) {
return new Promise<void>((resolve, reject) => {
authService.initializeService().pipe(timeout(3000)).subscribe(
FORESTIER Fabien
committed
() => {
resolve();
},
(err) => {
if (err.status !== 401) {
notificationService.notify({
type: 'error',
message: notificationMessages.userInfo.userInit,
});
}
FORESTIER Fabien
committed
resolve();
});
export function initTarteaucitronService(tarteaucitronService: TarteAuCitronService) {
return (): Promise<void> => {
FORESTIER Fabien
committed
export function initAppConfig(appConfigService: AppConfigService) {
return new Promise<void>((resolve, reject) => {
FORESTIER Fabien
committed
appConfigService.load();
resolve();
});
};
}
],
imports: [
BrowserModule,
BrowserAnimationsModule,
FORESTIER Fabien
committed
CoreModule,
ncastejon
committed
EditorialisationModule,
UserModule,
FORESTIER Fabien
committed
// The order is important as the InitUserService require the configuration of the app
FORESTIER Fabien
committed
useFactory: initAppConfig,
deps: [AppConfigService],
{
provide: APP_INITIALIZER,
useFactory: initTarteaucitronService,
deps: [TarteAuCitronService],
multi: true,
},
FORESTIER Fabien
committed
{
provide: APP_INITIALIZER,
FORESTIER Fabien
committed
useFactory: initUserService,
deps: [UserService, NotificationService],
FORESTIER Fabien
committed
multi: true,
},
})
export class AppModule { }