participant-list.component.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import { Component, OnInit, ViewChild, ElementRef, Renderer2 } from '@angular/core';
  2. import { Router, ActivatedRoute } from '@angular/router';
  3. import { FormsModule, NgForm } from '@angular/forms';
  4. import { TooltipModule } from 'ngx-bootstrap/tooltip';
  5. import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
  6. import { faPlus, faFilter, faRotate, faFlagCheckered, faFilterCircleXmark, faCircleCheck, faBed, faCircleXmark, faArrowLeft, faArrowRight } from '@fortawesome/free-solid-svg-icons';
  7. import { MenuComponent } from '../menu/menu.component';
  8. import { ParticipantList, ParticipantEnum, ParticipantStatutList } from '../../interfaces/participant';
  9. import { ParticipantService } from '../../services/participant.service';
  10. import { Journees, Pagination } from '../../interfaces/divers';
  11. import { DiversService } from '../../services/divers.service'
  12. @Component({ selector: 'app-participant-list', imports: [FontAwesomeModule, TooltipModule, FormsModule, MenuComponent], templateUrl: './participant-list.component.html', styleUrl: './participant-list.component.css' })
  13. export class ParticipantListComponent implements OnInit
  14. {
  15. faPlus = faPlus; faFilter = faFilter; faRotate = faRotate; faFlagCheckered = faFlagCheckered; faFilterCircleXmark = faFilterCircleXmark; faCircleCheck = faCircleCheck; faBed = faBed;
  16. faCircleXmark = faCircleXmark; faArrowLeft = faArrowLeft; faArrowRight = faArrowRight;
  17. journees: Journees = new Journees();
  18. listeTri: number = 0;
  19. nomFiltre: string = "";
  20. statutFiltre: number = 0;
  21. arriveFiltre: number = 0;
  22. PS: ParticipantEnum[] = ParticipantStatutList;
  23. pagination: Pagination = new Pagination();
  24. pages: number[] = [1];
  25. participants: ParticipantList[] = [];
  26. @ViewChild('boutonSetArrives', {static: false}) boutonSetArrives!: ElementRef;
  27. @ViewChild('listeParticipants', {static: false}) listeParticipants!: ElementRef;
  28. selection: Array<number> = new Array<number>();
  29. constructor(
  30. private diversService: DiversService,
  31. private participantService: ParticipantService,
  32. private router: Router,
  33. private route: ActivatedRoute,
  34. private renderer: Renderer2
  35. ) { }
  36. ngOnInit()
  37. {
  38. this.journees = new Journees();
  39. this.diversService.getJournees().subscribe(data => { this.journees = data; });
  40. this.goToRefreshListParticipant();
  41. }
  42. private retreiveDatas(pageVoulue: number)
  43. {
  44. this.participantService.getPagination(this.nomFiltre, this.statutFiltre, this.arriveFiltre, pageVoulue).subscribe(page =>
  45. {
  46. this.pagination = page;
  47. this.pages = [1];
  48. if (this.pagination.nombrePages > 1) { for (let i = 2; i <= this.pagination.nombrePages; i++) { this.pages.push(i); } }
  49. this.participantService.getListParticipant(this.nomFiltre, this.statutFiltre, this.arriveFiltre, this.listeTri, this.pagination.pageCourante, this.pagination.taillePage).subscribe(data =>
  50. {
  51. this.participants = data;
  52. if (this.listeParticipants) { this.listeParticipants.nativeElement.scrollTop = 0; }
  53. });
  54. });
  55. }
  56. getNombreJours(j1: boolean, j2: boolean, j3: boolean)
  57. {
  58. var nbjours: number = 0;
  59. if (j1) { nbjours++; }
  60. if (j2) { nbjours++; }
  61. if (j3) { nbjours++; }
  62. return nbjours;
  63. }
  64. goToRefreshListParticipant() { this.retreiveDatas(this.pagination.pageCourante); }
  65. goToNextPage() { this.retreiveDatas(this.pagination.pageCourante + 1); }
  66. goToPrevPage() { this.retreiveDatas(this.pagination.pageCourante - 1); }
  67. goToPage(pageVoulue: number) { this.retreiveDatas(pageVoulue); }
  68. goToFiltrage() { this.retreiveDatas(this.pagination.pageCourante); }
  69. trier(event: any) { this.listeTri = event.target.value; this.retreiveDatas(this.pagination.pageCourante); }
  70. filtrageParNom() { this.retreiveDatas(this.pagination.pageCourante); }
  71. filtrageParStatut(event: any) { this.statutFiltre = event.target.value; this.retreiveDatas(this.pagination.pageCourante); }
  72. filtrageParArrive(event: any) { this.arriveFiltre = event.target.value; this.retreiveDatas(this.pagination.pageCourante); }
  73. filtrageReset() { this.nomFiltre = ""; this.statutFiltre = 0; this.arriveFiltre = 0; this.retreiveDatas(this.pagination.pageCourante); }
  74. goToNewParticipant() { this.router.navigate(['/participant-create']); }
  75. formParticipant(id: number) { this.router.navigate(['/participant-details', id]); }
  76. modifierSelection(event: any)
  77. {
  78. const id = event.target.id;
  79. if (id)
  80. {
  81. if (id.startsWith("check_"))
  82. {
  83. let nu = Number('' + id.substring(6));
  84. let nb = 0;
  85. if (this.selection.includes(nu)) { this.selection = this.selection.filter(it => it !== nu); nb = this.selection.length; } else { nb = this.selection.push(nu); }
  86. if (this.boutonSetArrives) { if (nb > 0) { this.renderer.removeClass(this.boutonSetArrives.nativeElement, 'disabled'); } else { this.renderer.addClass(this.boutonSetArrives.nativeElement, 'disabled'); } }
  87. }
  88. }
  89. }
  90. topperArrives() { if (this.selection.length > 0) { this.participantService.setParticipantsArrives(this.selection).subscribe(() => { this.retreiveDatas(this.pagination.pageCourante) }); } }
  91. }