nexus site path corrected
[portal.git] / ecomp-portal-FE / 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(userProfileService, $log, $rootScope) {
24             this.$log = $log;
25             this.userProfileService = userProfileService;
26             this.$rootScope = $rootScope;
27             $rootScope.isAdminPortalAdmin = false;
28
29             //if (bowser.msie || bowser.msedge)
30             //    $log.debug('SidebarCtrl::init: Browser is: Internet Explorer or Edge');
31             // else
32             //    $log.debug('SidebarCtrl::init: Browser is: ' + bowser.name + ': ' + bowser.version);
33
34             userProfileService.getUserProfile()
35                 .then(profile=> {
36                     // $log.debug('SidebarCtrl::getUserProfile: profile.roles.indexOf(superAdmin) = ' + profile.roles.indexOf('superAdmin'));
37                     // $log.debug('SidebarCtrl::getUserProfile: profile.roles.indexOf(admin) = ' + profile.roles.indexOf('admin'));
38                     if (profile.roles.indexOf('superAdmin') > -1) {
39                         $rootScope.isAdminPortalAdmin = true;
40                         // this.$log.debug('SidebarCtrl::getUserProfile: user has the superAdmin role');
41                         this.sidebarModel = {
42                             label: 'ECOMP portal',
43                             navItems: [
44                                 {
45                                     name: 'Home',
46                                     state: 'root.applicationsHome',
47                                     imageSrc : 'ion-home'
48                                 }, {
49                                     name: 'Application Catalog',
50                                     state: 'root.appCatalog',
51                                     imageSrc : 'ion-grid'
52                                 }, {
53                                     name: 'Widgets',
54                                     state: 'root.widgetsHome',
55                                     imageSrc : 'ion-android-apps'
56                                 }, {
57                                     name: 'Admins',
58                                     state: 'root.admins',
59                                     imageSrc : 'ion-android-star'
60                                 }, {
61                                     name: 'Users',
62                                     state: 'root.users',
63                                     imageSrc : 'ion-person'
64                                 },{
65                                     name: 'Portal Admins',
66                                     state: 'root.portalAdmins',
67                                     imageSrc : 'ion-gear-a'
68                                 }, {
69                                     name: 'Application Onboarding',
70                                     state: 'root.applications',
71                                     imageSrc : 'ion-ios-upload-outline'
72                                 }, {
73                                     name: 'Widget Onboarding',
74                                     state: 'root.widgets',
75                                     imageSrc : 'ion-ios-upload-outline'
76                                 },{
77                                     name: 'Edit Functional Menu',
78                                     state: 'root.functionalMenu',
79                                     imageSrc : 'ion-compose'
80                                 }
81                             ]
82                         };
83                     }
84                     else if (profile.roles.indexOf('admin')  > -1) {
85                         // this.$log.debug('SidebarCtrl::getUserProfile: user has the admin role');
86                         this.sidebarModel = {
87                             label: 'ECOMP portal',
88                             navItems: [
89                                        {
90                                            name: 'Home',
91                                            state: 'root.applicationsHome',
92                                            imageSrc : 'ion-home'
93                                        }, {
94                                            name: 'Application Catalog',
95                                            state: 'root.appCatalog',
96                                            imageSrc : 'ion-grid'
97                                        }, {
98                                         name: 'Widgets',
99                                         state: 'root.widgetsHome',
100                                         imageSrc : 'ion-grid'
101                                        }, {
102                                         name: 'Users',
103                                         state: 'root.users',
104                                         imageSrc : 'ion-person'
105                                        }, {
106                                         name: 'Widget Onboarding',
107                                         state: 'root.widgets',
108                                         imageSrc : 'ion-grid'
109                                        }
110                                    ]
111                         };
112                     }
113                     else {
114                         $rootScope.isAdminPortalAdmin = false;
115                         // this.$log.debug('SidebarCtrl::getUserProfile: user is not superAdmin nor admin');
116                         this.sidebarModel = {
117                             label: 'ECOMP portal',
118                             navItems: [
119                                        {
120                                            name: 'Home',
121                                            state: 'root.applicationsHome',
122                                            imageSrc : 'ion-home'
123                                        }, {
124                                            name: 'Application Catalog',
125                                            state: 'root.appCatalog',
126                                            imageSrc : 'ion-grid'
127                                        }, {
128                                         name: 'Widgets',
129                                         state: 'root.widgetsHome',
130                                         imageSrc : 'ion-grid'
131                                        }
132                                    ]
133                         };
134                     }
135                 }).catch(err=> {
136                           $log.error('SidebarCtrl: failed to get user profile: ' + err);
137             });
138
139         }
140     }
141     SidebarCtrl.$inject = ['userProfileService', '$log', '$rootScope'];
142     angular.module('ecompApp').controller('SidebarCtrl', SidebarCtrl);
143 })();