diff options
author | Sunder Tattavarada <statta@research.att.com> | 2020-07-28 16:56:24 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-07-28 16:56:24 +0000 |
commit | 4d79935df7115dc063a9191a0186d6f834838c69 (patch) | |
tree | 8782d041c6624bc49f50a32acd7ad9072e29a20a /ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/admin/roles/roles.component.ts | |
parent | 382c506e61f11d9ebf41d2c90fc7794a3bb71900 (diff) | |
parent | 05af2c42b57d71d375ba2e50fd10a3fd682ea226 (diff) |
Merge "Integrated UI lazy loading and Raptor update"
Diffstat (limited to 'ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/admin/roles/roles.component.ts')
-rw-r--r-- | ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/admin/roles/roles.component.ts | 216 |
1 files changed, 216 insertions, 0 deletions
diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/admin/roles/roles.component.ts b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/admin/roles/roles.component.ts new file mode 100644 index 00000000..8032aa18 --- /dev/null +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/admin/roles/roles.component.ts @@ -0,0 +1,216 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ +import { Component, OnInit, ViewChild } from '@angular/core'; +import { AdminService } from '../admin.service'; +import { MatTableDataSource } from '@angular/material/table'; +import { MatSort } from '@angular/material/sort'; +import { MatPaginator } from '@angular/material/paginator'; +import { User } from 'src/app/shared/services/user/user'; +import { UserService } from 'src/app/shared/services/user/user.service'; +import { NgbModal, ModalDismissReasons } from '@ng-bootstrap/ng-bootstrap'; +import { InformationModalComponent } from 'src/app/modals/information-modal/information-modal.component'; +import { NewRoleComponent } from './new-role/new-role.component'; +import { Router } from '@angular/router'; + + +@Component({ + selector: 'app-roles', + templateUrl: './roles.component.html', + styleUrls: ['./roles.component.scss'] +}) +export class RolesComponent implements OnInit { + tableData: Array<object> = []; + roleHeaders: Array<string> = []; + constructor(public adminService:AdminService,public userService: UserService,private ngbModal: NgbModal,private _router: Router) { } + roleId; + response:any; + result:any; + roleInfo:any; + roleData:any; + ociavailableRoleFunctions; + availableRoleFunctions; + availableRoles; + dataSource: MatTableDataSource<[]>; + user:User; + isAppCentralized; + closeResult: string; + isEditMode: boolean = false; + showSpinner:boolean; + + @ViewChild(MatPaginator, {}) paginator: MatPaginator; + @ViewChild(MatSort, {}) sort: MatSort; + + + ngOnInit() { + this.roleHeaders = ["name","priority","Edit","Active?","Delete?"]; + this.showSpinner = false; + this.roleId=undefined; + this.getRole(this.roleId); + let result = this.userService.getFunctionalMenuStaticDetailSession(); + let user; + result.subscribe(user => { + this.user = user; + this.isAppCentralized = this.user.isAppCentralized; + }); + } + + getRole(roleId:any){ + this.showSpinner = true; + this.response = this.adminService.getRole(roleId); + this.response.subscribe(data => { + this.result = data; + this.roleInfo = JSON.parse(this.result.data); + this.roleData =JSON.parse(this.roleInfo.role); + this.ociavailableRoleFunctions =JSON.parse(this.roleInfo.availableRoleFunctions); + this.availableRoleFunctions=[]; + for( let availableFun of this.ociavailableRoleFunctions){ + let availableRoleFunction = availableFun; + availableRoleFunction.selected = false; + for( let availableFunc of this.roleData.roleFunctions){ + if(availableFun.code === availableFunc.code){ + availableRoleFunction.selected = true; + } + } + this.availableRoleFunctions.push(availableRoleFunction); + } + this.availableRoles=JSON.parse(this.roleInfo.availableRoles); + this.dataSource = new MatTableDataSource(this.availableRoles); + this.dataSource.paginator = this.paginator; + this.dataSource.sort = this.sort; + this.showSpinner = false; + }); + } + + delRoleConfirmPopUp(item: any) { + const modalRef = this.ngbModal.open(InformationModalComponent); + modalRef.componentInstance.title = 'Confirmation'; + let response; + modalRef.componentInstance.message = `Are you sure you want to delete ${item.name} ?`; + modalRef.result.then((result) => { + if (result === 'Ok') { + this.adminService.deleteRole(item).subscribe(data => { + this.showSpinner = true; + response = data; + this.availableRoles = response.availableRoles; + this.dataSource = new MatTableDataSource(this.availableRoles); + this.dataSource.paginator = this.paginator; + this.dataSource.sort = this.sort; + this.showSpinner = false; + }) + } + }, (reason) => { + this.closeResult = `Dismissed ${this.getDismissReason(reason)}`; + }); + } + + private getDismissReason(reason: any): string { + if (reason === ModalDismissReasons.ESC) { + return 'by pressing ESC'; + } else if (reason === ModalDismissReasons.BACKDROP_CLICK) { + return 'by clicking on a backdrop'; + } else { + return `with: ${reason}`; + } + + } + + /** + * openAddNewRoleModal + * @param rowData + */ + openAddNewRoleModal(rowData: any){ + const modalRef = this.ngbModal.open(NewRoleComponent, { size: 'lg' }); + modalRef.componentInstance.title = 'Role Details'; + modalRef.componentInstance.availableRoles = this.availableRoles; + modalRef.componentInstance.ociavailableRoleFunctions = this.ociavailableRoleFunctions; + if(rowData != 'undefined' && rowData){ + modalRef.componentInstance.role = rowData; + this.isEditMode = true; + modalRef.componentInstance.isEditMode = true; + }else{ + modalRef.componentInstance.role = {}; + this.isEditMode = false; + modalRef.componentInstance.isEditMode = false; + } + modalRef.componentInstance.passEntry.subscribe((receivedEntry: any) => { + if(receivedEntry){ + this.availableRoles = []; + this.getRole(this.roleId); + } + }); + } + + toggleRole(_element) { + let activeOrInactive = (_element.active) ? 'activate' : 'inactivate'; + const modalInfoRef = this.ngbModal.open(InformationModalComponent); + modalInfoRef.componentInstance.title = 'Confirmation'; + modalInfoRef.componentInstance.message = 'You are about to ' + activeOrInactive + ' the role ' + _element.name + '. Do you want to continue?'; + modalInfoRef.result.then((_res) => { + if (_res === 'Ok') { + this.showSpinner = true; + let postData={ + role: _element, + childRoles: _element.childRoles, + roleFunctions : _element.roleFunctions + }; + this.adminService.saveRole(postData, _element.id) + .subscribe( _data => { + this.showSpinner = false; + }, (response) => { + _element.active = !_element.active; + const modalErrorRef = this.ngbModal.open(InformationModalComponent); + modalErrorRef.componentInstance.title = 'Error'; + modalErrorRef.componentInstance.message = 'Error while saving. ' + response.restCallStatus; + }); + } else { + _element.active = !_element.active; + } + + }, (result) => { + + }) + } + + applyFilter(filterValue: string) { + this.dataSource.filter = filterValue.trim().toLowerCase(); + } + + getFunctions() { + this._router.navigate(['v2/admin/role_function_list']); +} +}
\ No newline at end of file |