5edd17b9a4351aabb291b2a233b76bc5e59ca6f9
[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   api = environment.api;
51   isLoadingTable: boolean;
52   appTable: any[];
53   displayedColumns: string[] = ['function', 'applicationName', 'roleName', 'currentRole', 'requestStatus'];
54   getAccessDataSource = new MatTableDataSource(this.appTable);
55   @ViewChild(MatPaginator) paginator: MatPaginator;
56   showSpinner: boolean;
57   getAccessUrl = this.api.getAccessUrl;
58   getAccessName = this.api.getAccessName;
59   getAccessInfo = this.api.getAccessInfo;
60
61   constructor(private getAccessService: GetAccessService) { }
62
63   ngOnInit() {
64     this.appTable = [];
65     this.getAccessAppsList();
66   }
67
68   applyFilter(filterValue: string) {
69     this.getAccessDataSource.filter = filterValue.trim().toLowerCase();
70   }
71   
72   // Convert this code to typescript after mylogins feature is back again
73   // var resultAccessValue = null;
74         
75   // $scope.openAppRoleModal = (itemData) => {          
76   //   if(resultAccessValue){
77   //   let data = null;
78   //           data = {
79   //               dialogState: 2,
80   //               selectedUser:{
81   //                   orgUserId: $scope.orgUserId,
82   //                   firstName: $scope.firstName,
83   //                   lastName: $scope.lastName,
84   //                   headerText: itemData.app_name,
85   //               }
86   //           }
87   //       ngDialog.open({
88   //           templateUrl: 'app/views/catalog/request-access-catalog-dialogs/request-access-catalog.modal.html',
89   //           controller: 'ExternalRequestAccessCtrl',
90   //           controllerAs: 'userInfo',
91   //           data: data
92   //       });
93   //   }
94   //   }
95   
96   //   userProfileService.getUserProfile().then(
97   //     function(profile) {
98   //       $scope.orgUserId = profile.orgUserId;
99   //       $scope.firstName = profile.firstName;
100   //       $scope.lastName = profile.lastName;
101   //   });
102
103   getAccessAppsList() {
104     this.showSpinner = true;
105     this.getAccessService.getListOfApp().subscribe((_res: any) => {
106       var tableData = [];
107       // $log.info('GetAccessCtrl::updateAppsList: getting res');
108       var result = (typeof (_res) != "undefined" && _res != null) ? _res : null;
109       this.showSpinner = false;
110       // $log.info('GetAccessCtrl::updateAppsList: result',result);
111       // $log.info('GetAccessCtrl::updateAppsList: done');
112       var source = result;
113       // $log.info('GetAccessCtrl::updateAppsList source: ', source);
114       for (var i = 0; i < source.length; i++) {
115         var dataArr = source[i];
116         var checkEcompFuncAvail = 'Function Not Available';
117         var reqStatus = 'Pending';
118         dataArr.ecompFunction = (dataArr.ecompFunction === null) ? checkEcompFuncAvail : dataArr.ecompFunction;
119         dataArr.reqType = (dataArr.reqType === 'P') ? reqStatus : dataArr.reqType;
120         var dataTemp = {
121           ecomp_function: dataArr.ecompFunction,
122           app_name: dataArr.appName,
123           role_name: dataArr.roleName,
124           current_role: dataArr.roleActive,
125           request_type: dataArr.reqType
126         }
127         tableData.push(dataTemp);
128       }
129       this.appTable = tableData;
130       this.getAccessDataSource = new MatTableDataSource(this.appTable);
131       this.getAccessDataSource.paginator = this.paginator;
132     }, (_err) => {
133       this.isLoadingTable = false;
134     })
135   }
136 }