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 * ================================================================================
23 constructor($log, $window, userProfileService, menusService, $scope, ECOMP_URL_REGEX, $cookies, $state,auditLogService,notificationService,recommendationService,ngDialog) {
27 this.menusService = menusService;
29 this.favoritesMenuItems = '';
30 $scope.favoriteItemsCount = 0;
31 $scope.favoritesMenuItems = '';
32 $scope.showFavorites = false;
33 $scope.emptyFavorites = false;
34 $scope.favoritesWindow = false;
35 $scope.notificationCount=0;
36 $scope.recommendationCount=0;
37 $scope.showNotification = true;
39 $scope.hideMenus = false;
41 $scope.menuItems = [];
42 $scope.activeClickSubMenu = {
45 $scope.activeClickMenu = {
48 $scope.megaMenuDataObject =[];
49 $scope.notificationCount= notificationService.notificationCount;
50 $scope.recommendationCount= recommendationService.recommendationCount;
51 this.isLoading = true;
52 this.ECOMP_URL_REGEX = ECOMP_URL_REGEX;
54 var unflatten = function( array, parent, tree ){
56 tree = typeof tree !== 'undefined' ? tree : [];
57 parent = typeof parent !== 'undefined' ? parent : { menuId: null };
58 var children = _.filter( array, function(child){ return child.parentMenuId == parent.menuId; });
60 if( !_.isEmpty( children ) ){
61 if( parent.menuId === null ){
64 parent['children'] = children
66 _.each( children, function( child ){ unflatten( array, child ) } );
72 userProfileService.getFunctionalMenuStaticInfo()
74 // $log.debug('HeaderCtrl::getFunctionalMenuStaticInfo: getting Functional Menu Static Info init');
75 if(res==null || res.firstName==null || res.firstName=='' || res.lastName==null || res.lastName=='' ){
76 // $log.info('HeaderCtrl::getFunctionalMenuStaticInfo: failed getting userinfo from shared context.. ');
77 $log.info('HeaderCtrl: failed to get all required data, trying user profile');
78 userProfileService.getUserProfile()
80 // $log.debug('HeaderCtrl:: getting userinfo from session success');
81 this.firstName = profile.firstName;
82 this.lastName = profile.lastName;
83 // $log.debug('HeaderCtrl::getFunctionalMenuStaticInfo: user has the following roles: ' + profile.roles);
85 $log.error('Header Controller:: getUserProfile() failed: ' + err);
88 // $log.debug('HeaderCtrl: fetched Functional Menu Static Info successfully',res);
89 this.firstName = res.firstName;
90 this.lastName = res.lastName;
93 menusService.GetFunctionalMenuForUser()
94 .then(jsonHeaderMenu=> {
95 $scope.menuItems = unflatten( jsonHeaderMenu );
96 $scope.megaMenuDataObject = $scope.menuItems;
98 $log.error('HeaderCtrl::GetFunctionalMenuForUser: HeaderCtrl json returned: ' + err);
102 $log.error('HeaderCtrl::getFunctionalMenuStaticInfo failed: ' + err);
106 $scope.auditLog = function(app,type) {
107 var comment = 'type: '+type+ ',title: '+app.text+",url: "+app.url;
108 auditLogService.storeAudit(app.appid,'functional',comment);
111 $scope.loadFavorites = function () {
112 $scope.hideMenus = false;
113 // $log.debug('HeaderCtrl::loadFavorites: loadFavorites has happened.');
114 if ($scope.favoritesMenuItems == '') {
115 generateFavoriteItems();
116 // $log.debug('HeaderCtrl::loadFavorites: loadFavorites is calling generateFavoriteItems()');
118 // $log.debug('HeaderCtrl::loadFavorites: loadFavorites is NOT calling generateFavoriteItems()');
122 $scope.goToUrl = (item) => {
123 // $log.error('HeaderCtrl::goToUrl has started',item);
125 let restrictedApp = item.restrictedApp;
127 $log.warn('HeaderCtrl::goToUrl: No url found for this application, doing nothing..');
131 $window.open(url, '_blank');
133 if(item.url=="getAccess" || item.url=="contactUs"){
134 // if (url = window.location.href)
135 $state.go("root."+url);
137 var tabContent = { id: new Date(), title: item.text, url: item.url,appId:item.appid };
138 $cookies.putObject('addTab', tabContent );
140 // $log.debug('HeaderCtrl::goToUrl: url = ', url);
142 $scope.hideMenus = true;
147 $scope.submenuLevelAction = function(index, column) {
148 if ($scope.favoritesMenuItems == '') {
149 generateFavoriteItems();
150 // $log.debug('HeaderCtrl::submenuLevelAction: submenuLevelAction is calling generateFavoriteItems()');
152 // $log.debug('submenuLevelAction is NOT calling generateFavoriteItems()');
154 // $log.debug('item hovered: ' + index + '; column = ' + column);
155 // if (column == 2) { // 2 is Design
156 // // This is an admitted hack. See aw3218 for reasons why
157 // $log.debug('submenuLevelAction column == 2');
158 // $scope.favoritesWindow = false;
159 // $scope.showFavorites = false;
160 // $scope.emptyFavorites = false;
162 if (index=='Favorites' && $scope.favoriteItemsCount != 0) {
163 // $log.debug('HeaderCtrl::submenuLevelAction: Showing Favorites window');
164 // generateFavoriteItems();
165 $scope.favoritesWindow = true;
166 $scope.showFavorites = true;
167 $scope.emptyFavorites = false;
169 if (index=='Favorites' && $scope.favoriteItemsCount == 0) {
170 // $log.debug('HeaderCtrl::submenuLevelAction: Hiding Favorites window in favor of No Favorites Window');
171 // generateFavoriteItems();
172 $scope.favoritesWindow = true;
173 $scope.showFavorites = false;
174 $scope.emptyFavorites = true;
176 if (index!='Favorites' ) {
177 $scope.favoritesWindow = false;
178 $scope.showFavorites = false;
179 $scope.emptyFavorites = false;
184 $scope.hideFavoritesWindow = function() {
185 $scope.showFavorites = false;
186 $scope.emptyFavorites = false;
187 // $scope.thirdFourthMenus = true;
190 $scope.isUrlFavorite = function (menuId) {
191 // $log.debug('array objects in menu favorites = ' + $scope.favoriteItemsCount + '; menuId=' + menuId);
192 var jsonMenu = JSON.stringify($scope.favoritesMenuItems);
193 var isMenuFavorite = jsonMenu.indexOf('menuId\":' + menuId);
194 // $log.debug('jsonMenu.indexOf(menuId:' + jsonMenu.indexOf('menuId\":'+menuId));
195 // $log.debug('isMenuFavorite= ' + isMenuFavorite);
196 if (isMenuFavorite==-1) {
204 /*Getting Ecomp portal Title*/
206 let getEcompPortalTitle = () => {
207 menusService.getEcompPortalTitle()
209 $scope.ecompTitle = title.response;
211 $log.error('HeaderCtrl.getEcompPortalTitle:: Error retrieving ECMOP portal title: ' + err);
214 getEcompPortalTitle();
216 let generateFavoriteItems = () => {
217 menusService.getFavoriteItems()
219 // $log.debug('HeaderCtrl.getFavoriteItems:: ' + JSON.stringify(favorites));
220 $scope.favoritesMenuItems = favorites;
221 $scope.favoriteItemsCount = Object.keys(favorites).length;
222 // $log.info('HeaderCtrl.getFavoriteItems:: number of favorite menus: ' + $scope.favoriteItemsCount);
224 $log.error('HeaderCtrl.getFavoriteItems:: Error retrieving Favorites menus: ' + err);
228 $scope.setAsFavoriteItem = function(event, menuId){
229 var jsonMenuID = angular.toJson({'menuId': + menuId });
230 // $log.debug('HeaderCtrl::setFavoriteItems: ' + jsonMenuID + " - " + event.target.id);
232 menusService.setFavoriteItem(jsonMenuID)
234 // var elementId = '#'+ event.currentTarget.id;
235 angular.element('#' + event.target.id).css('color', '#fbb313');
236 generateFavoriteItems();
238 $log.error('HeaderCtrl::setFavoriteItems:: API setFavoriteItem error: ' + err);
242 $scope.removeAsFavoriteItem = function(event, menuId){
243 // $log.debug('-----------------------------removeAsFavoriteItem: ' + menuId + " - " + event.target.id);
244 menusService.removeFavoriteItem(menuId)
246 angular.element('#' + event.target.id).css('color', '#666666');
247 generateFavoriteItems();
249 $log.error('HeaderCtrl::removeAsFavoriteItem: API removeFavoriteItem error: ' + err);
253 $scope.goToPortal = (headerText, url) => {
255 $log.warn('HeaderCtrl::goToPortal: No url found for this application, doing nothing..');
258 if (!ECOMP_URL_REGEX.test(url)) {
259 url = 'http://' + url;
262 if(headerText.startsWith("vUSP")) {
263 window.open(url, '_blank');//, '_self'
266 var tabContent = { id: new Date(), title: headerText, url: url };
267 $cookies.putObject('addTab', tabContent );
271 $scope.editProfile = () => {
275 templateUrl: 'app/views/header/profile-edit-dialogs/profile-edit.modal.html',
276 controller: 'EditProfileModalCtrl',
277 controllerAs: 'profileDetail',
279 }).closePromise.then(needUpdate => {
280 if(needUpdate.value === true){
281 // $log.debug('AdminsCtrl:openAddNewAdminModal:: updating table data...');
288 class LoginSnippetCtrl {
289 constructor($log, $scope, $cookies, $timeout, userProfileService, sessionService) {
292 $scope.displayUserAppRoles=false;
293 $scope.allAppsLogout = function(){
295 var cookieTabs = $cookies.getObject('visInVisCookieTabs');
296 if(cookieTabs!=null){
297 for(var t in cookieTabs){
299 var url = cookieTabs[t].content;
301 sessionService.logout(url);
305 // wait for individual applications to log out before the portal logout
306 $timeout(function() {
307 window.location = "logout.htm";
313 userProfileService.getFunctionalMenuStaticInfo()
315 // $log.info('HeaderCtrl::LoginSnippetCtrl: Login information: ' + JSON.stringify(res));
316 $scope.firstName = res.firstName;
317 $scope.lastName = res.lastName;
318 $scope.loginSnippetEmail = res.email;
319 $scope.loginSnippetUserid = res.userId;
320 $scope.lastLogin = res.last_login;
322 $log.error('HeaderCtrl::LoginSnippetCtrl: failed in getFunctionalMenuStaticInfo: ' + err);
325 $log.error('HeaderCtrl::LoginSnippetCtrl caught exception: ' + err);
328 $scope.getUserApplicationRoles= function(){
329 $scope.userapproles = [];
330 if($scope.displayUserAppRoles)
331 $scope.displayUserAppRoles = false;
333 $scope.displayUserAppRoles = true;
335 userProfileService.getUserAppRoles($scope.loginSnippetUserid)
338 for(var i=0;i<res.length;i++){
341 Roles:res[i].roleNames,
344 $scope.userapproles.push(userapprole);
352 class NotificationCtrl{
353 constructor($log, $scope, $cookies, $timeout, sessionService,notificationService,$interval,ngDialog) {
354 $scope.notifications=[];
355 var intervalPromise = null;
356 $scope.notificationCount= notificationService.notificationCount;
358 $scope.getNotification = function(){
359 notificationService.getNotification()
361 notificationService.decrementRefreshCount();
362 var count = notificationService.getRefreshCount();
363 if (res==null || res.data==null || res.data.message!='success') {
364 $log.error('NotificationCtrl::updateNotifications: failed to get notifications');
365 if (intervalPromise != null)
366 $interval.cancel(intervalPromise);
368 if (intervalPromise != null)
369 $interval.cancel(intervalPromise);
371 $scope.notifications = [];
372 notificationService.setNotificationCount(res.data.response.length);
373 for(var i=0;i<res.data.response.length;i++){
374 var data = res.data.response[i];
376 id:data.notificationId,
377 title:data.msgHeader,
378 message:data.msgDescription,
379 source:data.msgSource,
380 time:data.createdDate,
381 priority:data.priority
383 $scope.notifications.push(notification);
387 $log.error('NotificationCtrl::getNotification: caught exception: ' + err);
388 if (intervalPromise != null)
389 $interval.cancel(intervalPromise);
392 $scope.getNotification();
393 function updateNotifications() {
394 $scope.getNotification();
396 $scope.start = function(rate) {
397 // stops any running interval to avoid two intervals running at the same time
399 // store the interval promise
400 intervalPromise = $interval(updateNotifications, rate);
403 $scope.stop = function() {
404 $interval.cancel(intervalPromise);
407 $scope.showDetailedJsonMessage=function (selectedAdminNotification) {
408 notificationService.getMessageRecipients(selectedAdminNotification.id).then(res =>{
409 $scope.messageRecipients = res;
410 var messageObject=JSON.parse(selectedAdminNotification.message);
412 html+='<p>'+'Message Source'+' : '+selectedAdminNotification.source+'</p>';
413 html+='<p>'+'Message Title'+' : '+selectedAdminNotification.title+'</p>';
414 html+='<p>'+'Message Recipient'+' : '+$scope.messageRecipients+'</p>';
416 for(var field in messageObject){
417 if(field=='eventDate'||field=='lastModifiedDate'){
418 html+='<p>'+field+' : '+new Date(+messageObject[field])+'</p>';
421 html+='<p>'+field+' : '+messageObject[field]+'</p>';
426 var modalInstance = ngDialog.open({
427 templateUrl: 'app/views/user-notifications-admin/user.notifications.Json.details.modal.page.html',
428 controller: 'userNotificationCtrl',
430 message: function () {
443 $log.error('userNotificationsCtrl:getMessageRecipients:: error ', err);
444 $scope.isLoadingTable = false;
448 notificationService.getNotificationRate().then(res=> {
449 if (res == null || res.response == null) {
450 $log.error('NotificationCtrl: failed to notification update rate or duration, check system.properties file.');
452 var rate = parseInt(res.response.updateRate);
453 var duration = parseInt(res.response.updateDuration);
454 notificationService.setMaxRefreshCount(parseInt(duration/rate)+1);
455 notificationService.setRefreshCount(notificationService.maxCount);
456 if (rate != NaN && duration != NaN) {
457 $scope.updateRate=rate;
458 $scope.start($scope.updateRate);
462 $log.error('NotificationCtrl: getNotificationRate() failed: ' + err);
465 $scope.deleteNotification = function(index){
466 if ($scope.notifications[index].id == null || $scope.notifications[index].id == '') {
467 $log.error('NotificationCtrl: failed to delete Notification.');
470 notificationService.setNotificationRead($scope.notifications[index].id);
471 $scope.notifications.splice(index,1);
472 notificationService.setNotificationCount($scope.notifications.length);
477 class RecommendationCtrl{
478 constructor($log, $scope, $cookies, $timeout, sessionService,recommendationService,notificationService,$interval,ngDialog) {
479 $scope.recommendations=[];
480 var intervalPromise = null;
481 $scope.recommendationCount= recommendationService.recommendationCount;
483 $scope.getRecommendations = function(){
484 $("#recommendation-bulb").removeClass('icon-misc-bulbL').addClass('icon-misc-bulb')
485 recommendationService.getRecommendations()
488 $("#recommendation-bulb").removeClass('icon-misc-bulb').addClass('icon-misc-bulbL')
489 recommendationService.decrementRefreshCount();
490 var count = recommendationService.getRefreshCount();
491 if ( res.data==null) {
492 $log.error('RecommendationCtrl::update Recommendation: failed to get recommendation');
493 if (intervalPromise != null)
494 $interval.cancel(intervalPromise);
496 if (intervalPromise != null)
497 $interval.cancel(intervalPromise);
499 $scope.recommendations = [];
500 recommendationService.setRecommendationCount(res.data.recommendations.length);
501 for(var i=0;i<res.data.recommendations.length;i++){
502 var data = res.data.recommendations[i];
503 var recommendations ={
507 $scope.recommendations.push(recommendations);
511 $log.error('RecommendationCtrl::gatRecommendations: caught exception: ' + err);
512 if (intervalPromise != null)
513 $interval.cancel(intervalPromise);
516 $scope.getRecommendations();
518 function updateRecommendations() {
519 $scope.getRecommendations();
522 notificationService.getNotificationRate().then(res=> {
523 if (res == null || res.response == null) {
524 $log.error('NotificationCtrl: failed to notification update rate or duration, check system.properties file.');
526 var rate = parseInt(res.response.updateRate);
527 var duration = parseInt(res.response.updateDuration);
528 notificationService.setMaxRefreshCount(parseInt(duration/rate)+1);
529 notificationService.setRefreshCount(notificationService.maxCount);
530 if (rate != NaN && duration != NaN) {
531 $scope.updateRate=rate;
532 setInterval(function(){$scope.getRecommendations();},rate);
537 $log.error('NotificationCtrl: getNotificationRate() failed: ' + err);
539 $scope.deleteRecommendation = function(index){
540 if ($scope.recommendations[index] == null || $scope.recommendations[index] == '') {
541 $log.error('RecommendationCtrl: failed to delete Recommendation.');
544 $scope.recommendations.splice(index,1);
545 recommendationService.setRecommendationCount($scope.recommendations.length);
549 NotificationCtrl.$inject = ['$log', '$scope', '$cookies', '$timeout', 'sessionService','notificationService','$interval','ngDialog'];
550 RecommendationCtrl.$inject = ['$log', '$scope', '$cookies', '$timeout', 'sessionService','recommendationService','notificationService','$interval','ngDialog'];
551 LoginSnippetCtrl.$inject = ['$log', '$scope', '$cookies', '$timeout','userProfileService', 'sessionService'];
552 HeaderCtrl.$inject = ['$log', '$window', 'userProfileService', 'menusService', '$scope', 'ECOMP_URL_REGEX','$cookies','$state','auditLogService','notificationService','recommendationService','ngDialog'];
553 angular.module('ecompApp').controller('HeaderCtrl', HeaderCtrl);
554 angular.module('ecompApp').controller('loginSnippetCtrl', LoginSnippetCtrl);
555 angular.module('ecompApp').controller('notificationCtrl', NotificationCtrl);
556 angular.module('ecompApp').controller('recommendationCtrl', RecommendationCtrl);