diff --git a/dmp-frontend/src/app/core/services/auth/auth.service.ts b/dmp-frontend/src/app/core/services/auth/auth.service.ts index f42ae3d6c..38531c729 100644 --- a/dmp-frontend/src/app/core/services/auth/auth.service.ts +++ b/dmp-frontend/src/app/core/services/auth/auth.service.ts @@ -323,6 +323,15 @@ export class AuthService extends BaseService { ); this.zone.run(() => this.router.navigate([returnUrl])); } + + onAuthenticateSuccessReload(): void { + this.authState(true); + this.uiNotificationService.snackBarNotification( + this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-LOGIN'), + SnackBarNotificationLevel.Success + ); + window.location.reload(); + } public hasPermission(permission: AppPermission): boolean { // if (!this.installationConfiguration.appServiceEnabled) { return true; } //TODO: maybe reconsider diff --git a/dmp-frontend/src/app/ui/navbar/navbar.component.html b/dmp-frontend/src/app/ui/navbar/navbar.component.html index 74721dea0..b219200f2 100644 --- a/dmp-frontend/src/app/ui/navbar/navbar.component.html +++ b/dmp-frontend/src/app/ui/navbar/navbar.component.html @@ -32,7 +32,19 @@ +
+ + + + +
+ + + @@ -70,30 +82,33 @@
  • - {{ 'FAQ.TITLE' | translate }} - + + + + + +
  • -
  • +
  • - - - - - -
    diff --git a/dmp-frontend/src/app/ui/navbar/navbar.module.ts b/dmp-frontend/src/app/ui/navbar/navbar.module.ts index 21ffdf8f3..6bea2ba88 100644 --- a/dmp-frontend/src/app/ui/navbar/navbar.module.ts +++ b/dmp-frontend/src/app/ui/navbar/navbar.module.ts @@ -5,13 +5,15 @@ import { CommonFormsModule } from '@common/forms/common-forms.module'; import { CommonUiModule } from '@common/ui/common-ui.module'; import { LanguageModule } from '../language/language.module'; import { UserDialogComponent } from './user-dialog/user-dialog.component'; +import { TenantModule } from '../tenant/tenant.module'; @NgModule({ imports: [ CommonUiModule, CommonFormsModule, RouterModule, - LanguageModule + LanguageModule, + TenantModule ], declarations: [ NavbarComponent, diff --git a/dmp-frontend/src/app/ui/tenant/tenant-switch/tenant-switch.component.html b/dmp-frontend/src/app/ui/tenant/tenant-switch/tenant-switch.component.html new file mode 100644 index 000000000..775d85bba --- /dev/null +++ b/dmp-frontend/src/app/ui/tenant/tenant-switch/tenant-switch.component.html @@ -0,0 +1,5 @@ + +
    + {{ tenant }} +
    +
    diff --git a/dmp-frontend/src/app/ui/tenant/tenant-switch/tenant-switch.component.scss b/dmp-frontend/src/app/ui/tenant/tenant-switch/tenant-switch.component.scss new file mode 100644 index 000000000..5e19e49da --- /dev/null +++ b/dmp-frontend/src/app/ui/tenant/tenant-switch/tenant-switch.component.scss @@ -0,0 +1,9 @@ +::ng-deep.tenant-menu { + border-color: transparent; + padding: 8px; +} + +::ng-deep.tenant-button { + padding-top: 15px; + padding-bottom: 15px; +} diff --git a/dmp-frontend/src/app/ui/tenant/tenant-switch/tenant-switch.component.ts b/dmp-frontend/src/app/ui/tenant/tenant-switch/tenant-switch.component.ts new file mode 100644 index 000000000..1e053cb95 --- /dev/null +++ b/dmp-frontend/src/app/ui/tenant/tenant-switch/tenant-switch.component.ts @@ -0,0 +1,68 @@ +import { Component, EventEmitter, OnInit, Output } from "@angular/core"; +import { MatButtonToggleChange } from "@angular/material/button-toggle"; +import { Router } from "@angular/router"; +import { AuthService } from "@app/core/services/auth/auth.service"; +import { PrincipalService } from "@app/core/services/http/principal.service"; +import { BaseComponent } from "@common/base/base.component"; +import { BaseHttpParams } from "@common/http/base-http-params"; +import { InterceptorType } from "@common/http/interceptors/interceptor-type"; +import { KeycloakService } from "keycloak-angular"; +import { Observable, from } from "rxjs"; +import { takeUntil } from "rxjs/operators"; + +@Component({ + selector: 'app-tenant-switch', + templateUrl: 'tenant-switch.component.html', + styleUrls: ['tenant-switch.component.scss'] +}) +export class TenantSwitchComponent extends BaseComponent implements OnInit { + tenants: Observable>; + + constructor( + private router: Router, + private keycloakService: KeycloakService, + private principalService: PrincipalService, + private authService: AuthService, + ) { + super(); + } + + get currentTenant(): string { + return this.authService.selectedTenant(); + } + + ngOnInit() { + this.tenants = this.loadUserTenants(); //TODO + //this.tenantChange.emit(this.getCurrentLanguage()) + } + + loadUserTenants(): Observable> { + const params = new BaseHttpParams(); + params.interceptorContext = { + excludedInterceptors: [InterceptorType.TenantHeaderInterceptor] + }; + return this.principalService.myTenants({ params: params }); + } + + onTenantSelected(selectedTenant: MatButtonToggleChange) { + if (selectedTenant.value === undefined || selectedTenant.value === '') return; + + this.formSubmit(selectedTenant.value); + this.loadUser(); + } + + formSubmit(selectedTenant: string): void { + this.authService.selectedTenant(selectedTenant); + } + + loadUser(): void { + this.authService.prepareAuthRequest(from(this.keycloakService.getToken()), {}) + .pipe(takeUntil(this._destroyed)) + .subscribe( + () => { + this.authService.onAuthenticateSuccessReload(); + }, + (error) => this.authService.onAuthenticateError(error) + ); + } +} \ No newline at end of file diff --git a/dmp-frontend/src/app/ui/tenant/tenant.module.ts b/dmp-frontend/src/app/ui/tenant/tenant.module.ts new file mode 100644 index 000000000..4dc4415a3 --- /dev/null +++ b/dmp-frontend/src/app/ui/tenant/tenant.module.ts @@ -0,0 +1,18 @@ +import { NgModule } from '@angular/core'; +import { CommonUiModule } from '@common/ui/common-ui.module'; +import { TenantSwitchComponent } from './tenant-switch/tenant-switch.component'; + + + +@NgModule({ + declarations: [ + TenantSwitchComponent, + ], + imports: [ + CommonUiModule + ], + exports: [ + TenantSwitchComponent, + ] +}) +export class TenantModule { }