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;
63 constructor(public router: Router, private userProfileService: UserProfileService, private menusService: MenusService, private cookieService: CookieService) {
65 this.router.events.subscribe(val => {
67 val instanceof NavigationEnd &&
68 window.innerWidth <= 992 &&
77 this.pushRightClass = 'push-right';
78 this.getUserInformation();
80 this.brandName = "ONAP Portal";
81 if(this.api.brandName != ''){
82 this.brandName = this.api.brandName;
85 this.brandLogoImagePath = "assets/images/global.logo";
86 if(this.api.brandLogoImagePath != ''){
87 this.brandLogoImagePath = this.api.brandLogoImagePath;
91 getUserInformation() {
92 this.userProfileService.getFunctionalMenuStaticInfo().toPromise().then((res: any) => {
93 if (res == null || res.firstName == null || res.firstName == '' || res.lastName == null || res.lastName == '') {
94 // $log.info('HeaderCtrl: failed to get all required data, trying user profile');
95 this.userProfileService.getUserProfile().toPromise().then((profile: any) => {
96 this.firstName = profile.firstName;
97 this.lastName = profile.lastName;
99 // $log.error('Header Controller:: getUserProfile() failed: ' + err);
102 this.firstName = res.firstName;
103 this.lastName = res.lastName;
104 this.loginSnippetEmail = res.email;
105 this.loginSnippetUserid = res.userId;
106 this.lastLogin = Date.parse(res.last_login);
108 sessionStorage.userId = res.userId;
109 this.menusService.getFunctionalMenuForUser().toPromise().then((jsonHeaderMenu: any) => {
110 // $scope.menuItems = unflatten(jsonHeaderMenu);
111 // $scope.megaMenuDataObject = $scope.menuItems;
113 // $log.error('HeaderCtrl::GetFunctionalMenuForUser: HeaderCtrl json returned: ' + err);
117 // $log.error('HeaderCtrl::getFunctionalMenuStaticInfo failed: ' + err);
121 // unflatten = function( array, parent, tree ){
123 // tree = typeof tree !== 'undefined' ? tree : [];
124 // parent = typeof parent !== 'undefined' ? parent : { menuId: null };
125 // var children = _.filter( array, function(child){ return child.parentMenuId == parent.menuId; });
127 // if( !_.isEmpty( children ) ){
128 // if( parent.menuId === null ){
131 // parent['children'] = children
133 // _.each( children, function( child ){ unflatten( array, child ) } );
139 getUserApplicationRoles() {
140 this.userapproles = [];
141 if (this.displayUserAppRoles) {
142 this.displayUserAppRoles = false;
144 this.displayUserAppRoles = true;
145 this.isLoading = true;
146 this.userProfileService.getUserAppRoles(this.loginSnippetUserid)
147 .subscribe((res: any) => {
148 this.isLoading = false;
149 for (var i = 0; i < res.length; i++) {
152 Roles: res[i].roleNames,
154 this.userapproles.push(userapprole);
157 this.isLoading = false;
165 this.displayUserAppRoles=false;
166 var cookieTabs = this.cookieService.get("visInVisCookieTabs").toString;
167 if(cookieTabs!=null){
168 for(var t in cookieTabs){
170 var url = cookieTabs[t].content;
172 this.menusService.logout(url);
176 // wait for individual applications to log out before the portal logout
177 setTimeout(function() {
178 window.location.href = "logout.htm";
182 isToggled(): boolean {
183 const dom: Element = document.querySelector('body');
184 return dom.classList.contains(this.pushRightClass);
188 const dom: any = document.querySelector('body');
189 dom.classList.toggle(this.pushRightClass);
193 localStorage.removeItem('isLoggedin');