Changes made to upgrade pom version
[portal.git] / portal-FE-common / src / app / pages / get-access / get-access.component.ts
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2019 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  * 
37  */
38
39 import { Component, OnInit, ViewChild } from '@angular/core';
40 import { GetAccessService } from 'src/app/shared/services/get-access/get-access.service';
41 import { MatTableDataSource, MatPaginator } from '@angular/material';
42 import { environment } from '../../../environments/environment';
43
44 @Component({
45   selector: 'app-get-access',
46   templateUrl: './get-access.component.html',
47   styleUrls: ['./get-access.component.scss']
48 })
49 export class GetAccessComponent implements OnInit {
50   isLoadingTable: boolean;
51   appTable: any[];
52   displayedColumns: string[] = ['function', 'applicationName', 'roleName', 'currentRole', 'requestStatus'];
53   getAccessDataSource = new MatTableDataSource(this.appTable);
54   @ViewChild(MatPaginator) paginator: MatPaginator;
55   showSpinner: boolean;
56   getAccessUrl = environment.getAccessUrl;
57   getAccessName = environment.getAccessName;
58   getAccessInfo = environment.getAccessInfo;
59
60   constructor(private getAccessService: GetAccessService) { }
61
62   ngOnInit() {
63     this.appTable = [];
64     this.getAccessAppsList();
65   }
66
67   applyFilter(filterValue: string) {
68     this.getAccessDataSource.filter = filterValue.trim().toLowerCase();
69   }
70   
71   // Convert this code to typescript after mylogins feature is back again
72   // var resultAccessValue = null;
73         
74   // $scope.openAppRoleModal = (itemData) => {          
75   //   if(resultAccessValue){
76   //   let data = null;
77   //           data = {
78   //               dialogState: 2,
79   //               selectedUser:{
80   //                   orgUserId: $scope.orgUserId,
81   //                   firstName: $scope.firstName,
82   //                   lastName: $scope.lastName,
83   //                   headerText: itemData.app_name,
84   //               }
85   //           }
86   //       ngDialog.open({
87   //           templateUrl: 'app/views/catalog/request-access-catalog-dialogs/request-access-catalog.modal.html',
88   //           controller: 'ExternalRequestAccessCtrl',
89   //           controllerAs: 'userInfo',
90   //           data: data
91   //       });
92   //   }
93   //   }
94   
95   //   userProfileService.getUserProfile().then(
96   //     function(profile) {
97   //       $scope.orgUserId = profile.orgUserId;
98   //       $scope.firstName = profile.firstName;
99   //       $scope.lastName = profile.lastName;
100   //   });
101
102   getAccessAppsList() {
103     this.showSpinner = true;
104     this.getAccessService.getListOfApp().subscribe((_res: any) => {
105       var tableData = [];
106       // $log.info('GetAccessCtrl::updateAppsList: getting res');
107       var result = (typeof (_res) != "undefined" && _res != null) ? _res : null;
108       this.showSpinner = false;
109       // $log.info('GetAccessCtrl::updateAppsList: result',result);
110       // $log.info('GetAccessCtrl::updateAppsList: done');
111       var source = result;
112       // $log.info('GetAccessCtrl::updateAppsList source: ', source);
113       for (var i = 0; i < source.length; i++) {
114         var dataArr = source[i];
115         var checkEcompFuncAvail = 'Function Not Available';
116         var reqStatus = 'Pending';
117         dataArr.ecompFunction = (dataArr.ecompFunction === null) ? checkEcompFuncAvail : dataArr.ecompFunction;
118         dataArr.reqType = (dataArr.reqType === 'P') ? reqStatus : dataArr.reqType;
119         var dataTemp = {
120           ecomp_function: dataArr.ecompFunction,
121           app_name: dataArr.appName,
122           role_name: dataArr.roleName,
123           current_role: dataArr.roleActive,
124           request_type: dataArr.reqType
125         }
126         tableData.push(dataTemp);
127       }
128       this.appTable = tableData;
129       this.getAccessDataSource = new MatTableDataSource(this.appTable);
130       this.getAccessDataSource.paginator = this.paginator;
131     }, (_err) => {
132       this.isLoadingTable = false;
133     })
134   }
135 }