import { CoreApplication, CoreProduct } from './../models/index'; export class GlobalSiteHeaderViewController { public static NAME = "GlobalSiteHeaderViewController"; public static NAME_AS = `${GlobalSiteHeaderViewController.NAME} as headerController`; public static $inject = ["$rootScope", "$scope", "SessionDataService", "ApiHost"]; public hamburgerMenuIsVisible = false; public currentApp: CoreApplication; public user: HashidevDashboardCore.IUser; public currentProduct: CoreProduct; public urlForDashboard: string; public urlForProfile: string; public urlForKnowledgebase: string = CoreApplication.DEFAULT.urlForKnowledgebase; public currentSiteIsDefault: boolean; constructor( private $rootScope: ng.IRootScopeService, private $scope: ng.IScope, private sessionDataService: HashidevDashboardCore.ISessionDataService ) { this.setupScopeListeners(); if (!$scope["stateForLogout"]) { $scope["stateForLogout"] = "logout"; } this.sessionDataService.getUser() .then((user) => { this.user = user; }); this.currentApp = CoreApplication.GetApplicationFromSiteKey($scope["site"]); if (this.currentApp && this.currentApp.siteKey === CoreApplication.DEFAULT.siteKey) { this.currentSiteIsDefault = true; } var productFolderName: string = $scope["productFolderName"]; var rootDomain: string = $scope["rootDomain"]; this.currentProduct = CoreProduct.GetFromProductFolderName(productFolderName, rootDomain); this.setUrls(); } private setupScopeListeners() { this.$rootScope.$on("userSetEvent", (event, eventArguments) => { this.$scope["user"] = eventArguments; }); this.$rootScope.$on("practiceSelectedEvent", (event, eventArguments) => { if (this.$scope["practiceId"] == eventArguments) { return; } this.$scope["practiceId"] = eventArguments; }); } public toggleDropDownForHamburger() { this.hamburgerMenuIsVisible = !this.hamburgerMenuIsVisible; } public hideDropDownForHamburger() { this.hamburgerMenuIsVisible = false; } private setUrls() { this.urlForKnowledgebase = this.getUrlForKnowledgebase(); this.urlForDashboard = this.currentProduct.urlForDashboard; this.urlForProfile = this.currentProduct.urlForProfile; } private getUrlForKnowledgebase(): string { if (!this.currentApp || !this.currentProduct || !this.currentProduct.urlForKnowledgebase) { return ""; } return this.currentProduct.urlForKnowledgebase + this.currentApp.knwoledgebaseCategoryName; } }