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,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.showNotification = true;
38 $scope.hideMenus = false;
40 $scope.menuItems = [];
41 $scope.activeClickSubMenu = {
44 $scope.activeClickMenu = {
47 $scope.megaMenuDataObject =[];
48 $scope.notificationCount= notificationService.notificationCount;
49 this.isLoading = true;
50 this.ECOMP_URL_REGEX = ECOMP_URL_REGEX;
52 var unflatten = function( array, parent, tree ){
54 tree = typeof tree !== 'undefined' ? tree : [];
55 parent = typeof parent !== 'undefined' ? parent : { menuId: null };
56 var children = _.filter( array, function(child){ return child.parentMenuId == parent.menuId; });
58 if( !_.isEmpty( children ) ){
59 if( parent.menuId === null ){
62 parent['children'] = children
64 _.each( children, function( child ){ unflatten( array, child ) } );
70 userProfileService.getFunctionalMenuStaticInfo()
72 // $log.debug('HeaderCtrl::getFunctionalMenuStaticInfo: getting Functional Menu Static Info init');
73 if(res==null || res.firstName==null || res.firstName=='' || res.lastName==null || res.lastName=='' ){
74 // $log.info('HeaderCtrl::getFunctionalMenuStaticInfo: failed getting userinfo from shared context.. ');
75 $log.info('HeaderCtrl: failed to get all required data, trying user profile');
76 userProfileService.getUserProfile()
78 // $log.debug('HeaderCtrl:: getting userinfo from session success');
79 this.firstName = profile.firstName;
80 this.lastName = profile.lastName;
81 // $log.debug('HeaderCtrl::getFunctionalMenuStaticInfo: user has the following roles: ' + profile.roles);
83 $log.error('Header Controller:: getUserProfile() failed: ' + err);
86 // $log.debug('HeaderCtrl: fetched Functional Menu Static Info successfully',res);
87 this.firstName = res.firstName;
88 this.lastName = res.lastName;
91 menusService.GetFunctionalMenuForUser()
92 .then(jsonHeaderMenu=> {
93 $scope.menuItems = unflatten( jsonHeaderMenu );
94 $scope.megaMenuDataObject = $scope.menuItems;
96 $log.error('HeaderCtrl::GetFunctionalMenuForUser: HeaderCtrl json returned: ' + err);
100 $log.error('HeaderCtrl::getFunctionalMenuStaticInfo failed: ' + err);
104 $scope.auditLog = function(app,type) {
105 var comment = 'type: '+type+ ',title: '+app.text+",url: "+app.url;
106 auditLogService.storeAudit(app.appid,'functional',comment);
109 $scope.loadFavorites = function () {
110 $scope.hideMenus = false;
111 // $log.debug('HeaderCtrl::loadFavorites: loadFavorites has happened.');
112 if ($scope.favoritesMenuItems == '') {
113 generateFavoriteItems();
114 // $log.debug('HeaderCtrl::loadFavorites: loadFavorites is calling generateFavoriteItems()');
116 // $log.debug('HeaderCtrl::loadFavorites: loadFavorites is NOT calling generateFavoriteItems()');
120 $scope.goToUrl = (item) => {
121 // $log.error('HeaderCtrl::goToUrl has started',item);
123 let restrictedApp = item.restrictedApp;
125 $log.warn('HeaderCtrl::goToUrl: No url found for this application, doing nothing..');
129 $window.open(url, '_blank');
131 if(item.url=="getAccess" || item.url=="contactUs"){
132 // if (url = window.location.href)
133 $state.go("root."+url);
135 var tabContent = { id: new Date(), title: item.text, url: item.url,appId:item.appid };
136 $cookies.putObject('addTab', tabContent );
138 // $log.debug('HeaderCtrl::goToUrl: url = ', url);
140 $scope.hideMenus = true;
145 $scope.submenuLevelAction = function(index, column) {
146 if ($scope.favoritesMenuItems == '') {
147 generateFavoriteItems();
148 // $log.debug('HeaderCtrl::submenuLevelAction: submenuLevelAction is calling generateFavoriteItems()');
150 // $log.debug('submenuLevelAction is NOT calling generateFavoriteItems()');
152 // $log.debug('item hovered: ' + index + '; column = ' + column);
153 // if (column == 2) { // 2 is Design
154 // // This is an admitted hack. See aw3218 for reasons why
155 // $log.debug('submenuLevelAction column == 2');
156 // $scope.favoritesWindow = false;
157 // $scope.showFavorites = false;
158 // $scope.emptyFavorites = false;
160 if (index=='Favorites' && $scope.favoriteItemsCount != 0) {
161 // $log.debug('HeaderCtrl::submenuLevelAction: Showing Favorites window');
162 // generateFavoriteItems();
163 $scope.favoritesWindow = true;
164 $scope.showFavorites = true;
165 $scope.emptyFavorites = false;
167 if (index=='Favorites' && $scope.favoriteItemsCount == 0) {
168 // $log.debug('HeaderCtrl::submenuLevelAction: Hiding Favorites window in favor of No Favorites Window');
169 // generateFavoriteItems();
170 $scope.favoritesWindow = true;
171 $scope.showFavorites = false;
172 $scope.emptyFavorites = true;
174 if (index!='Favorites' ) {
175 $scope.favoritesWindow = false;
176 $scope.showFavorites = false;
177 $scope.emptyFavorites = false;
182 $scope.hideFavoritesWindow = function() {
183 $scope.showFavorites = false;
184 $scope.emptyFavorites = false;
185 // $scope.thirdFourthMenus = true;
188 $scope.isUrlFavorite = function (menuId) {
189 // $log.debug('array objects in menu favorites = ' + $scope.favoriteItemsCount + '; menuId=' + menuId);
190 var jsonMenu = JSON.stringify($scope.favoritesMenuItems);
191 var isMenuFavorite = jsonMenu.indexOf('menuId\":' + menuId);
192 // $log.debug('jsonMenu.indexOf(menuId:' + jsonMenu.indexOf('menuId\":'+menuId));
193 // $log.debug('isMenuFavorite= ' + isMenuFavorite);
194 if (isMenuFavorite==-1) {
202 /*Getting Ecomp portal Title*/
204 let getEcompPortalTitle = () => {
205 menusService.getEcompPortalTitle()
207 $scope.ecompTitle = title.response;
209 $log.error('HeaderCtrl.getEcompPortalTitle:: Error retrieving ECMOP portal title: ' + err);
212 getEcompPortalTitle();
214 let generateFavoriteItems = () => {
215 menusService.getFavoriteItems()
217 // $log.debug('HeaderCtrl.getFavoriteItems:: ' + JSON.stringify(favorites));
218 $scope.favoritesMenuItems = favorites;
219 $scope.favoriteItemsCount = Object.keys(favorites).length;
220 // $log.info('HeaderCtrl.getFavoriteItems:: number of favorite menus: ' + $scope.favoriteItemsCount);
222 $log.error('HeaderCtrl.getFavoriteItems:: Error retrieving Favorites menus: ' + err);
226 $scope.setAsFavoriteItem = function(event, menuId){
227 var jsonMenuID = angular.toJson({'menuId': + menuId });
228 // $log.debug('HeaderCtrl::setFavoriteItems: ' + jsonMenuID + " - " + event.target.id);
230 menusService.setFavoriteItem(jsonMenuID)
232 // var elementId = '#'+ event.currentTarget.id;
233 angular.element('#' + event.target.id).css('color', '#fbb313');
234 generateFavoriteItems();
236 $log.error('HeaderCtrl::setFavoriteItems:: API setFavoriteItem error: ' + err);
240 $scope.removeAsFavoriteItem = function(event, menuId){
241 // $log.debug('-----------------------------removeAsFavoriteItem: ' + menuId + " - " + event.target.id);
242 menusService.removeFavoriteItem(menuId)
244 angular.element('#' + event.target.id).css('color', '#666666');
245 generateFavoriteItems();
247 $log.error('HeaderCtrl::removeAsFavoriteItem: API removeFavoriteItem error: ' + err);
251 $scope.goToPortal = (headerText, url) => {
253 $log.warn('HeaderCtrl::goToPortal: No url found for this application, doing nothing..');
256 if (!ECOMP_URL_REGEX.test(url)) {
257 url = 'http://' + url;
260 if(headerText.startsWith("vUSP")) {
261 window.open(url, '_blank');//, '_self'
264 var tabContent = { id: new Date(), title: headerText, url: url };
265 $cookies.putObject('addTab', tabContent );
269 $scope.editProfile = () => {
273 templateUrl: 'app/views/header/profile-edit-dialogs/profile-edit.modal.html',
274 controller: 'EditProfileModalCtrl',
275 controllerAs: 'profileDetail',
277 }).closePromise.then(needUpdate => {
278 if(needUpdate.value === true){
279 // $log.debug('AdminsCtrl:openAddNewAdminModal:: updating table data...');
286 class LoginSnippetCtrl {
287 constructor($log, $scope, $cookies, $timeout, userProfileService, sessionService) {
290 $scope.displayUserAppRoles=false;
291 $scope.allAppsLogout = function(){
293 var cookieTabs = $cookies.getObject('visInVisCookieTabs');
294 if(cookieTabs!=null){
295 for(var t in cookieTabs){
297 var url = cookieTabs[t].content;
299 sessionService.logout(url);
303 // wait for individual applications to log out before the portal logout
304 $timeout(function() {
305 window.location = "logout.htm";
311 userProfileService.getFunctionalMenuStaticInfo()
313 // $log.info('HeaderCtrl::LoginSnippetCtrl: Login information: ' + JSON.stringify(res));
314 $scope.firstName = res.firstName;
315 $scope.lastName = res.lastName;
316 $scope.loginSnippetEmail = res.email;
317 $scope.loginSnippetUserid = res.userId;
318 $scope.lastLogin = res.last_login;
320 $log.error('HeaderCtrl::LoginSnippetCtrl: failed in getFunctionalMenuStaticInfo: ' + err);
323 $log.error('HeaderCtrl::LoginSnippetCtrl caught exception: ' + err);
326 $scope.getUserApplicationRoles= function(){
327 $scope.userapproles = [];
328 if($scope.displayUserAppRoles)
329 $scope.displayUserAppRoles = false;
331 $scope.displayUserAppRoles = true;
333 userProfileService.getUserAppRoles($scope.loginSnippetUserid)
336 for(var i=0;i<res.length;i++){
339 Roles:res[i].roleNames,
342 $scope.userapproles.push(userapprole);
350 class NotificationCtrl{
351 constructor($log, $scope, $cookies, $timeout, sessionService,notificationService,$interval,ngDialog) {
352 $scope.notifications=[];
353 var intervalPromise = null;
354 $scope.notificationCount= notificationService.notificationCount;
356 $scope.getNotification = function(){
357 notificationService.getNotification()
359 notificationService.decrementRefreshCount();
360 var count = notificationService.getRefreshCount();
361 if (res==null || res.data==null || res.data.message!='success') {
362 $log.error('NotificationCtrl::updateNotifications: failed to get notifications');
363 if (intervalPromise != null)
364 $interval.cancel(intervalPromise);
366 if (intervalPromise != null)
367 $interval.cancel(intervalPromise);
369 $scope.notifications = [];
370 notificationService.setNotificationCount(res.data.response.length);
371 for(var i=0;i<res.data.response.length;i++){
372 var data = res.data.response[i];
374 id:data.notificationId,
375 title:data.msgHeader,
376 message:data.msgDescription,
377 source:data.msgSource,
378 time:data.createdDate,
379 priority:data.priority
381 $scope.notifications.push(notification);
385 $log.error('NotificationCtrl::getNotification: caught exception: ' + err);
386 if (intervalPromise != null)
387 $interval.cancel(intervalPromise);
390 $scope.getNotification();
391 function updateNotifications() {
392 $scope.getNotification();
394 $scope.start = function(rate) {
395 // stops any running interval to avoid two intervals running at the same time
397 // store the interval promise
398 intervalPromise = $interval(updateNotifications, rate);
401 $scope.stop = function() {
402 $interval.cancel(intervalPromise);
405 $scope.showDetailedJsonMessage=function (selectedAdminNotification) {
406 notificationService.getMessageRecipients(selectedAdminNotification.id).then(res =>{
407 $scope.messageRecipients = res;
408 var messageObject=JSON.parse(selectedAdminNotification.message);
410 html+='<p>'+'Message Source'+' : '+selectedAdminNotification.source+'</p>';
411 html+='<p>'+'Message Title'+' : '+selectedAdminNotification.title+'</p>';
412 html+='<p>'+'Message Recipient'+' : '+$scope.messageRecipients+'</p>';
414 for(var field in messageObject){
415 if(field=='eventDate'||field=='lastModifiedDate'){
416 html+='<p>'+field+' : '+new Date(+messageObject[field])+'</p>';
419 html+='<p>'+field+' : '+messageObject[field]+'</p>';
424 var modalInstance = ngDialog.open({
425 templateUrl: 'app/views/user-notifications-admin/user.notifications.Json.details.modal.page.html',
426 controller: 'userNotificationCtrl',
428 message: function () {
441 $log.error('userNotificationsCtrl:getMessageRecipients:: error ', err);
442 $scope.isLoadingTable = false;
446 notificationService.getNotificationRate().then(res=> {
447 if (res == null || res.response == null) {
448 $log.error('NotificationCtrl: failed to notification update rate or duration, check system.properties file.');
450 var rate = parseInt(res.response.updateRate);
451 var duration = parseInt(res.response.updateDuration);
452 notificationService.setMaxRefreshCount(parseInt(duration/rate)+1);
453 notificationService.setRefreshCount(notificationService.maxCount);
454 if (rate != NaN && duration != NaN) {
455 $scope.updateRate=rate;
456 $scope.start($scope.updateRate);
460 $log.error('NotificationCtrl: getNotificationRate() failed: ' + err);
463 $scope.deleteNotification = function(index){
464 if ($scope.notifications[index].id == null || $scope.notifications[index].id == '') {
465 $log.error('NotificationCtrl: failed to delete Notification.');
468 notificationService.setNotificationRead($scope.notifications[index].id);
469 $scope.notifications.splice(index,1);
470 notificationService.setNotificationCount($scope.notifications.length);
475 NotificationCtrl.$inject = ['$log', '$scope', '$cookies', '$timeout', 'sessionService','notificationService','$interval','ngDialog'];
476 LoginSnippetCtrl.$inject = ['$log', '$scope', '$cookies', '$timeout','userProfileService', 'sessionService'];
477 HeaderCtrl.$inject = ['$log', '$window', 'userProfileService', 'menusService', '$scope', 'ECOMP_URL_REGEX','$cookies','$state','auditLogService','notificationService','ngDialog'];
478 angular.module('ecompApp').controller('HeaderCtrl', HeaderCtrl);
479 angular.module('ecompApp').controller('loginSnippetCtrl', LoginSnippetCtrl);
480 angular.module('ecompApp').controller('notificationCtrl', NotificationCtrl);