[PORTAL-16 PORTAL-18] Widget ms; staging
[portal.git] / ecomp-portal-FE-common / client / app / views / header / header.controller.js
index 961362a..33cb845 100644 (file)
-/*-\r
- * ================================================================================\r
- * ECOMP Portal\r
- * ================================================================================\r
- * Copyright (C) 2017 AT&T Intellectual Property\r
- * ================================================================================\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- *      http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * ================================================================================\r
- */\r
-'use strict';\r
-(function () {\r
-       class HeaderCtrl {\r
-        constructor($log, $window, userProfileService, menusService, $scope, ECOMP_URL_REGEX, $cookies, $state,auditLogService,notificationService) {\r
-            this.firstName = '';\r
-            this.lastName = '';\r
-            this.$log = $log;\r
-            this.menusService = menusService;\r
-            this.$scope = $scope;\r
-            this.favoritesMenuItems = '';\r
-            $scope.favoriteItemsCount = 0;\r
-            $scope.favoritesMenuItems = '';\r
-            $scope.showFavorites = false;\r
-            $scope.emptyFavorites = false;\r
-            $scope.favoritesWindow = false;\r
-            $scope.notificationCount=0;\r
-            $scope.showNotification = true;\r
-\r
-            $scope.hideMenus = false;\r
-\r
-            $scope.menuItems = [];\r
-            $scope.activeClickSubMenu = {\r
-                x: ''\r
-            }; \r
-            $scope.activeClickMenu = {\r
-                x: ''\r
-            };\r
-            $scope.megaMenuDataObject =[];\r
-            $scope.notificationCount= notificationService.notificationCount;\r
-            this.isLoading = true;\r
-            this.ECOMP_URL_REGEX = ECOMP_URL_REGEX;\r
-            \r
-            var unflatten = function( array, parent, tree ){\r
-            \r
-                tree = typeof tree !== 'undefined' ? tree : [];\r
-                parent = typeof parent !== 'undefined' ? parent : { menuId: null };\r
-                var children = _.filter( array, function(child){ return child.parentMenuId == parent.menuId; });\r
-                \r
-                if( !_.isEmpty( children )  ){\r
-                  if( parent.menuId === null ){\r
-                    tree = children;\r
-                  }else{\r
-                    parent['children'] = children\r
-                  }\r
-                  _.each( children, function( child ){ unflatten( array, child ) } );\r
-                }\r
-            \r
-                return tree;\r
-            }\r
-            \r
-            userProfileService.getFunctionalMenuStaticInfo()\r
-            .then(res=> {\r
-               // $log.debug('HeaderCtrl::getFunctionalMenuStaticInfo: getting Functional Menu Static Info init');\r
-               if(res==null || res.firstName==null || res.firstName=='' || res.lastName==null || res.lastName=='' ){\r
-                       // $log.info('HeaderCtrl::getFunctionalMenuStaticInfo: failed getting userinfo from shared context.. ');\r
-                       $log.info('HeaderCtrl: failed to get all required data, trying user profile');\r
-                       userProfileService.getUserProfile()\r
-                    .then(profile=> {\r
-                       // $log.debug('HeaderCtrl:: getting userinfo from session success');\r
-                        this.firstName = profile.firstName;\r
-                        this.lastName = profile.lastName;                     \r
-                        // $log.debug('HeaderCtrl::getFunctionalMenuStaticInfo: user has the following roles: ' + profile.roles);\r
-                    }).catch(err=> {\r
-                        $log.error('Header Controller:: getUserProfile() failed: ' + err);\r
-                    });\r
-               } else {\r
-                       // $log.debug('HeaderCtrl: fetched Functional Menu Static Info successfully',res);\r
-                       this.firstName = res.firstName;\r
-                       this.lastName = res.lastName;                                     \r
-               }\r
-\r
-               menusService.GetFunctionalMenuForUser()\r
-               .then(jsonHeaderMenu=> {\r
-                       $scope.menuItems = unflatten( jsonHeaderMenu );\r
-                       $scope.megaMenuDataObject = $scope.menuItems;\r
-               }).catch(err=> {\r
-                       $log.error('HeaderCtrl::GetFunctionalMenuForUser: HeaderCtrl json returned: ' + err);\r
-               });      \r
-               \r
-            }).catch(err=> {\r
-               $log.error('HeaderCtrl::getFunctionalMenuStaticInfo failed: ' + err);\r
-            });\r
-            \r
-          //store audit log\r
-            $scope.auditLog = function(app,type) {\r
-               var comment = 'type: '+type+ ',title: '+app.text+",url: "+app.url;\r
-                       auditLogService.storeAudit(app.appid,'functional',comment);\r
-               };\r
-\r
-            $scope.loadFavorites = function () {\r
-                $scope.hideMenus = false;\r
-                // $log.debug('HeaderCtrl::loadFavorites: loadFavorites has happened.');\r
-                if ($scope.favoritesMenuItems == '') {\r
-                    generateFavoriteItems();\r
-                    // $log.debug('HeaderCtrl::loadFavorites: loadFavorites is calling generateFavoriteItems()');\r
-                } else {\r
-                    // $log.debug('HeaderCtrl::loadFavorites: loadFavorites is NOT calling generateFavoriteItems()');\r
-                }\r
-            }\r
-\r
-            $scope.goToUrl = (item) =>  {\r
-               //  $log.error('HeaderCtrl::goToUrl has started',item);\r
-                let url = item.url;\r
-                let restrictedApp = item.restrictedApp;\r
-                if (!url) {\r
-                    $log.warn('HeaderCtrl::goToUrl: No url found for this application, doing nothing..');\r
-                    return;\r
-                }\r
-                if (restrictedApp) {\r
-                    $window.open(url, '_blank');\r
-                } else {\r
-                       if(item.url=="getAccess" || item.url=="contactUs"){\r
-                           // if (url = window.location.href)\r
-                               $state.go("root."+url);\r
-                       } else {\r
-                       var tabContent = { id: new Date(), title: item.text, url: item.url,appId:item.appid };\r
-                       $cookies.putObject('addTab', tabContent );\r
-                    }\r
-                    // $log.debug('HeaderCtrl::goToUrl: url = ', url);\r
-                }\r
-                $scope.hideMenus = true;\r
-            }\r
-            \r
-            \r
-            \r
-            $scope.submenuLevelAction = function(index, column) {\r
-                if ($scope.favoritesMenuItems == '') {\r
-                    generateFavoriteItems();\r
-                    // $log.debug('HeaderCtrl::submenuLevelAction: submenuLevelAction is calling generateFavoriteItems()');\r
-                } else {\r
-                    // $log.debug('submenuLevelAction is NOT calling generateFavoriteItems()');\r
-                }\r
-                // $log.debug('item hovered: ' + index + '; column = ' + column);\r
-                // if (column == 2) {  // 2 is Design\r
-                //     // This is an admitted hack. See aw3218 for reasons why\r
-                //     $log.debug('submenuLevelAction column == 2');\r
-                //     $scope.favoritesWindow = false;\r
-                //     $scope.showFavorites = false;\r
-                //     $scope.emptyFavorites = false;\r
-                // }\r
-                if (index=='Favorites' && $scope.favoriteItemsCount != 0) {\r
-                    // $log.debug('HeaderCtrl::submenuLevelAction: Showing Favorites window');\r
-                    // generateFavoriteItems();\r
-                    $scope.favoritesWindow = true;\r
-                    $scope.showFavorites = true;\r
-                    $scope.emptyFavorites = false;\r
-                }\r
-                if (index=='Favorites' && $scope.favoriteItemsCount == 0) {\r
-                    // $log.debug('HeaderCtrl::submenuLevelAction: Hiding Favorites window in favor of No Favorites Window');\r
-                    // generateFavoriteItems();\r
-                    $scope.favoritesWindow = true;\r
-                    $scope.showFavorites = false;\r
-                    $scope.emptyFavorites = true;\r
-                }\r
-                if (index!='Favorites' ) {\r
-                    $scope.favoritesWindow = false;\r
-                    $scope.showFavorites = false;\r
-                    $scope.emptyFavorites = false;\r
-                }\r
-\r
-            };\r
-            \r
-            $scope.hideFavoritesWindow = function() {\r
-                $scope.showFavorites = false;\r
-                $scope.emptyFavorites = false;\r
-                // $scope.thirdFourthMenus = true;\r
-            }\r
-            \r
-            $scope.isUrlFavorite = function (menuId) {\r
-                // $log.debug('array objects in menu favorites = ' + $scope.favoriteItemsCount + '; menuId=' + menuId);\r
-                var jsonMenu =  JSON.stringify($scope.favoritesMenuItems);\r
-                var isMenuFavorite =  jsonMenu.indexOf('menuId\":' + menuId);\r
-                // $log.debug('jsonMenu.indexOf(menuId:' + jsonMenu.indexOf('menuId\":'+menuId));\r
-                // $log.debug('isMenuFavorite= ' + isMenuFavorite);\r
-                if (isMenuFavorite==-1) {\r
-                    return false;\r
-                } else {\r
-                    return true;\r
-                }\r
-\r
-            }\r
-            \r
-            let generateFavoriteItems  = () => {\r
-                menusService.getFavoriteItems()\r
-                    .then(favorites=> {\r
-                        // $log.debug('HeaderCtrl.getFavoriteItems:: ' + JSON.stringify(favorites));\r
-                        $scope.favoritesMenuItems = favorites;\r
-                        $scope.favoriteItemsCount = Object.keys(favorites).length;\r
-                        // $log.info('HeaderCtrl.getFavoriteItems:: number of favorite menus: ' + $scope.favoriteItemsCount);\r
-                    }).catch(err=> {\r
-                        $log.error('HeaderCtrl.getFavoriteItems:: Error retrieving Favorites menus: ' + err);\r
-                });\r
-            }\r
-\r
-           $scope.setAsFavoriteItem =  function(event, menuId){\r
-               var jsonMenuID = angular.toJson({'menuId': + menuId });\r
-               // $log.debug('HeaderCtrl::setFavoriteItems: ' + jsonMenuID  + " - " +  event.target.id);\r
-\r
-               menusService.setFavoriteItem(jsonMenuID)\r
-               .then(() => {\r
-                   // var elementId = '#'+ event.currentTarget.id;\r
-                   angular.element('#' + event.target.id).css('color', '#fbb313');\r
-                   generateFavoriteItems();\r
-               }).catch(err=> {\r
-                   $log.error('HeaderCtrl::setFavoriteItems:: API setFavoriteItem error: ' + err);\r
-               });\r
-           };\r
-\r
-            $scope.removeAsFavoriteItem =  function(event, menuId){\r
-                // $log.debug('-----------------------------removeAsFavoriteItem: ' + menuId + " - " +  event.target.id);\r
-                menusService.removeFavoriteItem(menuId)\r
-                .then(() => {\r
-                    angular.element('#' + event.target.id).css('color', '#666666');\r
-                    generateFavoriteItems();\r
-                }).catch(err=> {\r
-                    $log.error('HeaderCtrl::removeAsFavoriteItem: API removeFavoriteItem error: ' + err);\r
-                });\r
-            };\r
-\r
-            $scope.goToPortal = (headerText, url) => {\r
-                if (!url) {\r
-                    $log.warn('HeaderCtrl::goToPortal: No url found for this application, doing nothing..');\r
-                    return;\r
-                }\r
-                if (!ECOMP_URL_REGEX.test(url)) {\r
-                    url = 'http://' + url;\r
-                }\r
-\r
-                if(headerText.startsWith("vUSP")) {\r
-                       window.open(url, '_blank');//, '_self'\r
-                }\r
-                else {\r
-                       var tabContent = { id: new Date(), title: headerText, url: url };\r
-                       $cookies.putObject('addTab', tabContent );\r
-                }\r
-            };\r
-\r
-        }\r
-    }\r
-    class LoginSnippetCtrl {\r
-        constructor($log, $scope, $cookies, $timeout, userProfileService, sessionService) {\r
-            $scope.firstName="";\r
-            $scope.lastName="";\r
-            $scope.displayUserAppRoles=false; \r
-            $scope.allAppsLogout = function(){\r
-               \r
-               var cookieTabs = $cookies.getObject('visInVisCookieTabs');\r
-               if(cookieTabs!=null){\r
-                       for(var t in cookieTabs){\r
-                       \r
-                               var url = cookieTabs[t].content;\r
-                               if(url != "") {\r
-                                       sessionService.logout(url);\r
-                       }\r
-                       }\r
-               }\r
-               // wait for individual applications to log out before the portal logout\r
-               $timeout(function() {\r
-                       window.location = "logout.htm";\r
-               }, 2000);\r
-            }\r
-            \r
-            \r
-            try {\r
-               userProfileService.getFunctionalMenuStaticInfo()\r
-                .then(res=> {\r
-                 // $log.info('HeaderCtrl::LoginSnippetCtrl: Login information: ' + JSON.stringify(res));\r
-                 $scope.firstName = res.firstName;\r
-                 $scope.lastName = res.lastName;\r
-                 $scope.loginSnippetEmail = res.email;\r
-                 $scope.loginSnippetUserid = res.userId;\r
-                 $scope.lastLogin = res.last_login;\r
-                }).catch(err=> {\r
-                 $log.error('HeaderCtrl::LoginSnippetCtrl: failed in getFunctionalMenuStaticInfo: ' + err);\r
-                });\r
-            } catch (err) {\r
-                $log.error('HeaderCtrl::LoginSnippetCtrl caught exception: ' + err);\r
-            }\r
-            \r
-            $scope.getUserApplicationRoles= function(){\r
-                 $scope.userapproles = [];\r
-                 if($scope.displayUserAppRoles)\r
-                               $scope.displayUserAppRoles = false;\r
-                                else\r
-                                       $scope.displayUserAppRoles = true;\r
-                 \r
-                       userProfileService.getUserAppRoles($scope.loginSnippetUserid)\r
-                         .then(res=>{\r
-                               \r
-                        for(var i=0;i<res.length;i++){                                 \r
-                       var userapprole ={\r
-                               App:res[i].appName,\r
-                               Roles:res[i].roleNames, \r
-                       };\r
-                       \r
-                       $scope.userapproles.push(userapprole); \r
-                       }\r
-                        \r
-               });\r
-               \r
-          }\r
-        }        \r
-    }\r
-    class NotificationCtrl{\r
-       constructor($log, $scope, $cookies, $timeout, sessionService,notificationService,$interval,ngDialog) {\r
-                $scope.notifications=[];   \r
-                var intervalPromise = null;\r
-             $scope.notificationCount= notificationService.notificationCount;\r
-             \r
-             $scope.getNotification = function(){               \r
-                notificationService.getNotification()\r
-                 .then(res=> {\r
-                       notificationService.decrementRefreshCount();\r
-                       var count = notificationService.getRefreshCount();\r
-                       if (res==null || res.data==null || res.data.message!='success') {\r
-                               $log.error('NotificationCtrl::updateNotifications: failed to get notifications');\r
-                               if (intervalPromise != null)\r
-                                       $interval.cancel(intervalPromise);\r
-                       } else if(count<=0){\r
-                               if (intervalPromise != null)\r
-                                       $interval.cancel(intervalPromise);\r
-                       } else {\r
-                               $scope.notifications = [];\r
-                               notificationService.setNotificationCount(res.data.response.length);\r
-                               for(var i=0;i<res.data.response.length;i++){\r
-                                       var data = res.data.response[i];                                        \r
-                                       var notification ={\r
-                                               id:data.notificationId,\r
-                                               title:data.msgHeader,\r
-                                               message:data.msgDescription,\r
-                                               source:data.msgSource,\r
-                                               time:data.createdDate,\r
-                                               priority:data.priority\r
-                                       };\r
-                                       $scope.notifications.push(notification);       \r
-                                    }  \r
-                       }       \r
-                 }).catch(err=> {\r
-                       $log.error('NotificationCtrl::getNotification: caught exception: ' + err);\r
-                       if (intervalPromise != null)\r
-                               $interval.cancel(intervalPromise);\r
-                 });      \r
-             }\r
-             $scope.getNotification();\r
-             function updateNotifications() {\r
-                $scope.getNotification();\r
-             }\r
-             $scope.start = function(rate) {\r
-                               // stops any running interval to avoid two intervals running at the same time\r
-                               $scope.stop();  \r
-                               // store the interval promise\r
-                               intervalPromise = $interval(updateNotifications, rate);\r
-                        };\r
-\r
-                        $scope.stop = function() {\r
-                               $interval.cancel(intervalPromise);\r
-                        };\r
-                        \r
-                       \r
-                        $scope.showDetailedJsonMessage=function (selectedAdminNotification) {\r
-                               if (selectedAdminNotification.source!=='EP'){\r
-                                var messageObject=JSON.parse(selectedAdminNotification.message);\r
-                                var html="";\r
-                                html+='<p>'+'Message Source'+' : '+selectedAdminNotification.source+'</p>';\r
-                                html+='<p>'+'Message Title'+' : '+selectedAdminNotification.title+'</p>';\r
-                                for(var field in  messageObject){\r
-                                        if(field=='eventDate'||field=='lastModifiedDate'){\r
-                                                html+='<p>'+field+' : '+new Date(+messageObject[field])+'</p>';\r
-                                                 \r
-                                        }else{\r
-                                        html+='<p>'+field+' : '+messageObject[field]+'</p>';\r
-                                        \r
-                                        }\r
-                                }\r
-                       \r
-                    var modalInstance = ngDialog.open({\r
-                                   templateUrl: 'app/views/user-notifications-admin/user.notifications.Json.details.modal.page.html',\r
-                                   controller: 'userNotificationCtrl',\r
-                                   resolve: {\r
-                                       message: function () {\r
-                                               var message = {\r
-                                                          title:    '',\r
-                                               text:    html\r
-                                               \r
-                                               };\r
-                                         return message;\r
-                                       },\r
-                                    \r
-                                     }\r
-                                 }); \r
-                       \r
-                               } \r
-                        };\r
-                        \r
-                       notificationService.getNotificationRate().then(res=> {\r
-               if (res == null || res.response == null) {\r
-                       $log.error('NotificationCtrl: failed to notification update rate or duration, check system.properties file.');\r
-               } else {\r
-                       var rate = parseInt(res.response.updateRate);\r
-                                       var duration = parseInt(res.response.updateDuration);\r
-                                       notificationService.setMaxRefreshCount(parseInt(duration/rate)+1);\r
-                                       notificationService.setRefreshCount(notificationService.maxCount);\r
-                               if (rate != NaN && duration != NaN) {\r
-                                               $scope.updateRate=rate;\r
-                                               $scope.start($scope.updateRate);\r
-                               }                               \r
-               }\r
-            }).catch(err=> {\r
-               $log.error('NotificationCtrl: getNotificationRate() failed: ' + err);\r
-            });\r
-             \r
-             $scope.deleteNotification = function(index){\r
-                if ($scope.notifications[index].id == null || $scope.notifications[index].id == '') {\r
-                       $log.error('NotificationCtrl: failed to delete Notification.');\r
-                       return;\r
-                }\r
-                notificationService.setNotificationRead($scope.notifications[index].id);\r
-                $scope.notifications.splice(index,1);\r
-                notificationService.setNotificationCount($scope.notifications.length);          \r
-             }\r
-       }\r
-    }\r
-    NotificationCtrl.$inject = ['$log', '$scope', '$cookies', '$timeout', 'sessionService','notificationService','$interval','ngDialog'];\r
-    LoginSnippetCtrl.$inject = ['$log', '$scope', '$cookies', '$timeout','userProfileService', 'sessionService'];\r
-    HeaderCtrl.$inject = ['$log', '$window', 'userProfileService', 'menusService', '$scope', 'ECOMP_URL_REGEX','$cookies','$state','auditLogService','notificationService'];\r
-    angular.module('ecompApp').controller('HeaderCtrl', HeaderCtrl);\r
-    angular.module('ecompApp').controller('loginSnippetCtrl', LoginSnippetCtrl);\r
-    angular.module('ecompApp').controller('notificationCtrl', NotificationCtrl);\r
-\r
-})();\r
+/*-
+ * ================================================================================
+ * ECOMP Portal
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ================================================================================
+ */
+'use strict';
+(function () {
+       class HeaderCtrl {
+        constructor($log, $window, userProfileService, menusService, $scope, ECOMP_URL_REGEX, $cookies, $state,auditLogService,notificationService,recommendationService,ngDialog) {
+            this.firstName = '';
+            this.lastName = '';
+            this.$log = $log;
+            this.menusService = menusService;
+            this.$scope = $scope;
+            this.favoritesMenuItems = '';
+            $scope.favoriteItemsCount = 0;
+            $scope.favoritesMenuItems = '';
+            $scope.showFavorites = false;
+            $scope.emptyFavorites = false;
+            $scope.favoritesWindow = false;
+            $scope.notificationCount=0;
+            $scope.recommendationCount=0;
+            $scope.showNotification = true;
+
+            $scope.hideMenus = false;
+
+            $scope.menuItems = [];
+            $scope.activeClickSubMenu = {
+                x: ''
+            }; 
+            $scope.activeClickMenu = {
+                x: ''
+            };
+            $scope.megaMenuDataObject =[];
+            $scope.notificationCount= notificationService.notificationCount;
+            $scope.recommendationCount= recommendationService.recommendationCount;
+            this.isLoading = true;
+            this.ECOMP_URL_REGEX = ECOMP_URL_REGEX;
+            
+            var unflatten = function( array, parent, tree ){
+            
+                tree = typeof tree !== 'undefined' ? tree : [];
+                parent = typeof parent !== 'undefined' ? parent : { menuId: null };
+                var children = _.filter( array, function(child){ return child.parentMenuId == parent.menuId; });
+                
+                if( !_.isEmpty( children )  ){
+                  if( parent.menuId === null ){
+                    tree = children;
+                  }else{
+                    parent['children'] = children
+                  }
+                  _.each( children, function( child ){ unflatten( array, child ) } );
+                }
+            
+                return tree;
+            }
+            
+            userProfileService.getFunctionalMenuStaticInfo()
+            .then(res=> {
+               // $log.debug('HeaderCtrl::getFunctionalMenuStaticInfo: getting Functional Menu Static Info init');
+               if(res==null || res.firstName==null || res.firstName=='' || res.lastName==null || res.lastName=='' ){
+                       // $log.info('HeaderCtrl::getFunctionalMenuStaticInfo: failed getting userinfo from shared context.. ');
+                       $log.info('HeaderCtrl: failed to get all required data, trying user profile');
+                       userProfileService.getUserProfile()
+                    .then(profile=> {
+                       // $log.debug('HeaderCtrl:: getting userinfo from session success');
+                        this.firstName = profile.firstName;
+                        this.lastName = profile.lastName;                     
+                        // $log.debug('HeaderCtrl::getFunctionalMenuStaticInfo: user has the following roles: ' + profile.roles);
+                    }).catch(err=> {
+                        $log.error('Header Controller:: getUserProfile() failed: ' + err);
+                    });
+               } else {
+                       // $log.debug('HeaderCtrl: fetched Functional Menu Static Info successfully',res);
+                       this.firstName = res.firstName;
+                       this.lastName = res.lastName;                                     
+               }
+
+               menusService.GetFunctionalMenuForUser()
+               .then(jsonHeaderMenu=> {
+                       $scope.menuItems = unflatten( jsonHeaderMenu );
+                       $scope.megaMenuDataObject = $scope.menuItems;
+               }).catch(err=> {
+                       $log.error('HeaderCtrl::GetFunctionalMenuForUser: HeaderCtrl json returned: ' + err);
+               });      
+               
+            }).catch(err=> {
+               $log.error('HeaderCtrl::getFunctionalMenuStaticInfo failed: ' + err);
+            });
+            
+          //store audit log
+            $scope.auditLog = function(app,type) {
+               var comment = 'type: '+type+ ',title: '+app.text+",url: "+app.url;
+                       auditLogService.storeAudit(app.appid,'functional',comment);
+               };
+
+            $scope.loadFavorites = function () {
+                $scope.hideMenus = false;
+                // $log.debug('HeaderCtrl::loadFavorites: loadFavorites has happened.');
+                if ($scope.favoritesMenuItems == '') {
+                    generateFavoriteItems();
+                    // $log.debug('HeaderCtrl::loadFavorites: loadFavorites is calling generateFavoriteItems()');
+                } else {
+                    // $log.debug('HeaderCtrl::loadFavorites: loadFavorites is NOT calling generateFavoriteItems()');
+                }
+            }
+
+            $scope.goToUrl = (item) =>  {
+               //  $log.error('HeaderCtrl::goToUrl has started',item);
+                let url = item.url;
+                let restrictedApp = item.restrictedApp;
+                if (!url) {
+                    $log.warn('HeaderCtrl::goToUrl: No url found for this application, doing nothing..');
+                    return;
+                }
+                if (restrictedApp) {
+                    $window.open(url, '_blank');
+                } else {
+                       if(item.url=="getAccess" || item.url=="contactUs"){
+                           // if (url = window.location.href)
+                               $state.go("root."+url);
+                       } else {
+                       var tabContent = { id: new Date(), title: item.text, url: item.url,appId:item.appid };
+                       $cookies.putObject('addTab', tabContent );
+                    }
+                    // $log.debug('HeaderCtrl::goToUrl: url = ', url);
+                }
+                $scope.hideMenus = true;
+            }
+            
+            
+            
+            $scope.submenuLevelAction = function(index, column) {
+                if ($scope.favoritesMenuItems == '') {
+                    generateFavoriteItems();
+                    // $log.debug('HeaderCtrl::submenuLevelAction: submenuLevelAction is calling generateFavoriteItems()');
+                } else {
+                    // $log.debug('submenuLevelAction is NOT calling generateFavoriteItems()');
+                }
+                // $log.debug('item hovered: ' + index + '; column = ' + column);
+                // if (column == 2) {  // 2 is Design
+                //     // This is an admitted hack. See aw3218 for reasons why
+                //     $log.debug('submenuLevelAction column == 2');
+                //     $scope.favoritesWindow = false;
+                //     $scope.showFavorites = false;
+                //     $scope.emptyFavorites = false;
+                // }
+                if (index=='Favorites' && $scope.favoriteItemsCount != 0) {
+                    // $log.debug('HeaderCtrl::submenuLevelAction: Showing Favorites window');
+                    // generateFavoriteItems();
+                    $scope.favoritesWindow = true;
+                    $scope.showFavorites = true;
+                    $scope.emptyFavorites = false;
+                }
+                if (index=='Favorites' && $scope.favoriteItemsCount == 0) {
+                    // $log.debug('HeaderCtrl::submenuLevelAction: Hiding Favorites window in favor of No Favorites Window');
+                    // generateFavoriteItems();
+                    $scope.favoritesWindow = true;
+                    $scope.showFavorites = false;
+                    $scope.emptyFavorites = true;
+                }
+                if (index!='Favorites' ) {
+                    $scope.favoritesWindow = false;
+                    $scope.showFavorites = false;
+                    $scope.emptyFavorites = false;
+                }
+
+            };
+            
+            $scope.hideFavoritesWindow = function() {
+                $scope.showFavorites = false;
+                $scope.emptyFavorites = false;
+                // $scope.thirdFourthMenus = true;
+            }
+            
+            $scope.isUrlFavorite = function (menuId) {
+                // $log.debug('array objects in menu favorites = ' + $scope.favoriteItemsCount + '; menuId=' + menuId);
+                var jsonMenu =  JSON.stringify($scope.favoritesMenuItems);
+                var isMenuFavorite =  jsonMenu.indexOf('menuId\":' + menuId);
+                // $log.debug('jsonMenu.indexOf(menuId:' + jsonMenu.indexOf('menuId\":'+menuId));
+                // $log.debug('isMenuFavorite= ' + isMenuFavorite);
+                if (isMenuFavorite==-1) {
+                    return false;
+                } else {
+                    return true;
+                }
+
+            }
+            
+            /*Getting Ecomp portal Title*/
+
+            let getEcompPortalTitle  = () => {
+               menusService.getEcompPortalTitle()
+               .then(title=> {
+                       $scope.ecompTitle = title.response;
+               }).catch(err=> {
+                       $log.error('HeaderCtrl.getEcompPortalTitle:: Error retrieving ECMOP portal title: ' + err);
+               });
+            }
+            getEcompPortalTitle();
+            
+            let generateFavoriteItems  = () => {
+                menusService.getFavoriteItems()
+                    .then(favorites=> {
+                        // $log.debug('HeaderCtrl.getFavoriteItems:: ' + JSON.stringify(favorites));
+                        $scope.favoritesMenuItems = favorites;
+                        $scope.favoriteItemsCount = Object.keys(favorites).length;
+                        // $log.info('HeaderCtrl.getFavoriteItems:: number of favorite menus: ' + $scope.favoriteItemsCount);
+                    }).catch(err=> {
+                        $log.error('HeaderCtrl.getFavoriteItems:: Error retrieving Favorites menus: ' + err);
+                });
+            }
+
+           $scope.setAsFavoriteItem =  function(event, menuId){
+               var jsonMenuID = angular.toJson({'menuId': + menuId });
+               // $log.debug('HeaderCtrl::setFavoriteItems: ' + jsonMenuID  + " - " +  event.target.id);
+
+               menusService.setFavoriteItem(jsonMenuID)
+               .then(() => {
+                   // var elementId = '#'+ event.currentTarget.id;
+                   angular.element('#' + event.target.id).css('color', '#fbb313');
+                   generateFavoriteItems();
+               }).catch(err=> {
+                   $log.error('HeaderCtrl::setFavoriteItems:: API setFavoriteItem error: ' + err);
+               });
+           };
+
+            $scope.removeAsFavoriteItem =  function(event, menuId){
+                // $log.debug('-----------------------------removeAsFavoriteItem: ' + menuId + " - " +  event.target.id);
+                menusService.removeFavoriteItem(menuId)
+                .then(() => {
+                    angular.element('#' + event.target.id).css('color', '#666666');
+                    generateFavoriteItems();
+                }).catch(err=> {
+                    $log.error('HeaderCtrl::removeAsFavoriteItem: API removeFavoriteItem error: ' + err);
+                });
+            };
+
+            $scope.goToPortal = (headerText, url) => {
+                if (!url) {
+                    $log.warn('HeaderCtrl::goToPortal: No url found for this application, doing nothing..');
+                    return;
+                }
+                if (!ECOMP_URL_REGEX.test(url)) {
+                    url = 'http://' + url;
+                }
+
+                if(headerText.startsWith("vUSP")) {
+                       window.open(url, '_blank');//, '_self'
+                }
+                else {
+                       var tabContent = { id: new Date(), title: headerText, url: url };
+                       $cookies.putObject('addTab', tabContent );
+                }
+            };
+            
+            $scope.editProfile = () => {
+                let data = null;
+               
+                ngDialog.open({
+                    templateUrl: 'app/views/header/profile-edit-dialogs/profile-edit.modal.html',
+                    controller: 'EditProfileModalCtrl',
+                    controllerAs: 'profileDetail',
+                    data: ''
+                }).closePromise.then(needUpdate => {
+                    if(needUpdate.value === true){
+                        // $log.debug('AdminsCtrl:openAddNewAdminModal:: updating table data...');
+                        updateTableData();
+                    }
+                });
+            };
+        }
+    }
+    class LoginSnippetCtrl {
+        constructor($log, $scope, $cookies, $timeout, userProfileService, sessionService) {
+            $scope.firstName="";
+            $scope.lastName="";
+            $scope.displayUserAppRoles=false; 
+            $scope.allAppsLogout = function(){
+               
+               var cookieTabs = $cookies.getObject('visInVisCookieTabs');
+               if(cookieTabs!=null){
+                       for(var t in cookieTabs){
+                       
+                               var url = cookieTabs[t].content;
+                               if(url != "") {
+                                       sessionService.logout(url);
+                       }
+                       }
+               }
+               // wait for individual applications to log out before the portal logout
+               $timeout(function() {
+                       window.location = "logout.htm";
+               }, 2000);
+            }
+            
+            
+            try {
+               userProfileService.getFunctionalMenuStaticInfo()
+                .then(res=> {
+                 // $log.info('HeaderCtrl::LoginSnippetCtrl: Login information: ' + JSON.stringify(res));
+                 $scope.firstName = res.firstName;
+                 $scope.lastName = res.lastName;
+                 $scope.loginSnippetEmail = res.email;
+                 $scope.loginSnippetUserid = res.userId;
+                 $scope.lastLogin = res.last_login;
+                }).catch(err=> {
+                 $log.error('HeaderCtrl::LoginSnippetCtrl: failed in getFunctionalMenuStaticInfo: ' + err);
+                });
+            } catch (err) {
+                $log.error('HeaderCtrl::LoginSnippetCtrl caught exception: ' + err);
+            }
+            
+            $scope.getUserApplicationRoles= function(){
+                 $scope.userapproles = [];
+                 if($scope.displayUserAppRoles)
+                               $scope.displayUserAppRoles = false;
+                                else
+                                       $scope.displayUserAppRoles = true;
+                 
+                       userProfileService.getUserAppRoles($scope.loginSnippetUserid)
+                         .then(res=>{
+                               
+                        for(var i=0;i<res.length;i++){                                 
+                       var userapprole ={
+                               App:res[i].appName,
+                               Roles:res[i].roleNames, 
+                       };
+                       
+                       $scope.userapproles.push(userapprole); 
+                       }
+                        
+               });
+               
+          }
+        }        
+    }
+    class NotificationCtrl{
+       constructor($log, $scope, $cookies, $timeout, sessionService,notificationService,$interval,ngDialog) {
+                $scope.notifications=[];   
+                var intervalPromise = null;
+             $scope.notificationCount= notificationService.notificationCount;
+             
+             $scope.getNotification = function(){               
+                notificationService.getNotification()
+                 .then(res=> {
+                       notificationService.decrementRefreshCount();
+                       var count = notificationService.getRefreshCount();
+                       if (res==null || res.data==null || res.data.message!='success') {
+                               $log.error('NotificationCtrl::updateNotifications: failed to get notifications');
+                               if (intervalPromise != null)
+                                       $interval.cancel(intervalPromise);
+                       } else if(count<=0){
+                               if (intervalPromise != null)
+                                       $interval.cancel(intervalPromise);
+                       } else {
+                               $scope.notifications = [];
+                               notificationService.setNotificationCount(res.data.response.length);
+                               for(var i=0;i<res.data.response.length;i++){
+                                       var data = res.data.response[i];                                        
+                                       var notification ={
+                                               id:data.notificationId,
+                                               title:data.msgHeader,
+                                               message:data.msgDescription,
+                                               source:data.msgSource,
+                                               time:data.createdDate,
+                                               priority:data.priority
+                                       };
+                                       $scope.notifications.push(notification);       
+                                    }  
+                       }       
+                 }).catch(err=> {
+                       $log.error('NotificationCtrl::getNotification: caught exception: ' + err);
+                       if (intervalPromise != null)
+                               $interval.cancel(intervalPromise);
+                 });      
+             }
+             $scope.getNotification();
+             function updateNotifications() {
+                $scope.getNotification();
+             }
+             $scope.start = function(rate) {
+                               // stops any running interval to avoid two intervals running at the same time
+                               $scope.stop();  
+                               // store the interval promise
+                               intervalPromise = $interval(updateNotifications, rate);
+                        };
+
+                        $scope.stop = function() {
+                               $interval.cancel(intervalPromise);
+                        };
+                        
+                        $scope.showDetailedJsonMessage=function (selectedAdminNotification) {
+                        notificationService.getMessageRecipients(selectedAdminNotification.id).then(res =>{
+                     $scope.messageRecipients = res;
+                                var messageObject=JSON.parse(selectedAdminNotification.message);
+                                var html="";
+                                html+='<p>'+'Message Source'+' : '+selectedAdminNotification.source+'</p>';
+                                html+='<p>'+'Message Title'+' : '+selectedAdminNotification.title+'</p>';
+                                html+='<p>'+'Message Recipient'+' : '+$scope.messageRecipients+'</p>';
+
+                                for(var field in  messageObject){
+                                        if(field=='eventDate'||field=='lastModifiedDate'){
+                                                html+='<p>'+field+' : '+new Date(+messageObject[field])+'</p>';
+                                                 
+                                        }else{
+                                        html+='<p>'+field+' : '+messageObject[field]+'</p>';
+                                        
+                                        }
+                                }
+
+                                var modalInstance = ngDialog.open({
+                                   templateUrl: 'app/views/user-notifications-admin/user.notifications.Json.details.modal.page.html',
+                                   controller: 'userNotificationCtrl',
+                                   resolve: {
+                                       message: function () {
+                                               var message = {
+                                                          title:    '',
+                                               text:    html
+                                               
+                                               };
+                                         return message;
+                                       },
+                                    
+                                     }
+                                 }); 
+                    
+                }).catch(err => {
+                 $log.error('userNotificationsCtrl:getMessageRecipients:: error ', err);
+                 $scope.isLoadingTable = false;
+             });
+                };
+                        
+                       notificationService.getNotificationRate().then(res=> {
+               if (res == null || res.response == null) {
+                       $log.error('NotificationCtrl: failed to notification update rate or duration, check system.properties file.');
+               } else {
+                       var rate = parseInt(res.response.updateRate);
+                                       var duration = parseInt(res.response.updateDuration);
+                                       notificationService.setMaxRefreshCount(parseInt(duration/rate)+1);
+                                       notificationService.setRefreshCount(notificationService.maxCount);
+                               if (rate != NaN && duration != NaN) {
+                                               $scope.updateRate=rate;
+                                               $scope.start($scope.updateRate);
+                               }                               
+               }
+            }).catch(err=> {
+               $log.error('NotificationCtrl: getNotificationRate() failed: ' + err);
+            });
+             
+             $scope.deleteNotification = function(index){
+                if ($scope.notifications[index].id == null || $scope.notifications[index].id == '') {
+                       $log.error('NotificationCtrl: failed to delete Notification.');
+                       return;
+                }
+                notificationService.setNotificationRead($scope.notifications[index].id);
+                $scope.notifications.splice(index,1);
+                notificationService.setNotificationCount($scope.notifications.length);          
+             }
+       }
+    }
+    
+    class RecommendationCtrl{
+       constructor($log, $scope, $cookies, $timeout, sessionService,recommendationService,notificationService,$interval,ngDialog) {
+                $scope.recommendations=[];   
+                var intervalPromise = null;
+             $scope.recommendationCount=  recommendationService.recommendationCount;
+             console.log("$",$);
+            $scope.getRecommendations = function(){ 
+               $("#recommendation-bulb").removeClass('icon-misc-bulbL').addClass('icon-misc-bulb')
+                recommendationService.getRecommendations()
+                
+                 .then(res=> {
+                               $("#recommendation-bulb").removeClass('icon-misc-bulb').addClass('icon-misc-bulbL')
+                       recommendationService.decrementRefreshCount();
+                       var count = recommendationService.getRefreshCount();
+                       if ( res.data==null) {
+                               $log.error('RecommendationCtrl::update Recommendation: failed to get recommendation');
+                               if (intervalPromise != null)
+                                       $interval.cancel(intervalPromise);
+                       } else if(count>=0){
+                               if (intervalPromise != null)
+                                       $interval.cancel(intervalPromise);
+                       } else {
+                               $scope.recommendations = [];
+                               recommendationService.setRecommendationCount(res.data.recommendations.length);
+                               for(var i=0;i<res.data.recommendations.length;i++){
+                                       var data = res.data.recommendations[i];                                 
+                                       var recommendations ={
+                                                                                               
+                                                       recommendation:data
+                                       };
+                                       $scope.recommendations.push(recommendations);       
+                                    }  
+                       }       
+                 }).catch(err=> {
+                       $log.error('RecommendationCtrl::gatRecommendations: caught exception: ' + err);
+                       if (intervalPromise != null)
+                               $interval.cancel(intervalPromise);
+                 });      
+             }
+             $scope.getRecommendations();
+             
+             function updateRecommendations() {
+                $scope.getRecommendations();
+             }
+             
+             notificationService.getNotificationRate().then(res=> {
+               if (res == null || res.response == null) {
+                       $log.error('NotificationCtrl: failed to notification update rate or duration, check system.properties file.');
+               } else {
+                       var rate = parseInt(res.response.updateRate);
+                                       var duration = parseInt(res.response.updateDuration);
+                                       notificationService.setMaxRefreshCount(parseInt(duration/rate)+1);
+                                       notificationService.setRefreshCount(notificationService.maxCount);
+                               if (rate != NaN && duration != NaN) {
+                                               $scope.updateRate=rate;
+                                   setInterval(function(){$scope.getRecommendations();},rate);
+
+                               }                               
+               }
+              }).catch(err=> {
+               $log.error('NotificationCtrl: getNotificationRate() failed: ' + err);
+              });             
+             $scope.deleteRecommendation = function(index){
+                if ($scope.recommendations[index] == null || $scope.recommendations[index] == '') {
+                       $log.error('RecommendationCtrl: failed to delete Recommendation.');
+                       return;
+                }
+                $scope.recommendations.splice(index,1);
+                recommendationService.setRecommendationCount($scope.recommendations.length);            
+             }
+       }
+    }
+    NotificationCtrl.$inject = ['$log', '$scope', '$cookies', '$timeout', 'sessionService','notificationService','$interval','ngDialog'];
+    RecommendationCtrl.$inject = ['$log', '$scope', '$cookies', '$timeout', 'sessionService','recommendationService','notificationService','$interval','ngDialog'];
+    LoginSnippetCtrl.$inject = ['$log', '$scope', '$cookies', '$timeout','userProfileService', 'sessionService'];
+    HeaderCtrl.$inject = ['$log', '$window', 'userProfileService', 'menusService', '$scope', 'ECOMP_URL_REGEX','$cookies','$state','auditLogService','notificationService','recommendationService','ngDialog'];
+    angular.module('ecompApp').controller('HeaderCtrl', HeaderCtrl);
+    angular.module('ecompApp').controller('loginSnippetCtrl', LoginSnippetCtrl);
+    angular.module('ecompApp').controller('notificationCtrl', NotificationCtrl);
+    angular.module('ecompApp').controller('recommendationCtrl', RecommendationCtrl);
+
+})();