2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
22 import * as _ from "lodash";
23 import {IAppConfigurtaion, User, IUser} from "app/models";
24 import {IUserProperties} from "../../models/user";
25 import {UserService} from "../../ng2/services/user.service";
27 export class MenuItem {
33 children:Array<MenuItem>
36 export interface IEcompHeaderDirectiveScope extends ng.IScope {
37 menuData:Array<MenuItem>;
42 megaMenuDataObjectTemp:Array<any>;
43 megaMenuDataObject:Array<any>;
45 selectedTopMenu:MenuItem;
46 selectedSubMenu:MenuItem;
48 firstMenuLevelClick:Function;
49 subMenuEnterAction:Function;
50 subMenuLeaveAction:Function;
52 memuItemClick:Function;
56 export class EcompHeaderDirective implements ng.IDirective {
58 constructor(private $http:ng.IHttpService,
59 private sdcConfig:IAppConfigurtaion,
60 private userService:UserService) {
70 public replace = true;
71 public restrict = 'E';
72 public controller = EcompHeaderController;
74 template = ():string => {
75 return 'src/app/directives/ecomp-header/ecomp-header.html';
78 link = ($scope:IEcompHeaderDirectiveScope, $elem:JQuery, attr:any) => {
80 if (!$scope.clickableLogo) {
81 $scope.clickableLogo = "true";
84 let findMenuItemById = (menuId):MenuItem => {
85 let selectedMenuItem:MenuItem = _.find($scope.menuData, (item:MenuItem)=> {
86 if (item.menuId === menuId) {
90 return selectedMenuItem;
93 let initUser = ():void => {
94 let defaultUserId:string;
95 let userInfo:IUserProperties = this.userService.getLoggedinUser();
97 defaultUserId = this.$http.defaults.headers.common[this.sdcConfig.cookie.userIdSuffix];
98 this.userService.getUser(defaultUserId).subscribe((defaultUserInfo):void => {
99 $scope.user = new User(defaultUserInfo);
102 $scope.user = new User(userInfo);
106 $scope.firstMenuLevelClick = (menuId:number):void => {
107 let selectedMenuItem:MenuItem = _.find($scope.megaMenuDataObjectTemp, (item:MenuItem)=> {
108 if (item.menuId === menuId) {
112 if (selectedMenuItem) {
113 $scope.selectedTopMenu = selectedMenuItem;
114 //console.log("Selected menu item: " + selectedMenuItem.text);
118 $scope.subMenuEnterAction = (menuId:number):void => {
119 $scope.selectedSubMenu = findMenuItemById(menuId);
122 $scope.subMenuLeaveAction = (menuId:number):void => {
123 $scope.selectedTopMenu = undefined;
126 $scope.memuItemClick = (menuItem:MenuItem):void => {
128 window.location.href = menuItem.url;
130 console.log("Menu item: " + menuItem.text + " does not have defined URL!");
138 public static factory = ($http:ng.IHttpService,
139 sdcConfig:IAppConfigurtaion,
140 userService:UserService)=> {
141 return new EcompHeaderDirective($http, sdcConfig, userService);
146 export class EcompHeaderController {
149 getAttachId:Function;
163 constructor(private $element:JQuery,
164 private $scope:IEcompHeaderDirectiveScope,
165 private $attrs:ng.IAttributes,
166 private $animate:any) {
168 this.$scope = $scope;
170 this.$scope.$watch('menuData', (newVal, oldVal) => {
180 this.$scope.contactUsUrl = "https://wiki.web.att.com/display/EcompPortal/ECOMP+Portal+Home";
181 this.$scope.getAccessUrl = "http://ecomp-tlv-dev2.uccentral.att.com:8080/ecompportal/get_access";
183 let unflatten = (array, parent?, tree?) => {
184 tree = typeof tree !== 'undefined' ? tree : [];
185 parent = typeof parent !== 'undefined' ? parent : {menuId: null};
186 let children = _.filter(array, function (child) {
187 return child["parentMenuId"] == parent.menuId;
189 if (!_.isEmpty(children)) {
190 if (parent.menuId === null) {
193 parent['children'] = children
195 _.each(children, function (child) {
196 unflatten(array, child)
202 let menuStructureConvert = (menuItems) => {
203 console.log(menuItems);
204 this.$scope.megaMenuDataObjectTemp = [
216 url: this.$scope.contactUsUrl
223 url: this.$scope.getAccessUrl
225 return this.$scope.megaMenuDataObjectTemp;
228 let a = unflatten(this.$scope.menuData);
229 this.$scope.megaMenuDataObject = menuStructureConvert(a);
230 //console.log(this.$scope.megaMenuDataObject);
234 EcompHeaderDirective.factory.$inject = ['$http', 'sdcConfig', 'UserServiceNg2'];