review-trainee-data-list.component.ts 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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-review-trainee-data-list',
  12. templateUrl: './review-trainee-data-list.component.html',
  13. styleUrls: ['./review-trainee-data-list.component.css']
  14. })
  15. export class ReviewTraineeDataListComponent 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. viewTableData: string = 'all';
  37. serviceName: string = '';
  38. pages = [];
  39. ngOnInit() {
  40. this.spinner.show();
  41. //init the values of permision boolean
  42. this.route.params.subscribe(
  43. (params: Params) => {
  44. this.pageId = params['newsPageId'];
  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. this.route.params.subscribe(
  59. (params: Params) => {
  60. this.pageId = params['reviewTrainerId'];
  61. }
  62. );
  63. //to show / hide permissions
  64. this.route.parent.params.subscribe(
  65. (params:Params) => {
  66. this.userLoginId = params['userID'];
  67. this.serviceId = params['serviceID'];
  68. this.route.parent.params.subscribe(
  69. (params:Params) => {
  70. this.userLoginId = params['userID'];
  71. this.serviceId = params['serviceID'];
  72. this.userSer.getPagesPermetiotns(this.userLoginId, this.serviceId).subscribe(
  73. (responce) => {
  74. console.log(responce);
  75. this.pages = responce['pages'];
  76. for(let i = 0; i< this.pages.length; i++) {
  77. if(this.pages[i].id == 35) {
  78. if(this.pages[i]['permissions'][0].name == 'review_of_trainee_data') {
  79. this.authSer.showAddBtn = true;
  80. this.authSer.showEditBtn = true;
  81. this.authSer.showDeleteBtn = true;
  82. } else {
  83. console.log('no permissions');
  84. }
  85. } else {
  86. console.log('no events');
  87. }
  88. }
  89. this.spinner.hide();
  90. },
  91. (error) => {console.log(error)}
  92. );
  93. }
  94. );
  95. }
  96. );
  97. //get list data
  98. this.dashBoardService.getListData(this.pageId, this.currentPage ,this.dataTableNumber).subscribe(
  99. (responce) => {
  100. console.log(responce);
  101. this.dataList = responce['requests'];
  102. if(this.dataList.length == 0) {
  103. this.toastr.warning('القائمه فارغه من الطلبات ');
  104. }
  105. this.count = responce['count'];
  106. this.perPagePagenation = responce['per_page'];
  107. console.log('evennnnts', this.dataList);
  108. this.spinner.hide();
  109. },
  110. (error) => {
  111. console.log(error);
  112. this.spinner.hide();
  113. }
  114. );
  115. }
  116. //make all checkbox of user checked
  117. selectAll() {
  118. for (var i = 0; i < this.dataList.length; i++) {
  119. this.dataList[i].selected = this.selectedAll;
  120. }
  121. }
  122. checkIfAllSelected() {
  123. this.selectedAll = this.dataList.every(function(item:any) {
  124. return item.selected == true;
  125. });
  126. }
  127. //filtter function
  128. filtterFunc(data) {
  129. this.dataList = [];
  130. console.log(data.target.value);
  131. const dataSearch = data.target.value;
  132. this.currentPage = 1;
  133. this.dashBoardService.getDataUSerSearchBar(dataSearch, this.pageId, this.currentPage, this.dataTableNumber).subscribe(
  134. (responce) => {
  135. console.log(responce);
  136. this.dataList = responce['requests'];
  137. this.count = responce['count'];
  138. this.perPagePagenation = responce['per_page'];
  139. console.log('filtter count', this.count);
  140. console.log('filtter perPagePAgenation', this.perPagePagenation);
  141. },
  142. (error) => {
  143. console.log(error)
  144. }
  145. );
  146. };
  147. //change page
  148. onPageChange(pagenationNumber) {
  149. this.spinner.show();
  150. this.currentPage = pagenationNumber;
  151. this.dataList = [];
  152. //console.log(pagenationNumber);
  153. //console.log(this.pageId);
  154. this.dashBoardService.getListData(this.pageId, pagenationNumber, 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. console.log(this.dataList);
  161. this.spinner.hide();
  162. },
  163. (error) => {
  164. console.log(error);
  165. this.spinner.hide();
  166. }
  167. );
  168. }
  169. //determine the list count from select element
  170. onGetValue(event) {
  171. this.spinner.show();
  172. this.dataList = [];
  173. this.dataTableNumber = event.target.value;
  174. this.dashBoardService.getListData(this.pageId, this.currentPage, this.dataTableNumber).subscribe(
  175. (responce) => {
  176. console.log(responce);
  177. this.dataList = responce['requests'];
  178. this.count = responce['count'];
  179. this.perPagePagenation = responce['per_page'];
  180. this.spinner.hide();
  181. },
  182. (error) => {
  183. console.log(error);
  184. this.spinner.hide();
  185. }
  186. );
  187. };
  188. onFiltterChosen(event) {
  189. this.spinner.show();
  190. this.dataList = [];
  191. console.log(event.target.value);
  192. console.log(this.authSer.pathApi + '/page_list/' +this.pageId + '/' + this.currentPage + '/' + this.dataTableNumber + '/' + event.target.value);
  193. this.http.get(this.authSer.pathApi + '/page_list/' +this.pageId + '/' + this.currentPage + '/' + this.dataTableNumber + '/' + event.target.value).subscribe(
  194. (responce) => {
  195. console.log(responce);
  196. console.log(responce);
  197. this.dataList = responce['requests'];
  198. this.count = responce['count'];
  199. this.perPagePagenation = responce['per_page'];
  200. this.spinner.hide();
  201. },
  202. (error) => {
  203. console.log(error);
  204. }
  205. )
  206. }
  207. // onDelete() {
  208. // for(let i = 0; i < this.dataList.length; i++) {
  209. // if(this.dataList[i].selected == true) {
  210. // this.dataListIds.push(this.dataList[i].id);
  211. // }
  212. // }
  213. // console.log(this.dataListIds);
  214. // if(this.dataListIds.length > 0) {
  215. // const dialogRef = this.modal.alert()
  216. // .size('sm')
  217. // .showClose(true)
  218. // .title('تأكيد الحذف')
  219. // .body(`
  220. // <h4>هل ترغب في حذف العناصر المحدده ؟ </h4>
  221. // `)
  222. // .open();
  223. // dialogRef.result
  224. // .then( result =>
  225. // this.dashBoardService.deleteItem(this.dataListIds, this.pageId).subscribe(
  226. // (responce) => {
  227. // console.log(responce);
  228. // this.toastr.success('تم الحذف');
  229. // this.spinner.show();
  230. // this.dataList = [];
  231. // this.dashBoardService.getListData(this.pageId, this.currentPage, this.dataTableNumber).subscribe(
  232. // (responce) => {
  233. // console.log(responce);
  234. // this.dataList = responce['requests'];
  235. // this.count = responce['count'];
  236. // this.perPagePagenation = responce['per_page'];
  237. // this.spinner.hide();
  238. // },
  239. // (error) => {
  240. // console.log(error);
  241. // this.spinner.hide();
  242. // }
  243. // );
  244. // },
  245. // (error) => {
  246. // this.toastr.success('يوجد خطأ إنتظر قليلا وأعد المحاوله ');
  247. // console.log(error);
  248. // this.spinner.hide();
  249. // },
  250. // )
  251. // );
  252. // } else {
  253. // this.toastr.warning('لم يتم إختيار أي عنصر للمسح !');
  254. // }
  255. // };
  256. //add function
  257. onAdd() {
  258. console.log('service/' + this.userLoginId + '/' + this.serviceId + '/reviewTraineeData/add');
  259. this.router.navigate(['service/' + this.userLoginId + '/' + this.serviceId + '/reviewTraineeData/add']);
  260. }
  261. //edit function
  262. onEdit(editNewID) {
  263. this.router.navigate(['service/' + this.userLoginId + '/' + this.serviceId + '/' + 'reviewTraineeData/edit/' + editNewID]);
  264. }
  265. }