Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / app / fusion / scripts / services / headerService.js
1 /*-
2  * ================================================================================
3  * eCOMP Portal SDK
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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  * ================================================================================
19  */
20 var menuStructureConvert = function(menuItems) {
21         var megaMenuDataObjectTemp = [
22                                          {
23                                                  text: "ECOMP",
24                                                  children:menuItems
25                                          },
26                                          {
27                                                  text: "Help",
28                                                  children: [{
29                                                          text:"Contact Us",
30                                                          url:"javascript:angular.element('[ng-controller=headerController]').scope().redirectLink('contact');"
31                                                  },
32                                                  {
33                                                          text:"Get Access",
34                                                          url:"javascript:angular.element('[ng-controller=headerController]').scope().redirectLink('access');"
35                                                  }]
36                                          }
37                                          ];
38         return megaMenuDataObjectTemp;
39 }; 
40 var unflatten = function( array, parent, tree ){
41                         tree = typeof tree !== 'undefined' ? tree : [];
42                         parent = typeof parent !== 'undefined' ? parent : { menuId: null };
43                         var children = _.filter( array, function(child){ return child.parentMenuId == parent.menuId; });
44                 
45                         if( !_.isEmpty( children )  ){
46                                 if( parent.menuId === null ){
47                                                 tree = children;
48                                 }else{
49                                         parent['children'] = children
50                                 }
51                                 _.each( children, function( child ){ unflatten( array, child ) } );
52                         }
53
54                         return tree;
55                 }
56 app.service('HeaderService', function ($http,$log, $q,UserInfoService) {
57         return{
58         
59                 getUserNameFromSession : function(){
60                         UserInfoService.getFunctionalMenuStaticDetailSession()
61                         .then(function (res) {
62                                         $scope.userName = res.userName;
63                                         $scope.redirectUrl = res.portalUrl;
64                         });
65             },
66                 getTopMenuStaticInfo:function() {
67                         var promise = UserInfoService.getFunctionalMenuStaticDetailShareContext();
68                         promise.then(
69                                         function(res) {                                         
70                                                 if(res==null || res==''){
71                                                         $log.info('failed getting static User information');    
72                                                         this.getUserNameFromSession();
73                                                 }else{
74                                                         $log.info('Received static User information');
75                                                         var resData = res;                                              
76                                                         $scope.inputUserInfo(resData);                                  
77                                                         $scope.userProfile.fullName = $scope.userProfile.firstName+ ' '+ $scope.userProfile.lastName;
78                                                         return $scope.userProfile;                              
79                                                 }
80                                         },
81                                         function(err) {
82                                                 $log.info('failed getting static User information');                                    
83                                         }
84                         );
85                         }
86                 }       
87         }
88 );
89