c9893bf2e9f2409e18e0246a59254a6517904cce
[portal/sdk.git] /
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';
12
13 @Component({
14   selector: 'app-role-functions',
15   templateUrl: './role-functions.component.html',
16   styleUrls: ['./role-functions.component.scss']
17 })
18 export class RoleFunctionsComponent implements OnInit {
19
20   tableData: Array<RoleFunction> = [];
21         response: any;
22   result: any;
23   function:RoleFunction;
24   
25   isAppCentralized:any;
26   user: User;
27   closeResult: string;
28
29   roleFunctionHeaders = ["name","code","type","action","edit","delete"];
30   dataSource: MatTableDataSource<RoleFunction>;
31
32   constructor(public adminService: AdminService, public userService: UserService,private ngModal: NgbModal) { }
33   
34   @ViewChild(MatPaginator, {}) paginator: MatPaginator;
35   @ViewChild(MatSort, {}) sort: MatSort;
36
37         ngOnInit() {
38    this.getRoleFunctions(); 
39       let result = this.userService.getFunctionalMenuStaticDetailSession();
40       let user;
41         result.subscribe(user => {
42         this.user = user;
43         this.isAppCentralized = this.user.isAppCentralized;
44       });
45     }
46
47     getRoleFunctions(){
48
49       let response;
50       this.response = this.adminService.getRoleFunctionList();
51       this.response.subscribe(data => {
52       response = 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;
58      
59     });
60
61     }
62
63     applyFilter(filterValue: string) {
64       this.dataSource.filter = filterValue.trim().toLowerCase();
65   
66       if (this.dataSource.paginator) {
67         this.dataSource.paginator.firstPage();
68       }
69     }
70
71
72     delRoleFunction(item: any) {
73       const modalRef = this.ngModal.open(InformationModalComponent);
74       modalRef.componentInstance.title = 'Confirmation';
75       let response;
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 => {
80             response = data;
81             if(response ='SUCCESS')
82             {
83               this.getRoleFunctions(); 
84             }       
85           })
86         }
87       }, (reason) => {
88         this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
89       });
90     }
91   
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';
97       } else {
98         return `with: ${reason}`;
99       }
100   
101   }
102   
103 }