2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright � 2019 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
38 import { Component, OnInit } from '@angular/core';
39 import { Router, NavigationEnd } from '@angular/router';
40 import { UserProfileService, MenusService } from 'src/app/shared/services';
41 import { CookieService } from 'ngx-cookie-service';
42 import { environment } from 'src/environments/environment';
45 selector: 'app-header',
46 templateUrl: './header.component.html',
47 styleUrls: ['./header.component.scss']
49 export class HeaderComponent implements OnInit {
50 public pushRightClass: string;
53 loginSnippetUserid: any;
55 loginSnippetEmail: any;
57 displayUserAppRoles: any;
59 api = environment.api;
61 brandLogoImagePath: string;
62 isSystemUser: boolean = false;
64 constructor(public router: Router, private userProfileService: UserProfileService, private menusService: MenusService, private cookieService: CookieService) {
66 this.router.events.subscribe(val => {
68 val instanceof NavigationEnd &&
69 window.innerWidth <= 992 &&
78 this.pushRightClass = 'push-right';
79 this.getUserInformation();
81 this.brandName = "ONAP Portal";
82 if(this.api.brandName != ''){
83 this.brandName = this.api.brandName;
86 this.brandLogoImagePath = "assets/images/global.logo";
87 if(this.api.brandLogoImagePath != ''){
88 this.brandLogoImagePath = this.api.brandLogoImagePath;
92 getUserInformation() {
93 this.userProfileService.getFunctionalMenuStaticInfo().toPromise().then((res: any) => {
94 if (res === null || res.firstName === null || res.firstName === '' || res.lastName === null || res.lastName === '') {
95 // $log.info('HeaderCtrl: failed to get all required data, trying user profile');
96 this.userProfileService.getUserProfile().toPromise().then((profile: any) => {
97 this.firstName = profile.firstName;
98 this.lastName = profile.lastName;
100 // $log.error('Header Controller:: getUserProfile() failed: ' + err);
103 this.firstName = res.firstName;
104 this.lastName = res.lastName;
105 this.loginSnippetEmail = res.email;
106 this.loginSnippetUserid = res.userId;
107 this.lastLogin = Date.parse(res.last_login);
109 if(res != null && res.isSystemUser === 'true'){
110 this.isSystemUser = true;
112 sessionStorage.userId = res.userId;
113 this.menusService.getFunctionalMenuForUser().toPromise().then((jsonHeaderMenu: any) => {
114 // $scope.menuItems = unflatten(jsonHeaderMenu);
115 // $scope.megaMenuDataObject = $scope.menuItems;
117 // $log.error('HeaderCtrl::GetFunctionalMenuForUser: HeaderCtrl json returned: ' + err);
121 // $log.error('HeaderCtrl::getFunctionalMenuStaticInfo failed: ' + err);
125 // unflatten = function( array, parent, tree ){
127 // tree = typeof tree !== 'undefined' ? tree : [];
128 // parent = typeof parent !== 'undefined' ? parent : { menuId: null };
129 // var children = _.filter( array, function(child){ return child.parentMenuId == parent.menuId; });
131 // if( !_.isEmpty( children ) ){
132 // if( parent.menuId === null ){
135 // parent['children'] = children
137 // _.each( children, function( child ){ unflatten( array, child ) } );
143 getUserApplicationRoles() {
144 this.userapproles = [];
145 if (this.displayUserAppRoles) {
146 this.displayUserAppRoles = false;
148 this.displayUserAppRoles = true;
149 this.isLoading = true;
150 this.userProfileService.getUserAppRoles(this.loginSnippetUserid)
151 .subscribe((res: any) => {
152 this.isLoading = false;
153 for (var i = 0; i < res.length; i++) {
156 Roles: res[i].roleNames,
158 this.userapproles.push(userapprole);
161 this.isLoading = false;
169 this.displayUserAppRoles=false;
170 var cookieTabs = this.cookieService.get("visInVisCookieTabs").toString;
171 if(cookieTabs!=null){
172 for(var t in cookieTabs){
174 var url = cookieTabs[t].content;
176 this.menusService.logout(url);
180 // wait for individual applications to log out before the portal logout
181 setTimeout(function() {
182 window.location.href = "logout.htm";
186 isToggled(): boolean {
187 const dom: Element = document.querySelector('body');
188 return dom.classList.contains(this.pushRightClass);
192 const dom: any = document.querySelector('body');
193 dom.classList.toggle(this.pushRightClass);
197 localStorage.removeItem('isLoggedin');