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