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, Output, EventEmitter } 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;
63 languages: string[] = [];
66 @Output() languageEvent = new EventEmitter();
68 constructor(public router: Router, private userProfileService: UserProfileService, private menusService: MenusService, private cookieService: CookieService) {
70 this.router.events.subscribe(val => {
72 val instanceof NavigationEnd &&
73 window.innerWidth <= 992 &&
82 this.pushRightClass = 'push-right';
83 this.getUserInformation();
85 this.brandName = "ONAP Portal";
86 if(this.api.brandName != ''){
87 this.brandName = this.api.brandName;
90 this.brandLogoImagePath = "assets/images/global.logo";
91 if(this.api.brandLogoImagePath != ''){
92 this.brandLogoImagePath = this.api.brandLogoImagePath;
95 this.menusService.getAllLanguages().subscribe(data =>{
97 for(let lang of this.result.languageList ){
98 this.languages.push(lang);
101 this.menusService.getCurrentLang(this.loginSnippetUserid).subscribe(data=>{
103 this.languages.map((obj:any)=>{
104 obj.selected = obj.languageId == parseInt(this.result.languageId);
110 getUserInformation() {
111 this.userProfileService.getFunctionalMenuStaticInfo().toPromise().then((res: any) => {
112 if (res === null || res.firstName === null || res.firstName === '' || res.lastName === null || res.lastName === '') {
113 // $log.info('HeaderCtrl: failed to get all required data, trying user profile');
114 this.userProfileService.getUserProfile().toPromise().then((profile: any) => {
115 this.firstName = profile.firstName;
116 this.lastName = profile.lastName;
118 // $log.error('Header Controller:: getUserProfile() failed: ' + err);
121 this.firstName = res.firstName;
122 this.lastName = res.lastName;
123 this.loginSnippetEmail = res.email;
124 this.loginSnippetUserid = res.userId;
125 this.lastLogin = Date.parse(res.last_login);
127 if(res != null && res.isSystemUser === 'true'){
128 this.isSystemUser = true;
130 sessionStorage.userId = res.userId;
131 this.menusService.getFunctionalMenuForUser().toPromise().then((jsonHeaderMenu: any) => {
132 // $scope.menuItems = unflatten(jsonHeaderMenu);
133 // $scope.megaMenuDataObject = $scope.menuItems;
135 // $log.error('HeaderCtrl::GetFunctionalMenuForUser: HeaderCtrl json returned: ' + err);
139 // $log.error('HeaderCtrl::getFunctionalMenuStaticInfo failed: ' + err);
143 // unflatten = function( array, parent, tree ){
145 // tree = typeof tree !== 'undefined' ? tree : [];
146 // parent = typeof parent !== 'undefined' ? parent : { menuId: null };
147 // var children = _.filter( array, function(child){ return child.parentMenuId == parent.menuId; });
149 // if( !_.isEmpty( children ) ){
150 // if( parent.menuId === null ){
153 // parent['children'] = children
155 // _.each( children, function( child ){ unflatten( array, child ) } );
161 getUserApplicationRoles() {
162 this.userapproles = [];
163 if (this.displayUserAppRoles) {
164 this.displayUserAppRoles = false;
166 this.displayUserAppRoles = true;
167 this.isLoading = true;
168 this.userProfileService.getUserAppRoles(this.loginSnippetUserid)
169 .subscribe((res: any) => {
170 this.isLoading = false;
171 for (var i = 0; i < res.length; i++) {
174 Roles: res[i].roleNames,
176 this.userapproles.push(userapprole);
179 this.isLoading = false;
187 this.displayUserAppRoles=false;
188 var cookieTabs = this.cookieService.get("visInVisCookieTabs").toString;
189 if(cookieTabs!=null){
190 for(var t in cookieTabs){
192 var url = cookieTabs[t].content;
194 this.menusService.logout(url);
198 // wait for individual applications to log out before the portal logout
199 setTimeout(function() {
200 window.location.href = "logout.htm";
204 isToggled(): boolean {
205 const dom: Element = document.querySelector('body');
206 return dom.classList.contains(this.pushRightClass);
210 const dom: any = document.querySelector('body');
211 dom.classList.toggle(this.pushRightClass);
215 localStorage.removeItem('isLoggedin');
218 setLanguage(langId : string){
220 this.menusService.setLanguage(langId, this.loginSnippetUserid).subscribe(data =>{
221 this.languageEvent.emit(langId);