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";
26 import { AuthenticationService } from "../../ng2/services/authentication.service";
28 export class MenuItem {
34 children:Array<MenuItem>
37 export interface IEcompHeaderDirectiveScope extends ng.IScope {
38 menuData:Array<MenuItem>;
43 megaMenuDataObjectTemp:Array<any>;
44 megaMenuDataObject:Array<any>;
46 selectedTopMenu:MenuItem;
47 selectedSubMenu:MenuItem;
49 firstMenuLevelClick:Function;
50 subMenuEnterAction:Function;
51 subMenuLeaveAction:Function;
53 memuItemClick:Function;
57 export class EcompHeaderDirective implements ng.IDirective {
59 constructor(private $http:ng.IHttpService,
60 private sdcConfig:IAppConfigurtaion,
61 private userService:UserService,
62 private authService:AuthenticationService) {
72 public replace = true;
73 public restrict = 'E';
74 public controller = EcompHeaderController;
76 template = ():string => {
77 return 'src/app/directives/ecomp-header/ecomp-header.html';
80 link = ($scope:IEcompHeaderDirectiveScope, $elem:JQuery, attr:any) => {
82 if (!$scope.clickableLogo) {
83 $scope.clickableLogo = "true";
86 let findMenuItemById = (menuId):MenuItem => {
87 let selectedMenuItem:MenuItem = _.find($scope.menuData, (item:MenuItem)=> {
88 if (item.menuId === menuId) {
92 return selectedMenuItem;
95 let initUser = ():void => {
96 let defaultUserId:string;
97 let userInfo:IUserProperties = this.authService.getLoggedinUser();
99 defaultUserId = this.$http.defaults.headers.common[this.sdcConfig.cookie.userIdSuffix];
100 this.userService.getUser(defaultUserId).subscribe((defaultUserInfo):void => {
101 $scope.user = new User(defaultUserInfo);
104 $scope.user = new User(userInfo);
108 $scope.firstMenuLevelClick = (menuId:number):void => {
109 let selectedMenuItem:MenuItem = _.find($scope.megaMenuDataObjectTemp, (item:MenuItem)=> {
110 if (item.menuId === menuId) {
114 if (selectedMenuItem) {
115 $scope.selectedTopMenu = selectedMenuItem;
116 //console.log("Selected menu item: " + selectedMenuItem.text);
120 $scope.subMenuEnterAction = (menuId:number):void => {
121 $scope.selectedSubMenu = findMenuItemById(menuId);
124 $scope.subMenuLeaveAction = (menuId:number):void => {
125 $scope.selectedTopMenu = undefined;
128 $scope.memuItemClick = (menuItem:MenuItem):void => {
130 window.location.href = menuItem.url;
132 console.log("Menu item: " + menuItem.text + " does not have defined URL!");
140 public static factory = ($http:ng.IHttpService,
141 sdcConfig:IAppConfigurtaion,
142 userService:UserService,
143 authService:AuthenticationService)=> {
144 return new EcompHeaderDirective($http, sdcConfig, userService, authService);
149 export class EcompHeaderController {
152 getAttachId:Function;
166 constructor(private $element:JQuery,
167 private $scope:IEcompHeaderDirectiveScope,
168 private $attrs:ng.IAttributes,
169 private $animate:any) {
171 this.$scope = $scope;
173 this.$scope.$watch('menuData', (newVal, oldVal) => {
183 this.$scope.contactUsUrl = "https://wiki.web.att.com/display/EcompPortal/ECOMP+Portal+Home";
184 this.$scope.getAccessUrl = "http://ecomp-tlv-dev2.uccentral.att.com:8080/ecompportal/get_access";
186 let unflatten = (array, parent?, tree?) => {
187 tree = typeof tree !== 'undefined' ? tree : [];
188 parent = typeof parent !== 'undefined' ? parent : {menuId: null};
189 let children = _.filter(array, function (child) {
190 return child["parentMenuId"] == parent.menuId;
192 if (!_.isEmpty(children)) {
193 if (parent.menuId === null) {
196 parent['children'] = children
198 _.each(children, function (child) {
199 unflatten(array, child)
205 let menuStructureConvert = (menuItems) => {
206 console.log(menuItems);
207 this.$scope.megaMenuDataObjectTemp = [
219 url: this.$scope.contactUsUrl
226 url: this.$scope.getAccessUrl
228 return this.$scope.megaMenuDataObjectTemp;
231 let a = unflatten(this.$scope.menuData);
232 this.$scope.megaMenuDataObject = menuStructureConvert(a);
233 //console.log(this.$scope.megaMenuDataObject);
237 EcompHeaderDirective.factory.$inject = ['$http', 'sdcConfig', 'UserServiceNg2', 'AuthenticationServiceNg2'];