[PORTAL-7] Rebase
[portal.git] / ecomp-portal-FE-common / client / app / views / support / get-access / get-access.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 GetAccessCtrl {\r
23         constructor($log, $scope,  $stateParams, getAccessService, userProfileService, ExternalRequestAccessService, applicationsService, ngDialog) {\r
24                 // $log.debug('GetAccessCtrl: appService param is: ' + applicationsService.goGetAccessAppName);\r
25                 var resultAccessValue = null;\r
26                 \r
27                 $scope.openAppRoleModal = (itemData) => {       \r
28                         if(resultAccessValue){\r
29                         let data = null;\r
30                     data = {\r
31                         dialogState: 2,\r
32                         selectedUser:{\r
33                             attuid: $scope.attuid,\r
34                             firstName: $scope.firstName,\r
35                             lastName: $scope.lastName,\r
36                             headerText: itemData.app_name\r
37                         }\r
38                     }\r
39                 ngDialog.open({\r
40                     templateUrl: 'app/views/catalog/add-catalog-dialogs/new-catalog.modal.html',\r
41                     controller: 'NewCatalogModalCtrl',\r
42                     controllerAs: 'userInfo',\r
43                     data: data\r
44                 });\r
45                         }\r
46             }\r
47                 \r
48             userProfileService.getUserProfile().then(\r
49                                 function(profile) {\r
50                                         $scope.attuid = profile.orgUserId;\r
51                                         $scope.firstName = profile.firstName;\r
52                                         $scope.lastName = profile.lastName;\r
53                   });\r
54             \r
55                 this.updateAppsList = () => {\r
56                         ExternalRequestAccessService.getExternalRequestAccessServiceInfo().then(\r
57                                                 function(property) {\r
58                                                         resultAccessValue = property.accessValue;\r
59                                 }).catch(err => {\r
60                     $log.error('GetAccessCtrl: failed getExternalRequestAccessServiceInfo: ' + JSON.Stringify(err));\r
61                 });\r
62                 getAccessService.getListOfApp().then(res=> {\r
63                         var tableData=[];\r
64                         // $log.info('GetAccessCtrl::updateAppsList: getting res');\r
65                         var result = (typeof(res.data) != "undefined" && res.data!=null)?res.data:null;\r
66                         // $log.info('GetAccessCtrl::updateAppsList: result',result);\r
67                         // $log.info('GetAccessCtrl::updateAppsList: done');\r
68                         var source = result;\r
69                         // $log.info('GetAccessCtrl::updateAppsList source: ', source);\r
70                         for(var i=0;i<source.length; i++){\r
71                                 var dataArr = source[i];\r
72                                 var checkEcompFuncAvail = 'Ecomp Function Not Available' ; \r
73                                 var reqStatus = 'Pending'; \r
74                                 dataArr.ecompFunction = (dataArr.ecompFunction === null) ? checkEcompFuncAvail : dataArr.ecompFunction;\r
75                                 dataArr.reqType = (dataArr.reqType === 'P') ? reqStatus : dataArr.reqType;\r
76                         var dataTemp={\r
77                                 ecomp_function: dataArr.ecompFunction,\r
78                                 app_name:dataArr.appName,\r
79                                 role_name:dataArr.roleName,\r
80                                 current_role:dataArr.roleActive,\r
81                                 request_type:dataArr.reqType\r
82                         }\r
83                         tableData.push(dataTemp);\r
84                         } \r
85                         this.appTable=tableData;\r
86                         if(tableData!=null){\r
87                                 var len = tableData.length;\r
88                                 this.totalPage =  Math.ceil(len/this.viewPerPage);     \r
89                         }\r
90                         if( $stateParams.appName != null)\r
91                                 this.searchString = $stateParams.appName;\r
92                         else\r
93                                 this.searchString = applicationsService.goGetAccessAppName;\r
94                         // the parameter has been used; clear the value.\r
95                         applicationsService.goGetAccessAppName = '';\r
96                 }).catch(err=> {\r
97                     $log.error('GetAccessCtrl:error:: ', err);\r
98                 }).finally(() => {\r
99                     this.isLoadingTable = false;\r
100                 });\r
101             };\r
102             \r
103             this.updateTable = (num) => {\r
104                 this.startIndex=this.viewPerPage*(num-1);\r
105                 this.currentPage = num;\r
106             };\r
107                 let init = () => {\r
108                 // $log.info('GetAccessCtrl:: initializing...');\r
109                 this.searchString = '';\r
110                 this.getAccessTableHeaders = ['ECOMP Function', 'Application Name', 'Role Name', 'Current Role', 'Request Status'];\r
111                 this.appTable=[];\r
112                 this.updateAppsList();             \r
113                 this.viewPerPage=20;\r
114                 this.startIndex=0;\r
115                 this.currentPage = 1;\r
116                 this.totalPage=0;\r
117             };\r
118             init();\r
119         }\r
120     }\r
121     GetAccessCtrl.$inject = ['$log', '$scope', '$stateParams', 'getAccessService', 'userProfileService', 'ExternalRequestAccessService','applicationsService', 'ngDialog'];\r
122     angular.module('ecompApp').controller('GetAccessCtrl', GetAccessCtrl);\r
123 })();\r