2 * ================================================================================
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
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 * ================================================================================
20 app.directive('qHeader', function () {
22 restrict: 'A', //This menas that it will be used as an attribute and NOT as an element. I don't like creating custom HTML elements
24 templateUrl: "app/fusion/scripts/view-models/header.html",
25 controller: ['$scope', '$filter','$http','$timeout', '$log','UserInfoService', '$window', '$cookies', function ($scope, $filter, $http, $timeout, $log,UserInfoService, $window, $cookies) {
35 $scope.menuItems = [];
36 $scope.loadMenufail=false;
37 $scope.megaMenuDataObject=[];
38 $scope.activeClickSubMenu = {
41 $scope.activeClickMenu = {
44 $scope.favoritesMenuItems = [];
45 $scope.favoriteItemsCount = 0;
46 $scope.showFavorites = false;
47 $scope.emptyFavorites = false;
48 $scope.favoritesWindow = false;
51 var menuStructureConvert = function(menuItems) {
52 console.log(menuItems);
53 $scope.megaMenuDataObjectTemp =
64 url:$scope.contactUsUrl
68 url:$scope.getAccessUrl
72 return $scope.megaMenuDataObjectTemp;
75 /***************functions**************/
76 /*Put user info into fields*/
77 $scope.inputUserInfo = function(userInfo){
78 if (typeof(userInfo) != "undefined" && userInfo!=null && userInfo!=''){
79 if(typeof(userInfo.USER_FIRST_NAME) != "undefined" && userInfo.USER_FIRST_NAME!=null){
80 $scope.userFirstName = userInfo.USER_FIRST_NAME;
84 /*getting user info from session*/
85 $scope.getUserNameFromSession = function(){
86 UserInfoService.getFunctionalMenuStaticDetailSession()
87 .then(function (res) {
88 $scope.contactUsUrl=res.contactUsLink;
89 $scope.userName = res.userName;
90 $scope.userFirstName = res.firstName;
91 $scope.redirectUrl = res.portalUrl;
92 $scope.getAccessUrl = res.getAccessUrl;
95 $scope.getTopMenuStaticInfo=function() {
96 var promise = UserInfoService.getFunctionalMenuStaticDetailShareContext();
99 if(res==null || res==''){
100 $log.info('failed getting static User information');
101 $scope.getUserNameFromSession();
103 $log.info('Received static User information');
106 console.log(resData);
107 $scope.inputUserInfo(resData);
108 $scope.userName = $scope.firstName+ ' '+ $scope.lastName;
112 $log.info('failed getting static User information');
117 $scope.returnToPortal=function(){
118 window.location.href = $scope.redirectUrl;
121 var unflatten = function( array, parent, tree ){
122 tree = typeof tree !== 'undefined' ? tree : [];
123 parent = typeof parent !== 'undefined' ? parent : { menuId: null };
124 var children = _.filter( array, function(child){ return child.parentMenuId == parent.menuId; });
125 if( !_.isEmpty( children ) ){
126 if( parent.menuId === null ){
129 parent['children'] = children
131 _.each( children, function( child ){ unflatten( array, child ) } );
136 $scope.getMenu=function() {
137 $scope.getTopMenuStaticInfo();
140 url: 'get_functional_menu',
141 // TIMEOUT USED FOR LOCAL TESTING ONLY
143 }).success(function (response) {
145 if (response == '101: Timeout') {
146 $log.debug('Timeout attempting to get_functional_menu');
147 $scope.megaMenuDataObject = menuStructureConvert("");
148 // $scope.createErrorMenu();
149 //$scope.loadMenufail=true;
151 if(typeof response != 'undefined' && response.length!=0 && typeof response[0] != 'undefined' && typeof response[0].error!="undefined"){
152 $log.debug('Timeout attempting to get_functional_menu');
153 $scope.menuItems = unflatten( response);
154 $scope.megaMenuDataObject = menuStructureConvert($scope.menuItems);
155 // $scope.createErrorMenu();
156 //$scope.loadMenufail=true;
158 $scope.loadMenufail=false;
159 $scope.contactUsURL = response.contactUsLink;
160 $log.debug('functional_menu',response);
161 $scope.megaMenuDataObject = menuStructureConvert("");
164 }).error(function (response){
165 $scope.megaMenuDataObject = menuStructureConvert("");
166 // $scope.createErrorMenu();
167 //$scope.loadMenufail=true;
168 $log.debug('REST API failed get_functional_menu...');
173 $scope.adjustHeader=function() {
174 $scope.showHeader = ($cookies.show_app_header == undefined ? true : $cookies.show_app_header);
176 if($scope.showHeader == true) {
177 $scope.drawer_margin_top = 70;
178 $scope.drawer_custom_top = 54;
179 $scope.toggle_drawer_top = 55;
183 $scope.drawer_margin_top = 60;
184 $scope.drawer_custom_top = 0;
185 $scope.toggle_drawer_top = 10;
191 $scope.adjustHeader();
193 /* **************************************************************************/
194 /* Logic for the favorite menus is here */
196 $scope.loadFavorites = function () {
197 $log.debug('loadFavorites has happened.');
198 if ($scope.favoritesMenuItems == '') {
199 $scope.generateFavoriteItems();
200 $log.debug('loadFavorites is calling generateFavoriteItems()');
202 $log.debug('loadFavorites is NOT calling generateFavoriteItems()');
206 $scope.goToUrl = function (item) {
207 $log.info("goToUrl called")
211 var restrictedApp = item.restrictedApp;
212 $log.debug('Restricted app status is: ' + restrictedApp);
214 $log.info('No url found for this application, doing nothing..');
218 $window.open(url, '_blank');
220 $window.open(url, '_self');
225 $scope.submenuLevelAction = function(index, column) {
226 if ($scope.favoritesMenuItems == '') {
227 $scope.generateFavoriteItems();
228 $log.debug('submenuLevelAction is calling generateFavoriteItems()');
230 $log.debug('item hovered/clicked: ' + index + '; column = ' + column);
231 if (column == 2) { // 2 is Design
232 $scope.favoritesWindow = false;
233 $scope.showFavorites = false;
234 $scope.emptyFavorites = false;
236 if (index=='Favorites' && $scope.favoriteItemsCount != 0) {
237 $log.debug('Showing Favorites window');
238 $scope.favoritesWindow = true;
239 $scope.showFavorites = true;
240 $scope.emptyFavorites = false;
242 if (index=='Favorites' && $scope.favoriteItemsCount == 0) {
243 $log.debug('Hiding Favorites window in favor of No Favorites Window');
244 $scope.favoritesWindow = true;
245 $scope.showFavorites = false;
246 $scope.emptyFavorites = true;
249 $scope.favoritesWindow = false;
250 $scope.showFavorites = false;
251 $scope.emptyFavorites = false;
255 $scope.hideFavoritesWindow = function() {
256 $log.debug('$scope.hideFavoritesWindow has been called');
257 $scope.showFavorites = false;
258 $scope.emptyFavorites = false;
261 $scope.isUrlFavorite = function (menuId) {
262 // $log.debug('array objects in menu favorites = ' + $scope.favoriteItemsCount + '; menuId=' + menuId);
263 var jsonMenu = JSON.stringify($scope.favoritesMenuItems);
264 var isMenuFavorite = jsonMenu.indexOf('menuId\":' + menuId);
265 if (isMenuFavorite==-1) {
273 $scope.generateFavoriteItems = function() {
276 url: 'get_favorites',
277 // TIMEOUT USED FOR LOCAL TESTING ONLY
279 }).success(function (response) {
280 if (response == '101: Timeout') {
281 $log.error('Timeout attempting to get_favorites_menu');
283 if(typeof response != 'undefined' && response.length!=0 && typeof response[0] != 'undefined' && typeof response[0].error!="undefined"){
284 $log.error('REST API failed get_favorites' + response);
286 $log.debug('get_favorites = ' + JSON.stringify(response));
287 $scope.favoritesMenuItems = response;
288 $scope.favoriteItemsCount = Object.keys($scope.favoritesMenuItems).length;
289 $log.info('number of favorite menus: ' + $scope.favoriteItemsCount);
292 }).error(function (response){
293 $log.error('REST API failed get_favorites' + response);
294 //createFavoriteErrorMenu() USED FOR LOCAL TESTING ONLY
295 // $scope.createFavoriteErrorMenu();
299 $scope.createFavoriteErrorMenu=function() {
300 $scope.favoritesMenuItems = [];
301 $scope.favoriteItemsCount = Object.keys($scope.favoritesMenuItems).length;
302 $log.info('number of favorite menus: ' + $scope.favoriteItemsCount);
305 /* end of Favorite Menu code */
306 /* **************************************************************************/
309 /* **************************************************************************/
310 // THIS IS USED FOR LOCAL TESTING ONLY
311 /* **************************************************************************/
312 $scope.createErrorMenu=function() {
313 $log.debug('Creating fake menu now...');
314 // $scope.loadMenufail=true;
320 "parentMenuId": null,
326 "text": "Infrastructure Ordering",
327 "parentMenuId": null,
333 "text": "Service Creation",
334 "parentMenuId": null,
340 "text": "Service Mgmt",
341 "parentMenuId": null,
354 "text": "Mike Little's Coffee Cup",
361 "text": "Andy and his Astrophotgraphy",
382 "text": "4th Level App4a R16",
389 "text": "3rd Level App1c R200",
396 "text": "3rd Level App4b R16",
403 "text": "3rd Level App2b R16",
411 "parentMenuId": null,
415 $scope.menuItems = unflatten( $scope.menuItems );
417 $scope.megaMenuDataObject = menuStructureConvert($scope.menuItems);
423 app.filter("ellipsis", function(){
424 return function(text, length){
426 var ellipsis = text.length > length ? "..." : "";
427 return text.slice(0, length) + ellipsis;
433 function reloadPageOnce() {
434 if( window.localStorage )
436 if( !localStorage.getItem('firstLoad') )
438 localStorage['firstLoad'] = true;
439 window.location.reload();
442 localStorage.removeItem('firstLoad');
445 app.controller('loginSnippetCtrl', function ($scope,$http, $log,UserInfoService){
454 /*Put user info into fields*/
455 $scope.inputUserInfo = function(userInfo){
456 if (typeof(userInfo) != "undefined" && userInfo!=null && userInfo!=''){
457 if (typeof(userInfo.USER_FIRST_NAME) != "undefined" && userInfo.USER_FIRST_NAME!=null && userInfo.USER_FIRST_NAME!='')
458 $scope.userProfile.firstName = userInfo.USER_FIRST_NAME;
459 if (typeof(userInfo.USER_LAST_NAME) != "undefined" && userInfo.USER_LAST_NAME!=null && userInfo.USER_LAST_NAME!='')
460 $scope.userProfile.lastName = userInfo.USER_LAST_NAME;
461 if (typeof(userInfo.USER_EMAIL) != "undefined" && userInfo.USER_EMAIL!=null && userInfo.USER_EMAIL!='')
462 $scope.userProfile.email = userInfo.USER_EMAIL;
463 if (typeof(userInfo.USER_ORGUSERID) != "undefined" && userInfo.USER_ORGUSERID!=null && userInfo.USER_ORGUSERID!='')
464 $scope.userProfile.userid = userInfo.USER_ORGUSERID;
467 /*getting user info from session*/
468 $scope.getUserNameFromSession = function(){
469 UserInfoService.getFunctionalMenuStaticDetailSession()
470 .then(function (response) {
471 $scope.userProfile.fullName = response.userName;
472 $scope.userProfile.userid = response.userid;
473 $scope.userProfile.email = response.email;
476 /*getting user info from shared context*/
477 $scope.getUserName=function() {
478 var promise = UserInfoService.getFunctionalMenuStaticDetailShareContext();
481 if(res==null || res==''){
482 $log.info('Getting User information from session');
483 $scope.getUserNameFromSession();
486 $log.info('Received User information from shared context',res);
488 console.log(resData);
489 $scope.inputUserInfo(resData);
490 $scope.userProfile.fullName = $scope.userProfile.firstName+ ' '+ $scope.userProfile.lastName;
494 console.log('error');
498 /*call the get user info function*/
500 $scope.getUserName();
502 $log.info('Error while getting User information',err);