[PORTAL-7] Rebase
[portal.git] / ecomp-portal-FE-common / client / app / views / sidebar / sidebar.controller.js
1 /*-\r
2  * ================================================================================\r
3  * ECOMP Portal\r
4  * ================================================================================\r
5  * Copyright (C) 2017 AT&T Intellectual Property\r
6  * ================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  * \r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * \r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ================================================================================\r
19  */\r
20 'use strict';\r
21 (function () {\r
22     class SidebarCtrl {\r
23         constructor(applicationsService,userProfileService, $log, $rootScope) {\r
24             this.$log = $log;\r
25             this.userProfileService = userProfileService;\r
26             this.$rootScope = $rootScope;\r
27             $rootScope.isAdminPortalAdmin = false;\r
28 \r
29 \r
30             //if (bowser.msie || bowser.msedge)\r
31             //    $log.debug('SidebarCtrl::init: Browser is: Internet Explorer or Edge');\r
32             // else\r
33             //    $log.debug('SidebarCtrl::init: Browser is: ' + bowser.name + ': ' + bowser.version);\r
34 \r
35             //note: this model should be retrieved from BE via sidebar specific service\r
36                 userProfileService.getUserProfile()\r
37                 .then(profile=> {\r
38                         \r
39                         if (profile.roles.indexOf('System Administrator') > -1) {\r
40                         $rootScope.isAdminPortalAdmin = true;\r
41                         } else {\r
42                                  this.$log.debug('SidebarCtrl::getUserProfile: user is not superAdmin nor admin');\r
43                         }\r
44                 });\r
45                 // $log.debug('SidebarCtrl::getUserProfile: profile.roles.indexOf(superAdmin) = ' + profile.roles.indexOf('superAdmin'));\r
46                 // $log.debug('SidebarCtrl::getUserProfile: profile.roles.indexOf(admin) = ' + profile.roles.indexOf('admin'));\r
47                 applicationsService\r
48                         .getLeftMenuItems()\r
49                         .then(res=>\r
50                                  {\r
51                                                 //console.log("Menu items is "+JSON.stringify(res));\r
52                                                 this.sidebarModel = res;         \r
53                                  }).catch(err => {\r
54                         //confirmBoxService.showInformation('There was a problem creating the menu. ' +\r
55                     // 'Please try again later. Error Status: '+ err.status).then(isConfirmed => {});\r
56                         $log.error('SidebarCtrl::getUserProfile: User Profile error occurred: ' + err);\r
57                                 });\r
58     \r
59         }\r
60     }\r
61     SidebarCtrl.$inject = ['applicationsService','userProfileService', '$log', '$rootScope'];\r
62     angular.module('ecompApp').controller('SidebarCtrl', SidebarCtrl);\r
63 })();\r