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;
98 this.menusService.getAllLanguages().subscribe(data =>{
100 for(let lang of this.result.languageList ){
101 this.languages.push(lang);
104 this.menusService.getCurrentLang(this.loginSnippetUserid).subscribe(data=>{
106 this.languages.map((obj:any)=>{
107 obj.selected = obj.languageId == parseInt(this.result.languageId);
113 getUserInformation() {
114 this.userProfileService.getFunctionalMenuStaticInfo().toPromise().then((res: any) => {
115 if (res === null || res.firstName === null || res.firstName === '' || res.lastName === null || res.lastName === '') {
116 // $log.info('HeaderCtrl: failed to get all required data, trying user profile');
117 this.userProfileService.getUserProfile().toPromise().then((profile: any) => {
118 this.firstName = profile.firstName;
119 this.lastName = profile.lastName;
121 // $log.error('Header Controller:: getUserProfile() failed: ' + err);
124 this.firstName = res.firstName;
125 this.lastName = res.lastName;
126 this.loginSnippetEmail = res.email;
127 this.loginSnippetUserid = res.userId;
128 this.lastLogin = Date.parse(res.last_login);
129 this.getLanguageInfo();
131 if(res != null && res.isSystemUser === 'true'){
132 this.isSystemUser = true;
134 sessionStorage.userId = res.userId;
135 this.menusService.getFunctionalMenuForUser().toPromise().then((jsonHeaderMenu: any) => {
136 // $scope.menuItems = unflatten(jsonHeaderMenu);
137 // $scope.megaMenuDataObject = $scope.menuItems;
139 // $log.error('HeaderCtrl::GetFunctionalMenuForUser: HeaderCtrl json returned: ' + err);
143 // $log.error('HeaderCtrl::getFunctionalMenuStaticInfo failed: ' + err);
147 // unflatten = function( array, parent, tree ){
149 // tree = typeof tree !== 'undefined' ? tree : [];
150 // parent = typeof parent !== 'undefined' ? parent : { menuId: null };
151 // var children = _.filter( array, function(child){ return child.parentMenuId == parent.menuId; });
153 // if( !_.isEmpty( children ) ){
154 // if( parent.menuId === null ){
157 // parent['children'] = children
159 // _.each( children, function( child ){ unflatten( array, child ) } );
165 getUserApplicationRoles() {
166 this.userapproles = [];
167 if (this.displayUserAppRoles) {
168 this.displayUserAppRoles = false;
170 this.displayUserAppRoles = true;
171 this.isLoading = true;
172 this.userProfileService.getUserAppRoles(this.loginSnippetUserid)
173 .subscribe((res: any) => {
174 this.isLoading = false;
175 for (var i = 0; i < res.length; i++) {
178 Roles: res[i].roleNames,
180 this.userapproles.push(userapprole);
183 this.isLoading = false;
191 this.displayUserAppRoles=false;
192 var cookieTabs = this.cookieService.get("visInVisCookieTabs").toString;
193 if(cookieTabs!=null){
194 for(var t in cookieTabs){
196 var url = cookieTabs[t].content;
198 this.menusService.logout(url);
202 // wait for individual applications to log out before the portal logout
203 setTimeout(function() {
204 window.location.href = "logout.htm";
208 isToggled(): boolean {
209 const dom: Element = document.querySelector('body');
210 return dom.classList.contains(this.pushRightClass);
214 const dom: any = document.querySelector('body');
215 dom.classList.toggle(this.pushRightClass);
219 localStorage.removeItem('isLoggedin');
222 setLanguage(langId : string){
224 this.menusService.setLanguage(langId, this.loginSnippetUserid).subscribe(data =>{
225 this.languageEvent.emit(langId);