1 import { Component, OnInit, Directive, Input, Output, EventEmitter, ViewChildren, QueryList, PipeTransform, ViewChild } from '@angular/core';
2 import { AdminService } from '../admin.service';
3 import {UserService} from '../../../shared/services/user/user.service'
4 import { User } from 'src/app/shared/services/user/user';
5 import { of, Observable } from 'rxjs';
6 import { RoleFunction } from './role-function';
7 import { MatTableDataSource } from '@angular/material/table';
8 import { MatPaginator } from '@angular/material/paginator';
9 import { MatSort } from '@angular/material/sort';
10 import { InformationModalComponent } from 'src/app/modals/information-modal/information-modal.component';
11 import { NgbModal, ModalDismissReasons } from '@ng-bootstrap/ng-bootstrap';
14 selector: 'app-role-functions',
15 templateUrl: './role-functions.component.html',
16 styleUrls: ['./role-functions.component.scss']
18 export class RoleFunctionsComponent implements OnInit {
20 tableData: Array<RoleFunction> = [];
23 function:RoleFunction;
29 roleFunctionHeaders = ["name","code","type","action","edit","delete"];
30 dataSource: MatTableDataSource<RoleFunction>;
32 constructor(public adminService: AdminService, public userService: UserService,private ngModal: NgbModal) { }
34 @ViewChild(MatPaginator, {}) paginator: MatPaginator;
35 @ViewChild(MatSort, {}) sort: MatSort;
38 this.getRoleFunctions();
39 let result = this.userService.getFunctionalMenuStaticDetailSession();
41 result.subscribe(user => {
43 this.isAppCentralized = this.user.isAppCentralized;
50 this.response = this.adminService.getRoleFunctionList();
51 this.response.subscribe(data => {
53 this.result = JSON.parse(response.data);
54 this.tableData = JSON.parse(this.result.availableRoleFunctions);
55 this.dataSource = new MatTableDataSource(this.tableData);
56 this.dataSource.paginator = this.paginator;
57 this.dataSource.sort = this.sort;
63 applyFilter(filterValue: string) {
64 this.dataSource.filter = filterValue.trim().toLowerCase();
66 if (this.dataSource.paginator) {
67 this.dataSource.paginator.firstPage();
72 delRoleFunction(item: any) {
73 const modalRef = this.ngModal.open(InformationModalComponent);
74 modalRef.componentInstance.title = 'Confirmation';
76 modalRef.componentInstance.message = `Are you sure you want to delete ${item.name} ?`;
77 modalRef.result.then((result) => {
78 if (result === 'Ok') {
79 this.adminService.deleteRoleFunction(item).subscribe(data => {
81 if(response ='SUCCESS')
83 this.getRoleFunctions();
88 this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
92 private getDismissReason(reason: any): string {
93 if (reason === ModalDismissReasons.ESC) {
94 return 'by pressing ESC';
95 } else if (reason === ModalDismissReasons.BACKDROP_CLICK) {
96 return 'by clicking on a backdrop';
98 return `with: ${reason}`;