2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
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
26 * https://creativecommons.org/licenses/by/4.0/
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.
34 * ============LICENSE_END============================================
38 import { Component, OnInit, ViewChild } from '@angular/core';
39 import { RoleService, ApplicationsService } from 'src/app/shared/services';
40 import { MatTableDataSource, MatPaginator, MatSort } from '@angular/material';
41 import { RoleFunctionModalComponent } from './role-function-modal/role-function-modal.component';
42 import { NgbModal, ModalDismissReasons } from '@ng-bootstrap/ng-bootstrap';
43 import { InformationModalComponent } from 'src/app/modals/information-modal/information-modal.component';
44 import { ConfirmationModalComponent } from 'src/app/modals/confirmation-modal/confirmation-modal.component';
45 import { HttpClient } from '@angular/common/http';
46 import { environment } from 'src/environments/environment';
49 selector: 'app-role-functions',
50 templateUrl: './role-functions.component.html',
51 styleUrls: ['./role-functions.component.scss']
53 export class RoleFunctionsComponent implements OnInit {
56 selectedCentralizedApp: any;
57 availableRoleFunctions: any;
58 displayedColumns: string[] = ['type', 'instance', 'action', 'name', 'edit', 'delete'];
59 roleFunctionsDataSource = new MatTableDataSource(this.availableRoleFunctions);
60 @ViewChild(MatSort) sort: MatSort;
61 @ViewChild(MatPaginator) paginator: MatPaginator;
64 constructor(public ngbModal: NgbModal,private roleService: RoleService, private applicationsService: ApplicationsService, public http: HttpClient) {}
67 this.availableRoleFunctions = [];
68 this.centralizedApps = [];
69 this.getCentralizedApps(sessionStorage.userId);
72 syncRolesFromExternalAuthSystem() {
73 this.applicationsService.syncRolesEcompFromExtAuthSystem(this.selectedCentralizedApp).toPromise().then((res: any) => {
74 if (res.status == 'OK') {
75 const modalInfoRef = this.ngbModal.open(InformationModalComponent);
76 modalInfoRef.componentInstance.title = 'Success';
77 modalInfoRef.componentInstance.message = 'Sync role functions completed successfully!';
78 modalInfoRef.result.then((_res) => {
80 this.getRoleFunctions(this.selectedCentralizedApp);
85 this.openConfirmationModal('Error', 'Sync failed ' + res.message);
88 this.openConfirmationModal('Error', 'Sync failed' + err);
94 getCentralizedApps(userId) {
95 this.roleService.getCentralizedApps(userId).toPromise().then((res: any) => {
97 this.centralizedApps = res;
98 this.selectedCentralizedApp = this.centralizedApps[0].appId;
99 this.getRoleFunctions(this.centralizedApps[0].appId);
102 // $log.error('RoleListCtrl::centralizedApps retrieval error: ', err);
104 // this.isLoadingTable = false;
108 getRoleFunctions(id) {
109 this.showSpinner = true;
110 this.roleService.getRoleFunctionList(id).subscribe((data: any) => {
111 this.showSpinner = false;
113 var roleFunctions = JSON.parse(j.data);
114 this.availableRoleFunctions = roleFunctions.availableRoleFunctions;
115 this.roleFunctionsDataSource = new MatTableDataSource(this.availableRoleFunctions);
116 this.roleFunctionsDataSource.sort = this.sort;
117 this.roleFunctionsDataSource.paginator = this.paginator;
119 this.showSpinner = false;
120 this.openConfirmationModal('Error', 'Failed to get role functions. Please try again!' + error.message);
124 addRoleFunctionModalPopup(){
125 const modalInfoRef = this.ngbModal.open(RoleFunctionModalComponent);
126 modalInfoRef.componentInstance.title = 'Add Role Function';
127 modalInfoRef.componentInstance.appId = this.selectedCentralizedApp;
128 modalInfoRef.componentInstance.currentRoleFunctions = this.availableRoleFunctions;
129 modalInfoRef.componentInstance.passBackRoleFunctionPopup.subscribe((_result: any) => {
131 modalInfoRef.close();
132 this.availableRoleFunctions.push(_result);
133 this.roleFunctionsDataSource = new MatTableDataSource(this.availableRoleFunctions);
134 this.roleFunctionsDataSource.sort = this.sort;
135 this.roleFunctionsDataSource.paginator = this.paginator;
137 }, (_reason: any) => {
143 editRoleFunctionModalPopup(_element){
144 const modalInfoRef = this.ngbModal.open(RoleFunctionModalComponent);
145 modalInfoRef.componentInstance.title = 'Edit Role Function';
146 modalInfoRef.componentInstance.appId = this.selectedCentralizedApp;
147 modalInfoRef.componentInstance.editRoleFunction = _element;
148 modalInfoRef.componentInstance.currentRoleFunctions = this.availableRoleFunctions;
149 modalInfoRef.componentInstance.passBackRoleFunctionPopup.subscribe((_result: any) => {
151 modalInfoRef.close();
152 this.availableRoleFunctions.splice(this.availableRoleFunctions.indexOf(_element), 1);
153 this.availableRoleFunctions.push(_result);
154 this.roleFunctionsDataSource = new MatTableDataSource(this.availableRoleFunctions);
155 this.roleFunctionsDataSource.sort = this.sort;
156 this.roleFunctionsDataSource.paginator = this.paginator;
158 }, (_reason: any) => {
163 removeRoleFunction(_element: any){
164 const ngbInfoModal = this.ngbModal.open(InformationModalComponent);
165 ngbInfoModal.componentInstance.title = 'Confirmation';
166 ngbInfoModal.componentInstance.message = 'You are about to delete the role function ' + _element.name + '. Do you want to continue?';
167 ngbInfoModal.result.then(_res =>{
169 this.showSpinner = true;
170 var uuu = this.api.removeRoleFunction.replace(':appId', this.selectedCentralizedApp);
171 var postData = _element;
172 this.http.post(uuu, postData).subscribe((response: any) => {
173 this.showSpinner = false;
174 if(response.status == 'OK'){
175 this.openConfirmationModal('Success', response.message);
176 this.availableRoleFunctions.splice(this.availableRoleFunctions.indexOf(_element), 1);
177 this.roleFunctionsDataSource = new MatTableDataSource(this.availableRoleFunctions);
178 this.roleFunctionsDataSource.sort = this.sort;
179 this.roleFunctionsDataSource.paginator = this.paginator;
181 this.showSpinner = false;
182 this.openConfirmationModal('Error', "Error while deleting: " + response.message);
185 this.showSpinner = false;
186 this.openConfirmationModal('Error', err.message);
189 }, (_reason: any) => {
194 openConfirmationModal(_title: string, _message: string) {
195 const modalInfoRef = this.ngbModal.open(ConfirmationModalComponent);
196 modalInfoRef.componentInstance.title = _title;
197 modalInfoRef.componentInstance.message = _message;