784d394efcc86e66a9a7d31e57746225a153b7ee
[portal.git] / ecomp-portal-FE-common / client / app / views / support / get-access / get-access.controller.js
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
8  * Unless otherwise specified, all software contained herein is licensed
9  * under the Apache License, Version 2.0 (the "License");
10  * you may not use this software except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * Unless otherwise specified, all documentation contained herein is licensed
22  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23  * you may not use this documentation except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
28  * Unless required by applicable law or agreed to in writing, documentation
29  * distributed under the License is distributed on an "AS IS" BASIS,
30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  *
34  * ============LICENSE_END============================================
35  *
36  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
37  */
38 'use strict';
39 (function () {
40     class GetAccessCtrl {
41         constructor($log, $scope,  $stateParams, filterFilter, getAccessService, userProfileService, ExternalRequestAccessService, applicationsService, ngDialog) {
42                 // $log.debug('GetAccessCtrl: appService param is: ' + applicationsService.goGetAccessAppName);
43                 var resultAccessValue = null;
44         
45                 $scope.openAppRoleModal = (itemData) => {       
46                         if(resultAccessValue){
47                         let data = null;
48                     data = {
49                         dialogState: 2,
50                         selectedUser:{
51                             orgUserId: $scope.orgUserId,
52                             firstName: $scope.firstName,
53                             lastName: $scope.lastName,
54                             headerText: itemData.app_name,
55                         }
56                     }
57                 ngDialog.open({
58                     templateUrl: 'app/views/catalog/request-access-catalog-dialogs/request-access-catalog.modal.html',
59                     controller: 'ExternalRequestAccessCtrl',
60                     controllerAs: 'userInfo',
61                     data: data
62                 });
63                         }
64             }
65                 
66             $scope.$watch('access.searchString', function (searchKey) {
67                 var search = searchKey;               
68                 this.totalPage = filterFilter($scope.access.appTable, search);
69                 var resultLen = this.totalPage.length;
70                 $scope.access.totalPage = Math.ceil(resultLen/$scope.access.viewPerPage);
71                 $scope.access.currentPage = 1;
72             });
73                 
74             userProfileService.getUserProfile().then(
75                                 function(profile) {
76                                         $scope.orgUserId = profile.orgUserId;
77                                         $scope.firstName = profile.firstName;
78                                         $scope.lastName = profile.lastName;
79                   });
80             
81                 this.updateAppsList = () => {
82                         ExternalRequestAccessService.getExternalRequestAccessServiceInfo().then(
83                                                 function(property) {
84                                                         resultAccessValue = property.accessValue;
85                                 }).catch(err => {
86                     $log.error('GetAccessCtrl: failed getExternalRequestAccessServiceInfo: ' + JSON.Stringify(err));
87                 });
88                 getAccessService.getListOfApp().then(res=> {
89                         var tableData=[];
90                         // $log.info('GetAccessCtrl::updateAppsList: getting res');
91                         var result = (typeof(res.data) != "undefined" && res.data!=null)?res.data:null;
92                         // $log.info('GetAccessCtrl::updateAppsList: result',result);
93                         // $log.info('GetAccessCtrl::updateAppsList: done');
94                         var source = result;
95                         // $log.info('GetAccessCtrl::updateAppsList source: ', source);
96                         for(var i=0;i<source.length; i++){
97                                 var dataArr = source[i];
98                                 var checkEcompFuncAvail = 'Function Not Available' ; 
99                                 var reqStatus = 'Pending'; 
100                                 dataArr.ecompFunction = (dataArr.ecompFunction === null) ? checkEcompFuncAvail : dataArr.ecompFunction;
101                                 dataArr.reqType = (dataArr.reqType === 'P') ? reqStatus : dataArr.reqType;
102                         var dataTemp={
103                                 ecomp_function: dataArr.ecompFunction,
104                                 app_name:dataArr.appName,
105                                 role_name:dataArr.roleName,
106                                 current_role:dataArr.roleActive,
107                                 request_type:dataArr.reqType
108                         }
109                         tableData.push(dataTemp);
110                         } 
111                         this.appTable=tableData;
112                         if(tableData!=null){
113                                 var len = tableData.length;
114                                 this.totalPage =  Math.ceil(len/this.viewPerPage);     
115                         }
116                         if( $stateParams.appName != null)
117                                 this.searchString = $stateParams.appName;
118                         else
119                                 this.searchString = applicationsService.goGetAccessAppName;
120                         // the parameter has been used; clear the value.
121                         applicationsService.goGetAccessAppName = '';
122                 }).catch(err=> {
123                     $log.error('GetAccessCtrl:error:: ', err);
124                 }).finally(() => {
125                     this.isLoadingTable = false;
126                 });
127             };
128             
129             this.updateTable = (num) => {
130                 this.startIndex=this.viewPerPage*(num-1);
131                 this.currentPage = num;
132             };
133                 let init = () => {
134                 // $log.info('GetAccessCtrl:: initializing...');
135                 this.searchString = '';
136                 this.getAccessTableHeaders = ['Function', 'Application Name', 'Role Name', 'Current Role', 'Request Status'];
137                 this.appTable=[];
138                 this.updateAppsList();             
139                 this.viewPerPage=20;
140                 this.startIndex=0;
141                 this.currentPage = 1;
142                 this.totalPage=0;
143             };
144             init();
145         }
146     }
147     GetAccessCtrl.$inject = ['$log', '$scope', '$stateParams', 'filterFilter', 'getAccessService', 'userProfileService', 'ExternalRequestAccessService','applicationsService', 'ngDialog'];
148     angular.module('ecompApp').controller('GetAccessCtrl', GetAccessCtrl);
149 })();