report-list.component.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import { ReportService } from './../../shared/report.service';
  2. import { AuthServiceService } from './../../shared/auth-service.service';
  3. import { HttpClient } from '@angular/common/http';
  4. import { UserService } from './../../shared/user.service';
  5. import { ActivatedRoute, Params, Router } from '@angular/router';
  6. import { ToastrService } from 'ngx-toastr';
  7. import { NgxSpinnerService } from 'ngx-spinner';
  8. import { Component, OnInit } from '@angular/core';
  9. @Component({
  10. selector: 'app-report-list',
  11. templateUrl: './report-list.component.html',
  12. styleUrls: ['./report-list.component.css']
  13. })
  14. export class ReportListComponent implements OnInit {
  15. constructor(private route: ActivatedRoute,
  16. private userSer: UserService,
  17. private router: Router,
  18. public authSer: AuthServiceService,
  19. private toastr: ToastrService,
  20. private reportService:ReportService,
  21. private spinner: NgxSpinnerService,
  22. private http: HttpClient) { }
  23. reportType: string;
  24. permissionsTable:boolean = false;
  25. pagesTable:boolean = false;
  26. name:string = '';
  27. usersList = [];
  28. rolesList= [];
  29. roleValue:number;
  30. serviceId: number;
  31. userLoginId:number;
  32. typeRoleReport:string //to determine the type 0f report of role
  33. ngOnInit() {
  34. this.userSer.getUserDataProfile();
  35. //show / hide notification search in header
  36. this.authSer.notificationLogin = true;
  37. this.authSer.showSearchHeader = false;
  38. this.authSer.showHeaderLogin = false;
  39. this.authSer.showHeaderDashBoard = true;
  40. this.authSer.showDashboardHeader = true;
  41. this.authSer.internalHeader = false;
  42. this.route.parent.params.subscribe(
  43. (params:Params) => {
  44. this.userLoginId = params['userID'];
  45. this.serviceId = params['serviceID'];
  46. }
  47. );
  48. this.route.params.subscribe(
  49. (params: Params) => {
  50. this.reportType = params['reportName'];
  51. if(this.reportType == 'reportPermissions') {
  52. //this.permissionsTable = true;
  53. } else if(this.reportType == 'reportPages') {
  54. this.typeRoleReport = 'reportPages';
  55. this.spinner.show();
  56. this.pagesTable = true;
  57. this.http.get(this.authSer.pathApi + '/roles_list').subscribe(
  58. (responce) => {
  59. console.log(responce);
  60. this.rolesList = responce['roles'];
  61. console.log(this.rolesList);
  62. this.spinner.hide();
  63. }
  64. )
  65. } else if(this.reportType == "reportUsers") {
  66. this.spinner.show();
  67. this.typeRoleReport = 'reportUsers';
  68. this.pagesTable = true;
  69. this.http.get(this.authSer.pathApi + '/roles_list').subscribe(
  70. (responce) => {
  71. console.log(responce);
  72. this.rolesList = responce['roles'];
  73. console.log(this.rolesList);
  74. this.spinner.hide();
  75. }
  76. );
  77. }
  78. }
  79. );
  80. }
  81. onSearchName() {
  82. this.spinner.show();
  83. console.log(this.name);
  84. this.http.get(this.authSer.pathApi + '/find_user/' + this.name).subscribe(
  85. (responce) => {
  86. console.log('reprt data ', responce);
  87. if(responce['user'] == null) {
  88. this.toastr.warning('لا يوجد مستخدمين بهذا الاسم');
  89. } else {
  90. this.usersList = responce['user'];
  91. this.permissionsTable = true;
  92. console.log(this.usersList);
  93. }
  94. this.spinner.hide();
  95. },
  96. (error) => {
  97. console.log(error);
  98. }
  99. );
  100. };
  101. onGetRoles(roleVal) {
  102. console.log(roleVal);
  103. this.roleValue = roleVal;
  104. }
  105. //on get user report
  106. onGetReport(user_id) {
  107. console.log(user_id);
  108. this.router.navigate(['service/' + this.userLoginId + '/' + this.serviceId + '/userreport/' + user_id]);
  109. }
  110. getRoleReport() {
  111. if(this.typeRoleReport == 'reportPages') {
  112. this.router.navigate(['service/' + this.userLoginId + '/' + this.serviceId + '/roleReport/' + this.roleValue]);
  113. } else if(this.typeRoleReport == 'reportUsers') {
  114. this.router.navigate(['service/' + this.userLoginId + '/' + this.serviceId + '/userInRoleReport/' + this.roleValue]);
  115. }
  116. }
  117. }