Enable junit test cases and fix defects.
[portal.git] / ecomp-portal-FE-common / client / app / views / header / header.controller.js
index 2eba057..f0a3117 100644 (file)
@@ -20,7 +20,7 @@
 'use strict';
 (function () {
        class HeaderCtrl {
-        constructor($log, $window, userProfileService, menusService, $scope, ECOMP_URL_REGEX, $cookies, $state,auditLogService,notificationService,ngDialog) {
+        constructor($log, $window, userProfileService, menusService, $scope, ECOMP_URL_REGEX, $cookies, $state,auditLogService,notificationService,ngDialog,$modal) {
             this.firstName = '';
             this.lastName = '';
             this.$log = $log;
             
             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;                                     
                }
 
             $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) {
                     $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;
-                // }
+            $scope.submenuLevelAction = function(index, column) {           
                 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;
                     $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 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=> {
            };
 
             $scope.removeAsFavoriteItem =  function(event, menuId){
-                // $log.debug('-----------------------------removeAsFavoriteItem: ' + menuId + " - " +  event.target.id);
                 menusService.removeFavoriteItem(menuId)
                 .then(() => {
                     angular.element('#' + event.target.id).css('color', '#666666');
                     data: ''
                 }).closePromise.then(needUpdate => {
                     if(needUpdate.value === true){
-                        // $log.debug('AdminsCtrl:openAddNewAdminModal:: updating table data...');
                         updateTableData();
                     }
                 });
             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;
                        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) {
+       constructor($log, $scope, $cookies, $timeout, sessionService,notificationService,$interval,ngDialog,$modal) {
                 $scope.notifications=[];   
                 var intervalPromise = null;
              $scope.notificationCount= notificationService.notificationCount;
                                        var data = res.data.response[i];                                        
                                        var notification ={
                                                id:data.notificationId,
-                                               title:data.msgHeader,
+                                               msgHeader:data.msgHeader,
                                                message:data.msgDescription,
-                                               source:data.msgSource,
+                                               msgSource:data.msgSource,
                                                time:data.createdDate,
-                                               priority:data.priority
+                                               priority:data.priority,
+                                               notificationHyperlink:data.notificationHyperlink
                                        };
                                        $scope.notifications.push(notification);       
                                     }  
                         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;
-             });
+                                var modalInstance = $modal.open({
+                           templateUrl: 'app/views/user-notifications-admin/user.notifications.json.details.modal.page.html',
+                           controller: 'userNotificationCtrl',
+                           sizeClass: 'modal-large', 
+                           resolve: {
+                                               items: function () {
+                                                       var items = {
+                                                                  title:    '',
+                                                   selectedAdminNotification:selectedAdminNotification,messageObject:messageObject,messageRecipients:$scope.messageRecipients
+                                                       
+                                                       };
+                                                 return items;
+                                               }
+                               }
+                       })
+                    
+        
+        }).catch(err => {
+            $log.error('userNotificationsCtrl:getMessageRecipients:: error ', err);
+            $scope.isLoadingTable = false;
+        });
                 };
                         
                        notificationService.getNotificationRate().then(res=> {
        }
     }
     
-    NotificationCtrl.$inject = ['$log', '$scope', '$cookies', '$timeout', 'sessionService','notificationService','$interval','ngDialog'];
+    NotificationCtrl.$inject = ['$log', '$scope', '$cookies', '$timeout', 'sessionService','notificationService','$interval','ngDialog','$modal'];
     LoginSnippetCtrl.$inject = ['$log', '$scope', '$cookies', '$timeout','userProfileService', 'sessionService'];
-    HeaderCtrl.$inject = ['$log', '$window', 'userProfileService', 'menusService', '$scope', 'ECOMP_URL_REGEX','$cookies','$state','auditLogService','notificationService','ngDialog'];
+    HeaderCtrl.$inject = ['$log', '$window', 'userProfileService', 'menusService', '$scope', 'ECOMP_URL_REGEX','$cookies','$state','auditLogService','notificationService','ngDialog','$modal'];
     angular.module('ecompApp').controller('HeaderCtrl', HeaderCtrl);
     angular.module('ecompApp').controller('loginSnippetCtrl', LoginSnippetCtrl);
     angular.module('ecompApp').controller('notificationCtrl', NotificationCtrl);