Skip to content
Snippets Groups Projects
Commit d98736fd authored by Fadil's avatar Fadil Committed by pybelecalo
Browse files

[US TRTL-615] Fix tenant selection in portal app

parent e24bd0e2
No related branches found
No related tags found
No related merge requests found
......@@ -41,6 +41,7 @@ import { BehaviorSubject } from 'rxjs';
import { Observable, of, Subject } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import { ApplicationApiService } from './api/application-api.service';
import { ApplicationId } from './application-id.enum';
import { AuthService } from './auth.service';
import { GlobalEventService } from './global-event.service';
import { ApplicationInfo } from './models/application/application.interface';
......@@ -191,6 +192,26 @@ export class ApplicationService {
return new Map([...appMap.entries()].sort((a, b) => a[0].order < b[0].order ? -1 : 1));
}
public getAppById(identifier: string): Application {
return this.applications.find(value => value.identifier === identifier);
}
/**
* Return an observable that notify if the current application has a tenant list or not.
*/
public hasTenantList(): Observable<boolean> {
return new Observable((observer) => {
this.globalEventService.pageEvent.subscribe((appId: string) => {
if (appId === ApplicationId.PORTAL_APP) {
observer.next(true);
} else {
const app = this.applications.find(value => value.identifier === appId);
app ? observer.next(app.hasTenantList) : observer.next(false);
}
});
});
}
private fillCategoriesWithApps(categoriesByIds: { [categoryId: string]: Category }, applications: Application[]) {
const resultMap = new Map<Category, Application[]>();
let categories: Category[] = Object.values(categoriesByIds);
......
......@@ -38,7 +38,7 @@ import { Component, OnDestroy, OnInit } from '@angular/core';
import { SafeResourceUrl } from '@angular/platform-browser';
import { Router } from '@angular/router';
import { Subscription } from 'rxjs';
import { AuthService, StartupService, ThemeDataType, ThemeService } from 'ui-frontend-common';
import { ApplicationId, AuthService, GlobalEventService, StartupService, ThemeDataType, ThemeService } from 'ui-frontend-common';
import { Application, ApplicationService, Category } from 'ui-frontend-common';
@Component({
......@@ -49,13 +49,9 @@ import { Application, ApplicationService, Category } from 'ui-frontend-common';
export class PortalComponent implements OnInit, OnDestroy {
public applications: Map<Category, Application[]>;
public welcomeTitle: string;
public welcomeMessage: string;
public customerLogoUrl: SafeResourceUrl;
public loading = true;
private sub: Subscription;
......@@ -65,7 +61,8 @@ export class PortalComponent implements OnInit, OnDestroy {
private startupService: StartupService,
private authService: AuthService,
private themeService: ThemeService,
private router: Router) { }
private router: Router,
private globalEventService: GlobalEventService) { }
ngOnInit() {
this.sub = this.applicationService.getActiveTenantAppsMap().subscribe((appMap) => {
......@@ -75,6 +72,7 @@ export class PortalComponent implements OnInit, OnDestroy {
this.welcomeTitle = this.themeService.getData(this.authService.user, ThemeDataType.PORTAL_TITLE) as string;
this.welcomeMessage = this.themeService.getData(this.authService.user, ThemeDataType.PORTAL_MESSAGE) as string;
this.customerLogoUrl = this.themeService.getData(this.authService.user, ThemeDataType.PORTAL_LOGO);
this.globalEventService.pageEvent.next(ApplicationId.PORTAL_APP);
}
ngOnDestroy() {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment