registration-trainee-movement-list.component.ts 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. import { DashboardService } from './../../../shared/dashboard.service';
  2. import { HttpClient } from '@angular/common/http';
  3. import { UserService } from './../../../shared/user.service';
  4. import { ActivatedRoute, Router, Params } from '@angular/router';
  5. import { NgxSpinnerService } from 'ngx-spinner';
  6. import { AuthServiceService } from './../../../shared/auth-service.service';
  7. import { Component, OnInit } from '@angular/core';
  8. import { ToastrService } from 'ngx-toastr';
  9. import { Modal } from 'ngx-modialog/plugins/bootstrap';
  10. @Component({
  11. selector: 'app-registration-trainee-movement-list',
  12. templateUrl: './registration-trainee-movement-list.component.html',
  13. styleUrls: ['./registration-trainee-movement-list.component.css']
  14. })
  15. export class RegistrationTraineeMovementListComponent implements OnInit {
  16. constructor(private route: ActivatedRoute,
  17. private router: Router,
  18. private userSer: UserService,
  19. private http: HttpClient,
  20. private toastr: ToastrService,
  21. private modal: Modal,
  22. private dashBoardService: DashboardService,
  23. private spinner: NgxSpinnerService,
  24. public authSer: AuthServiceService) { }
  25. pageId: number;
  26. dataList = [];
  27. dataListIds = [];
  28. count: number;
  29. perPagePagenation: number;
  30. currentPage:number = 1;
  31. filtterStatus = '';
  32. selectedAll: any;
  33. userLoginId:number;
  34. serviceId:number;
  35. dataTableNumber: number = 5;
  36. serviceName: string = '';
  37. pages = [];
  38. ngOnInit() {
  39. this.spinner.show();
  40. //init the values of permision boolean
  41. this.route.params.subscribe(
  42. (params:Params) => {
  43. this.pageId = +params['listPageId'];
  44. localStorage.setItem('pageIdActive', params['listPageId']);
  45. },
  46. );
  47. //init the values of permision boolean
  48. this.authSer.showAddBtn = false;
  49. this.authSer.showDeleteBtn = false;
  50. this.authSer.showEditBtn = false;
  51. //show / hide notification search in header
  52. this.authSer.notificationLogin = true;
  53. this.authSer.showSearchHeader = false;
  54. this.authSer.showHeaderLogin = false;
  55. this.authSer.showHeaderDashBoard = true;
  56. this.authSer.showDashboardHeader = true;
  57. this.authSer.internalHeader = false;
  58. //to show / hide permissions
  59. this.route.parent.params.subscribe(
  60. (params:Params) => {
  61. this.userLoginId = params['userID'];
  62. this.serviceId = params['serviceID'];
  63. this.route.parent.params.subscribe(
  64. (params:Params) => {
  65. this.userLoginId = params['userID'];
  66. this.serviceId = params['serviceID'];
  67. this.userSer.getPagesPermetiotns(this.userLoginId, this.serviceId).subscribe(
  68. (responce) => {
  69. console.log(responce);
  70. this.pages = responce['pages'];
  71. for(let i = 0; i< this.pages.length; i++) {
  72. if(this.pages[i].id == 38) {
  73. this.authSer.showAddBtn = true;
  74. this.authSer.showEditBtn = true;
  75. this.authSer.showDeleteBtn = true;
  76. } else {
  77. console.log('no events');
  78. }
  79. }
  80. this.spinner.hide();
  81. },
  82. (error) => {console.log(error)}
  83. );
  84. }
  85. );
  86. }
  87. );
  88. //get list data
  89. this.dashBoardService.getListData(this.pageId, this.currentPage ,this.dataTableNumber).subscribe(
  90. (responce) => {
  91. console.log('rescponce dataaaa', responce);
  92. this.dataList = responce['requests'];
  93. if(this.dataList.length == 0) {
  94. this.toastr.warning('القائمه فارغه من الطلبات ');
  95. }
  96. this.count = responce['count'];
  97. this.perPagePagenation = responce['per_page'];
  98. console.log('evennnnts', this.dataList);
  99. this.spinner.hide();
  100. },
  101. (error) => {
  102. console.log(error);
  103. this.spinner.hide();
  104. }
  105. );
  106. }
  107. //filtter function
  108. filtterFunc(data) {
  109. this.dataList = [];
  110. console.log(data.target.value);
  111. const dataSearch = data.target.value;
  112. this.currentPage = 1;
  113. this.dashBoardService.getDataUSerSearchBar(dataSearch, this.pageId, this.currentPage, this.dataTableNumber).subscribe(
  114. (responce) => {
  115. console.log(responce);
  116. this.dataList = responce['requests'];
  117. this.count = responce['count'];
  118. this.perPagePagenation = responce['per_page'];
  119. console.log('filtter count', this.count);
  120. console.log('filtter perPagePAgenation', this.perPagePagenation);
  121. },
  122. (error) => {
  123. console.log(error)
  124. }
  125. );
  126. };
  127. //change page
  128. onPageChange(pagenationNumber) {
  129. this.spinner.show();
  130. this.currentPage = pagenationNumber;
  131. this.dataList = [];
  132. //console.log(pagenationNumber);
  133. //console.log(this.pageId);
  134. this.dashBoardService.getListData(this.pageId, pagenationNumber, this.dataTableNumber).subscribe(
  135. (responce) => {
  136. console.log(responce);
  137. this.dataList = responce['requests'];
  138. this.count = responce['count'];
  139. this.perPagePagenation = responce['per_page'];
  140. console.log(this.dataList);
  141. this.spinner.hide();
  142. },
  143. (error) => {
  144. console.log(error);
  145. this.spinner.hide();
  146. }
  147. );
  148. }
  149. //determine the list count from select element
  150. onGetValue(event) {
  151. this.spinner.show();
  152. this.dataList = [];
  153. this.dataTableNumber = event.target.value;
  154. this.dashBoardService.getListData(this.pageId, this.currentPage, this.dataTableNumber).subscribe(
  155. (responce) => {
  156. console.log(responce);
  157. this.dataList = responce['requests'];
  158. this.count = responce['count'];
  159. this.perPagePagenation = responce['per_page'];
  160. this.spinner.hide();
  161. },
  162. (error) => {
  163. console.log(error);
  164. this.spinner.hide();
  165. }
  166. );
  167. };
  168. //edit function
  169. onEdit(editPageID) {
  170. this.router.navigate(['service/' + this.userLoginId + '/' + this.serviceId + '/' + 'registrationTraineeList/edit/' + editPageID]);
  171. }
  172. }