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