section-review-trainee-list.component.ts 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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-section-review-trainee-list',
  12. templateUrl: './section-review-trainee-list.component.html',
  13. styleUrls: ['./section-review-trainee-list.component.css']
  14. })
  15. export class SectionReviewTraineeListComponent 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. private 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. defaultValueFiltter: string = 'all';
  39. ngOnInit() {
  40. this.spinner.show();
  41. //init the values of permision boolean
  42. this.authSer.showAddBtn = false;
  43. this.authSer.showDeleteBtn = false;
  44. this.authSer.showEditBtn = false;
  45. //show / hide notification search in header
  46. this.authSer.notificationLogin = true;
  47. this.authSer.showSearchHeader = false;
  48. this.authSer.showHeaderLogin = false;
  49. this.authSer.showHeaderDashBoard = true;
  50. this.authSer.showDashboardHeader = true;
  51. this.authSer.internalHeader = false;
  52. this.route.params.subscribe(
  53. (params:Params) => {
  54. this.pageId = params['listPageId'];
  55. localStorage.setItem('pageIdActive', params['listPageId']);
  56. },
  57. );
  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 == 36) {
  73. if(this.pages[i]['permissions'][0].name == 'review_of_trainee_data_for_department') {
  74. this.authSer.showAddBtn = true;
  75. this.authSer.showEditBtn = true;
  76. this.authSer.showDeleteBtn = true;
  77. } else {
  78. console.log('no permissions');
  79. }
  80. } else {
  81. console.log('no events');
  82. }
  83. }
  84. this.spinner.hide();
  85. },
  86. (error) => {console.log(error)}
  87. );
  88. }
  89. );
  90. //get list data
  91. this.dashBoardService.getListData(this.pageId, this.currentPage ,this.dataTableNumber).subscribe(
  92. (responce) => {
  93. console.log(responce);
  94. this.dataList = responce['requests'];
  95. if(this.dataList.length == 0) {
  96. this.toastr.warning('القائمه فارغه من الطلبات ');
  97. }
  98. this.count = responce['count'];
  99. this.perPagePagenation = responce['per_page'];
  100. console.log('evennnnts', this.dataList);
  101. this.spinner.hide();
  102. },
  103. (error) => {
  104. console.log(error);
  105. this.spinner.hide();
  106. }
  107. );
  108. }
  109. );
  110. }
  111. //filtter function
  112. filtterFunc(data) {
  113. this.dataList = [];
  114. console.log(data.target.value);
  115. const dataSearch = data.target.value;
  116. this.currentPage = 1;
  117. this.dashBoardService.getDataUSerSearchBar(dataSearch, this.pageId, this.currentPage, this.dataTableNumber).subscribe(
  118. (responce) => {
  119. console.log(responce);
  120. this.dataList = responce['requests'];
  121. this.count = responce['count'];
  122. this.perPagePagenation = responce['per_page'];
  123. console.log('filtter count', this.count);
  124. console.log('filtter perPagePAgenation', this.perPagePagenation);
  125. },
  126. (error) => {
  127. console.log(error)
  128. }
  129. );
  130. };
  131. //change page
  132. onPageChange(pagenationNumber) {
  133. this.spinner.show();
  134. this.currentPage = pagenationNumber;
  135. this.dataList = [];
  136. //console.log(pagenationNumber);
  137. //console.log(this.pageId);
  138. this.dashBoardService.getListData(this.pageId, pagenationNumber, this.dataTableNumber).subscribe(
  139. (responce) => {
  140. console.log(responce);
  141. this.dataList = responce['requests'];
  142. this.count = responce['count'];
  143. this.perPagePagenation = responce['per_page'];
  144. console.log(this.dataList);
  145. this.spinner.hide();
  146. },
  147. (error) => {
  148. console.log(error);
  149. this.spinner.hide();
  150. }
  151. );
  152. }
  153. //determine the list count from select element
  154. onGetValue(event) {
  155. this.spinner.show();
  156. this.dataList = [];
  157. this.dataTableNumber = event.target.value;
  158. this.dashBoardService.getListData(this.pageId, this.currentPage, this.dataTableNumber).subscribe(
  159. (responce) => {
  160. console.log(responce);
  161. this.dataList = responce['requests'];
  162. this.count = responce['count'];
  163. this.perPagePagenation = responce['per_page'];
  164. this.spinner.hide();
  165. },
  166. (error) => {
  167. console.log(error);
  168. this.spinner.hide();
  169. }
  170. );
  171. };
  172. onFiltterChosen(event) {
  173. this.spinner.show();
  174. this.dataList = [];
  175. console.log(event.target.value);
  176. console.log(this.authSer.pathApi + '/page_list/' +this.pageId + '/' + this.currentPage + '/' + this.dataTableNumber + '/' + event.target.value);
  177. this.http.get(this.authSer.pathApi + '/page_list/' +this.pageId + '/' + this.currentPage + '/' + this.dataTableNumber + '/' + event.target.value).subscribe(
  178. (responce) => {
  179. console.log(responce);
  180. console.log(responce);
  181. this.dataList = responce['requests'];
  182. this.count = responce['count'];
  183. this.perPagePagenation = responce['per_page'];
  184. this.spinner.hide();
  185. },
  186. (error) => {
  187. console.log(error);
  188. }
  189. )
  190. }
  191. //edit function
  192. onEdit(editPageID) {
  193. this.router.navigate(['service/' + this.userLoginId + '/' + this.serviceId + '/' + 'reviewSectionForTrainee/edit/' + editPageID]);
  194. }
  195. }