import { Component, EventEmitter, Input, OnInit, Output } from "@angular/core"; import { BrandingService } from "../branding.service"; import { BrowserSecurityHelper } from "../browser.security.helper"; import { ImpersonateHelper } from "../impersonate.helper"; @Component({ selector: "rss-uc-header", templateUrl: "./uc-header.component.html", styleUrls: ["./uc-header.component.scss"], providers: [BrandingService], }) export class UcHeaderComponent implements OnInit { @Input() config; @Input() environment; @Output() public menuChange: EventEmitter = new EventEmitter(); @Output() public onBrandingResponse: EventEmitter> = new EventEmitter< Array >(); brandingConfig: any; profile: any; tenantCode: any; constructor(private brandingService: BrandingService) {} ngOnInit() { this.loadPersonDetails(); } loadPersonDetails() { this.getBrandingDetails(); const impersonateUser = ImpersonateHelper.getImpersonateUserId(); const userId = impersonateUser ? impersonateUser : BrowserSecurityHelper.authUser.id; this.getPersonDetails(userId); } private getBrandingDetails = () => { this.brandingService.getBranding(this.environment).subscribe( (res) => { this.brandingConfig = { appList: res.appList, help: res.serviceMap.help, profile: res.serviceMap.profile, suiteTitle: res.brand.suiteTitle, suiteTitleUrl: res.brand.suiteLandingUrl, }; this.brandingService.changeFavicon(res.brand.faviconUrl); if (this.brandingConfig.help) this.brandingConfig.help.contextUrl += this.config.APP_TITLE; this.onBrandingResponse.emit(this.brandingConfig.appList); }, (err) => { console.error(err); } ); }; private getBrandingDetailsByTenantCode = (tenantCode) => { this.brandingService .getBrandingByTenant(tenantCode, this.environment) .subscribe( (res) => { if (res.length != undefined) { this.brandingConfig = { suiteTitle: res.suiteTitle, suiteTitleUrl: res.suiteLandingUrl, }; } else { this.brandingConfig = { suiteTitle: "Risk & Safety Solutions", suiteTitleUrl: "", }; } }, (err) => { console.error(err); } ); }; private getPersonDetails = (username) => { this.brandingService .getPersonDetails(this.environment, username) .subscribe((res) => { this.profile = { firstName: res.firstName, lastName: res.lastName, email: res.email, authId: res.identifiers.authId, }; }); }; toggleMenu() { this.menuChange.emit(); } onClickSkipToContent() { window.location.hash = ""; window.location.hash = "main-content"; document.getElementById("main-content").blur(); } }