argos/dmp-frontend/src/app/app.module.ts

192 lines
7.2 KiB
TypeScript
Raw Normal View History

2019-01-18 18:03:45 +01:00
import { OverlayModule } from '@angular/cdk/overlay';
2023-12-20 08:20:38 +01:00
import { HttpClientModule } from '@angular/common/http';
2023-10-11 16:53:12 +02:00
import { APP_INITIALIZER, LOCALE_ID, NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
2023-10-05 21:42:47 +02:00
import { MAT_MOMENT_DATE_FORMATS, MatMomentDateModule } from '@angular/material-moment-adapter';
import { DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE } from '@angular/material/core';
2023-10-06 10:10:53 +02:00
import { MAT_FORM_FIELD_DEFAULT_OPTIONS, MatFormFieldDefaultOptions } from '@angular/material/form-field';
2019-09-16 17:46:19 +02:00
import { BrowserModule, Title } from '@angular/platform-browser';
2018-11-27 15:03:57 +01:00
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';
2019-12-13 12:15:12 +01:00
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';
2023-11-29 14:26:40 +01:00
import { BaseHttpParams } from '@common/http/base-http-params';
import { CommonHttpModule } from '@common/http/common-http.module';
2023-11-29 14:26:40 +01:00
import { InterceptorType } from '@common/http/interceptors/interceptor-type';
import { CommonUiModule } from '@common/ui/common-ui.module';
import { TranslateCompiler, TranslateLoader, TranslateModule } from '@ngx-translate/core';
2023-11-29 14:26:40 +01:00
import { KeycloakAngularModule, KeycloakService } from 'keycloak-angular';
2021-09-24 20:52:14 +02:00
import { DragulaModule } from 'ng2-dragula';
import { CookieService } from 'ngx-cookie-service';
import { NgcCookieConsentConfig, NgcCookieConsentModule } from 'ngx-cookieconsent';
2023-10-05 21:42:47 +02:00
import { MatomoInitializationMode, NgxMatomoModule } from 'ngx-matomo-client';
2023-11-29 14:26:40 +01:00
import { from } from 'rxjs';
import { AuthService } from './core/services/auth/auth.service';
import { ConfigurationService } from './core/services/configuration/configuration.service';
2021-09-24 20:52:14 +02:00
import { CultureService } from './core/services/culture/culture-service';
2023-11-29 14:26:40 +01:00
import { LanguageHttpService } from './core/services/language/language.http.service';
import { LanguageService } from './core/services/language/language.service';
2020-12-10 14:29:24 +01:00
import { TranslateServerLoader } from './core/services/language/server.loader';
import { MatomoService } from './core/services/matomo/matomo-service';
2020-07-30 17:29:20 +02:00
import { GuidedTourModule } from './library/guided-tour/guided-tour.module';
2023-10-05 21:42:47 +02:00
import { OpenDMPCustomTranslationCompiler } from './utilities/translate/opendmp-custom-translation-compiler';
import { CoreAnnotationServiceModule } from 'annotation-service/services/core-service.module';
2024-04-11 15:43:10 +02:00
import { CoreNotificationServiceModule } from '@notification-service/services/core-service.module';
2024-05-20 11:20:21 +02:00
import { DepositOauth2DialogModule } from './ui/misc/deposit-oauth2-dialog/deposit-oauth2-dialog.module';
2024-05-21 17:04:57 +02:00
import { AnalyticsService } from './core/services/matomo/analytics-service';
2017-12-14 17:43:57 +01:00
2019-01-18 18:03:45 +01:00
// AoT requires an exported function for factories
2023-11-29 14:26:40 +01:00
export function HttpLoaderFactory(languageHttpService: LanguageHttpService) {
return new TranslateServerLoader(languageHttpService);
2019-01-18 18:03:45 +01:00
}
2018-10-02 16:33:58 +02:00
2019-11-19 17:28:25 +01:00
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)
2019-11-19 17:28:25 +01:00
},
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",
2020-06-25 16:52:00 +02:00
policy: "Cookies Policy"
2019-11-19 17:28:25 +01:00
},
position: "bottom-right",
theme: 'edgeless',
type: 'info'
};
2020-07-29 17:04:19 +02:00
const appearance: MatFormFieldDefaultOptions = {
appearance: 'outline'
// appearance: 'standard'
};
2023-11-29 14:26:40 +01:00
export function InstallationConfigurationFactory(appConfig: ConfigurationService, keycloak: KeycloakService, authService: AuthService, languageService: LanguageService) {
return () => appConfig.loadConfiguration().then(() => {
return languageService.loadAvailableLanguages().toPromise();
}).then(x => keycloak.init({
2023-10-11 16:53:12 +02:00
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'
},
2023-11-29 14:26:40 +01:00
shouldAddToken: () => false
2023-10-11 16:53:12 +02:00
}).then(() => {
const params = new BaseHttpParams();
params.interceptorContext = {
excludedInterceptors: [
InterceptorType.Locale,
InterceptorType.ProgressIndication,
InterceptorType.RequestTiming,
InterceptorType.UnauthorizedResponse,
]
};
const tokenPromise = keycloak.getToken();
2023-11-29 14:26:40 +01:00
return authService.prepareAuthRequest(from(tokenPromise), { params }).toPromise().catch(error => authService.onAuthenticateError(error));
2023-10-11 16:53:12 +02:00
}));
}
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
2023-10-11 16:53:12 +02:00
KeycloakAngularModule,
2019-01-18 18:03:45 +01:00
CoreServiceModule.forRoot(),
CoreAnnotationServiceModule.forRoot(),
CoreNotificationServiceModule.forRoot(),
2019-01-18 18:03:45 +01:00
AppRoutingModule,
CommonUiModule,
TranslateModule.forRoot({
compiler: { provide: TranslateCompiler, useClass: OpenDMPCustomTranslationCompiler },
loader: {
provide: TranslateLoader,
useFactory: HttpLoaderFactory,
2023-11-29 14:26:40 +01:00
deps: [LanguageHttpService]
}
}),
2019-01-18 18:03:45 +01:00
HttpClientModule,
OverlayModule,
CommonHttpModule,
MatMomentDateModule,
LoginModule,
2019-01-18 18:03:45 +01:00
//Ui
NotificationModule,
// BreadcrumbModule,
ReactiveFormsModule,
FormsModule,
2019-04-24 11:26:53 +02:00
NavbarModule,
2019-11-19 17:28:25 +01:00
SidebarModule,
NgcCookieConsentModule.forRoot(cookieConfig),
2024-05-20 11:20:21 +02:00
DepositOauth2DialogModule,
GuidedTourModule.forRoot(),
2023-10-05 21:42:47 +02:00
DragulaModule.forRoot(),
NgxMatomoModule.forRoot({
mode: MatomoInitializationMode.AUTO_DEFERRED,
})
2019-01-18 18:03:45 +01:00
],
declarations: [
2019-12-13 12:15:12 +01:00
AppComponent,
ReloadHelperComponent
],
providers: [
2023-10-11 16:53:12 +02:00
ConfigurationService,
{
provide: APP_INITIALIZER,
useFactory: InstallationConfigurationFactory,
2023-11-29 14:26:40 +01:00
deps: [ConfigurationService, KeycloakService, AuthService, LanguageService],
2023-10-11 16:53:12 +02:00
multi: true
},
2018-10-05 17:00:54 +02:00
{
provide: MAT_DATE_LOCALE,
deps: [CultureService],
2019-01-18 18:03:45 +01:00
useFactory: (cultureService) => cultureService.getCurrentCulture().name
2018-10-05 17:00:54 +02:00
},
2019-01-18 18:03:45 +01:00
{ provide: MAT_DATE_FORMATS, useValue: MAT_MOMENT_DATE_FORMATS },
{ provide: DateAdapter, useClass: MomentUtcDateAdapter },
2018-10-05 17:00:54 +02:00
{
provide: LOCALE_ID,
deps: [CultureService],
2019-01-18 18:03:45 +01:00
useFactory: (cultureService) => cultureService.getCurrentCulture().name
2018-10-05 17:00:54 +02:00
},
2020-07-29 17:04:19 +02:00
{
provide: MAT_FORM_FIELD_DEFAULT_OPTIONS,
useValue: appearance
},
2019-11-19 17:28:25 +01:00
Title,
2020-12-10 14:29:24 +01:00
CookieService,
2024-05-21 17:04:57 +02:00
MatomoService,
AnalyticsService
],
bootstrap: [AppComponent]
})
export class AppModule { }