192 lines
7.2 KiB
TypeScript
192 lines
7.2 KiB
TypeScript
import { OverlayModule } from '@angular/cdk/overlay';
|
|
import { HttpClientModule } from '@angular/common/http';
|
|
import { APP_INITIALIZER, LOCALE_ID, NgModule } from '@angular/core';
|
|
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
|
import { MAT_MOMENT_DATE_FORMATS, MatMomentDateModule } from '@angular/material-moment-adapter';
|
|
import { DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE } from '@angular/material/core';
|
|
import { MAT_FORM_FIELD_DEFAULT_OPTIONS, MatFormFieldDefaultOptions } from '@angular/material/form-field';
|
|
import { BrowserModule, Title } from '@angular/platform-browser';
|
|
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
|
import { AppRoutingModule } from '@app/app-routing.module';
|
|
import { AppComponent } from '@app/app.component';
|
|
import { CoreServiceModule } from '@app/core/core-service.module';
|
|
import { NotificationModule } from '@app/library/notification/notification.module';
|
|
import { LoginModule } from '@app/ui/auth/login/login.module';
|
|
// import { BreadcrumbModule } from '@app/ui/misc/breadcrumb/breadcrumb.module';
|
|
import { ReloadHelperComponent } from '@app/ui/misc/reload-helper/reload-helper.component';
|
|
import { NavbarModule } from '@app/ui/navbar/navbar.module';
|
|
import { SidebarModule } from '@app/ui/sidebar/sidebar.module';
|
|
import { MomentUtcDateAdapter } from '@common/date/moment-utc-date-adapter';
|
|
import { BaseHttpParams } from '@common/http/base-http-params';
|
|
import { CommonHttpModule } from '@common/http/common-http.module';
|
|
import { InterceptorType } from '@common/http/interceptors/interceptor-type';
|
|
import { CommonUiModule } from '@common/ui/common-ui.module';
|
|
import { TranslateCompiler, TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
|
import { KeycloakAngularModule, KeycloakService } from 'keycloak-angular';
|
|
import { DragulaModule } from 'ng2-dragula';
|
|
import { CookieService } from 'ngx-cookie-service';
|
|
import { NgcCookieConsentConfig, NgcCookieConsentModule } from 'ngx-cookieconsent';
|
|
import { MatomoInitializationMode, NgxMatomoModule } from 'ngx-matomo-client';
|
|
import { from } from 'rxjs';
|
|
import { AuthService } from './core/services/auth/auth.service';
|
|
import { ConfigurationService } from './core/services/configuration/configuration.service';
|
|
import { CultureService } from './core/services/culture/culture-service';
|
|
import { LanguageHttpService } from './core/services/language/language.http.service';
|
|
import { LanguageService } from './core/services/language/language.service';
|
|
import { TranslateServerLoader } from './core/services/language/server.loader';
|
|
import { MatomoService } from './core/services/matomo/matomo-service';
|
|
import { GuidedTourModule } from './library/guided-tour/guided-tour.module';
|
|
import { OpenDMPCustomTranslationCompiler } from './utilities/translate/opendmp-custom-translation-compiler';
|
|
import { CoreAnnotationServiceModule } from 'annotation-service/services/core-service.module';
|
|
import { CoreNotificationServiceModule } from '@notification-service/services/core-service.module';
|
|
import { DepositOauth2DialogModule } from './ui/misc/deposit-oauth2-dialog/deposit-oauth2-dialog.module';
|
|
import { AnalyticsService } from './core/services/matomo/analytics-service';
|
|
|
|
// AoT requires an exported function for factories
|
|
export function HttpLoaderFactory(languageHttpService: LanguageHttpService) {
|
|
return new TranslateServerLoader(languageHttpService);
|
|
}
|
|
|
|
const cookieConfig: NgcCookieConsentConfig = {
|
|
enabled: true,
|
|
cookie: {
|
|
domain: ""//environment.App // or 'your.domain.com' // it is mandatory to set a domain, for cookies to work properly (see https://goo.gl/S2Hy2A)
|
|
},
|
|
palette: {
|
|
popup: {
|
|
background: "#000000",
|
|
text: "#ffffff",
|
|
link: "#ffffff"
|
|
},
|
|
button: {
|
|
background: "#00b29f",
|
|
text: "#ffffff",
|
|
border: "transparent"
|
|
}
|
|
},
|
|
content: {
|
|
message: "This website uses cookies to enhance the user experience.",
|
|
dismiss: "Got it!",
|
|
deny: "Refuse cookies",
|
|
link: "Learn more",
|
|
href: "",//environment.App + "terms-of-service",
|
|
policy: "Cookies Policy"
|
|
},
|
|
position: "bottom-right",
|
|
theme: 'edgeless',
|
|
type: 'info'
|
|
};
|
|
|
|
const appearance: MatFormFieldDefaultOptions = {
|
|
appearance: 'outline'
|
|
// appearance: 'standard'
|
|
};
|
|
|
|
export function InstallationConfigurationFactory(appConfig: ConfigurationService, keycloak: KeycloakService, authService: AuthService, languageService: LanguageService) {
|
|
return () => appConfig.loadConfiguration().then(() => {
|
|
return languageService.loadAvailableLanguages().toPromise();
|
|
}).then(x => keycloak.init({
|
|
config: {
|
|
url: appConfig.keycloak.address,
|
|
realm: appConfig.keycloak.realm,
|
|
clientId: appConfig.keycloak.clientId,
|
|
},
|
|
initOptions: {
|
|
onLoad: 'check-sso',
|
|
flow: appConfig.keycloak.flow,
|
|
checkLoginIframe: false,
|
|
scope: appConfig.keycloak.scope,
|
|
pkceMethod: 'S256'
|
|
},
|
|
shouldAddToken: () => false
|
|
}).then(() => {
|
|
const params = new BaseHttpParams();
|
|
params.interceptorContext = {
|
|
excludedInterceptors: [
|
|
InterceptorType.Locale,
|
|
InterceptorType.ProgressIndication,
|
|
InterceptorType.RequestTiming,
|
|
InterceptorType.UnauthorizedResponse,
|
|
]
|
|
};
|
|
const tokenPromise = keycloak.getToken();
|
|
return authService.prepareAuthRequest(from(tokenPromise), { params }).toPromise().catch(error => authService.onAuthenticateError(error));
|
|
}));
|
|
}
|
|
|
|
|
|
@NgModule({
|
|
imports: [
|
|
BrowserModule,
|
|
BrowserAnimationsModule,
|
|
KeycloakAngularModule,
|
|
CoreServiceModule.forRoot(),
|
|
CoreAnnotationServiceModule.forRoot(),
|
|
CoreNotificationServiceModule.forRoot(),
|
|
AppRoutingModule,
|
|
CommonUiModule,
|
|
TranslateModule.forRoot({
|
|
compiler: { provide: TranslateCompiler, useClass: OpenDMPCustomTranslationCompiler },
|
|
loader: {
|
|
provide: TranslateLoader,
|
|
useFactory: HttpLoaderFactory,
|
|
deps: [LanguageHttpService]
|
|
}
|
|
}),
|
|
HttpClientModule,
|
|
OverlayModule,
|
|
CommonHttpModule,
|
|
MatMomentDateModule,
|
|
LoginModule,
|
|
//Ui
|
|
NotificationModule,
|
|
// BreadcrumbModule,
|
|
ReactiveFormsModule,
|
|
FormsModule,
|
|
NavbarModule,
|
|
SidebarModule,
|
|
NgcCookieConsentModule.forRoot(cookieConfig),
|
|
DepositOauth2DialogModule,
|
|
GuidedTourModule.forRoot(),
|
|
DragulaModule.forRoot(),
|
|
NgxMatomoModule.forRoot({
|
|
mode: MatomoInitializationMode.AUTO_DEFERRED,
|
|
})
|
|
],
|
|
declarations: [
|
|
AppComponent,
|
|
ReloadHelperComponent
|
|
],
|
|
providers: [
|
|
ConfigurationService,
|
|
{
|
|
provide: APP_INITIALIZER,
|
|
useFactory: InstallationConfigurationFactory,
|
|
deps: [ConfigurationService, KeycloakService, AuthService, LanguageService],
|
|
multi: true
|
|
},
|
|
{
|
|
provide: MAT_DATE_LOCALE,
|
|
deps: [CultureService],
|
|
useFactory: (cultureService) => cultureService.getCurrentCulture().name
|
|
},
|
|
{ provide: MAT_DATE_FORMATS, useValue: MAT_MOMENT_DATE_FORMATS },
|
|
{ provide: DateAdapter, useClass: MomentUtcDateAdapter },
|
|
{
|
|
provide: LOCALE_ID,
|
|
deps: [CultureService],
|
|
useFactory: (cultureService) => cultureService.getCurrentCulture().name
|
|
},
|
|
{
|
|
provide: MAT_FORM_FIELD_DEFAULT_OPTIONS,
|
|
useValue: appearance
|
|
},
|
|
Title,
|
|
CookieService,
|
|
MatomoService,
|
|
AnalyticsService
|
|
],
|
|
bootstrap: [AppComponent]
|
|
})
|
|
export class AppModule { }
|