2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 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 * as _ from 'underscore';
39 import { Component, OnInit } from '@angular/core';
40 import { MenusService } from 'src/app/shared/services/menus/menus.service';
41 import { AddTabFunctionService } from 'src/app/shared/services/tab/add-tab-function.service';
42 import { Router } from '@angular/router';
45 selector: 'app-header-menu',
46 templateUrl: './header-menu.component.html',
47 styleUrls: ['./header-menu.component.scss']
49 export class HeaderMenuComponent implements OnInit {
50 hideMenus: boolean[] = [];
51 hideSecondLevelMenus: boolean[][] = [];
52 hideThirdLevelMenus: boolean[] = [];
53 megaMenuDataObject: any[];
54 favoritesMenuItems: any[];
55 favoritesWindow: boolean;
56 showFavorites: boolean;
57 emptyFavorites: boolean;
58 favoriteItemsCount: number;
60 constructor(public router: Router, private menusService: MenusService, private addTabFuntionService: AddTabFunctionService) { }
63 //this.hideMenus[0] = false;
64 this.getFunctionalMenuForUser();
68 unflatten(array: any, parent?: any, tree?: any) {
69 tree = typeof tree !== 'undefined' ? tree : [];
70 parent = typeof parent !== 'undefined' ? parent : { menuId: null };
71 var children = _.filter(array, function (child: any) {
72 return child.parentMenuId == parent.menuId;
74 if (!_.isEmpty(children)) {
75 if (parent.menuId === null) {
78 parent['children'] = children
80 _.each(children, function (child: any) {
81 this.unflatten(array, child)
87 getFunctionalMenuForUser() {
88 this.menusService.getFunctionalMenuForUser().subscribe((jsonHeaderMenu: any) => {
89 this.megaMenuDataObject = this.unflatten(jsonHeaderMenu);
90 // for (let entry of this.megaMenuDataObject) {
91 // console.log('First level '+entry.text);
92 // for (let secondLevel of entry.children)
96 // console.log('Second level '+secondLevel.text);
97 // for (let thirdLevel of secondLevel.children)
99 // console.log('Third level '+thirdLevel.text);
109 console.log('HeaderCtrl::GetFunctionalMenuForUser: HeaderCtrl json returned: ' + err);
114 this.menusService.getFavoriteItems().toPromise().then((jsonFavourites: any) => {
115 this.favoritesMenuItems = jsonFavourites;
116 if (this.favoritesMenuItems) {
117 this.favoriteItemsCount = this.favoritesMenuItems.length;
120 console.log('HeaderCtrl::getFavoriteItems: HeaderCtrl json returned: ' + err);
123 loadFirstLevel(index: any) {
125 this.hideSecondLevelMenus = [];
126 for (let firstLevelIndex = 0; firstLevelIndex < this.megaMenuDataObject.length; firstLevelIndex++) {
127 this.hideMenus.push(false);
128 this.hideSecondLevelMenus.push(new Array(this.megaMenuDataObject[firstLevelIndex].length).fill(false));
130 this.hideMenus[index] = true;
131 if (!this.favoritesMenuItems) {
132 this.getFavoriteItems();
136 isUrlFavorite(menuId: any) {
137 if (this.favoritesMenuItems) {
138 var jsonMenu = JSON.stringify(this.favoritesMenuItems);
139 var isMenuFavorite = jsonMenu.indexOf('menuId\":' + menuId);
140 if (isMenuFavorite == -1) {
150 submenuLevelAction(index: any, column: any) {
151 //console.log('index and column' + index + column);
152 if (index == 'Favorites' && this.favoriteItemsCount != 0) {
153 this.favoritesWindow = true;
154 this.showFavorites = true;
155 this.emptyFavorites = false;
157 if (index == 'Favorites' && this.favoriteItemsCount == 0) {
158 this.favoritesWindow = true;
159 this.showFavorites = false;
160 this.emptyFavorites = true;
162 if (index != 'Favorites') {
163 this.favoritesWindow = false;
164 this.showFavorites = false;
165 this.emptyFavorites = false;
168 hideFavoritesWindow() {
169 this.showFavorites = false;
170 this.emptyFavorites = false;
172 removeAsFavoriteItem(event: any, menuId: any) {
173 this.menusService.removeFavoriteItem(menuId).subscribe(() => {
174 //angular.element('#' + event.target.id).css('color', '#666666');
175 this.getFavoriteItems();
177 console.error('HeaderCtrl::removeAsFavoriteItem: API removeFavoriteItem error: ' + err);
180 hideThirdLevelMenu(firstLevelIndex: any, secondLevelIndex: any) {
181 this.hideSecondLevelMenus = [];
182 for (let firstLevelIndex = 0; firstLevelIndex < this.megaMenuDataObject.length; firstLevelIndex++) {
183 this.hideSecondLevelMenus.push(new Array(this.megaMenuDataObject[firstLevelIndex].length).fill(false));
185 this.hideSecondLevelMenus[firstLevelIndex][secondLevelIndex] = true;
188 clickOutSide(event: any) {
190 this.hideSecondLevelMenus = [];
191 for (let firstLevelIndex = 0; firstLevelIndex < this.megaMenuDataObject.length; firstLevelIndex++) {
192 this.hideMenus.push(false);
193 this.hideSecondLevelMenus.push(new Array(this.megaMenuDataObject[firstLevelIndex].length).fill(false));
197 setAsFavoriteItem(event: any, menuId: any) {
201 //console.log('Get into URL function' + item.url);
203 let restrictedApp = item.restrictedApp;
205 console.log('HeaderCtrl::goToUrl: No url found for this application, doing nothing..');
209 window.open(url, '_blank');
211 if (item.url == "getAccess" || item.url == "contactUs") {
213 this.router.navigate(['/' + item.url]);
222 this.addTabFuntionService.filter(tabContent);
227 auditLog(link: any, action: any) {