[PORTAL-16 PORTAL-18] Widget ms; staging
[portal.git] / ecomp-portal-FE-common / client / app / views / sidebar / sidebar.controller.js
1 /*-
2  * ================================================================================
3  * ECOMP Portal
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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  * ================================================================================
19  */
20 'use strict';
21 (function () {
22     class SidebarCtrl {
23         constructor(applicationsService,userProfileService, $log, $rootScope) {
24             this.$log = $log;
25             this.userProfileService = userProfileService;
26             this.$rootScope = $rootScope;
27             $rootScope.isAdminPortalAdmin = false;
28
29
30             //if (bowser.msie || bowser.msedge)
31             //    $log.debug('SidebarCtrl::init: Browser is: Internet Explorer or Edge');
32             // else
33             //    $log.debug('SidebarCtrl::init: Browser is: ' + bowser.name + ': ' + bowser.version);
34
35             //note: this model should be retrieved from BE via sidebar specific service
36                 userProfileService.getUserProfile()
37                 .then(profile=> {
38                         
39                         if (profile.roles.indexOf('System Administrator') > -1) {
40                         $rootScope.isAdminPortalAdmin = true;
41                         } else {
42                                  this.$log.debug('SidebarCtrl::getUserProfile: user is not superAdmin nor admin');
43                         }
44                 });
45                 // $log.debug('SidebarCtrl::getUserProfile: profile.roles.indexOf(superAdmin) = ' + profile.roles.indexOf('superAdmin'));
46                 // $log.debug('SidebarCtrl::getUserProfile: profile.roles.indexOf(admin) = ' + profile.roles.indexOf('admin'));
47                 applicationsService
48                         .getLeftMenuItems()
49                         .then(res=>
50                                  {
51                                                 //console.log("Menu items is "+JSON.stringify(res));
52                                                 this.sidebarModel = res;         
53                                  }).catch(err => {
54                         //confirmBoxService.showInformation('There was a problem creating the menu. ' +
55                     // 'Please try again later. Error Status: '+ err.status).then(isConfirmed => {});
56                         $log.error('SidebarCtrl::getUserProfile: User Profile error occurred: ' + err);
57                                 });
58     
59         }
60     }
61     SidebarCtrl.$inject = ['applicationsService','userProfileService', '$log', '$rootScope'];
62     angular.module('ecompApp').controller('SidebarCtrl', SidebarCtrl);
63 })();