participant-create.component.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { Component, OnInit, ViewChild } from '@angular/core';
  2. import { Router } from '@angular/router';
  3. import { FormsModule, NgForm } from '@angular/forms';
  4. import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
  5. import { faXmark, faPlus } from '@fortawesome/free-solid-svg-icons';
  6. import { MenuComponent } from '../menu/menu.component';
  7. import { Participant, ParticipantEnum, ProfilList, ParticipantStatutList, ParticipantModePaiementList } from '../../interfaces/participant';
  8. import { Journees } from '../../interfaces/divers';
  9. import { ParticipantService } from '../../services/participant.service';
  10. import { DiversService } from '../../services/divers.service'
  11. import { AccountService } from '../../services/account.service';
  12. @Component({ selector: 'app-participant-create', imports: [FontAwesomeModule, FormsModule, MenuComponent], templateUrl: './participant-create.component.html', styleUrl: './participant-create.component.css' })
  13. export class ParticipantCreateComponent implements OnInit
  14. {
  15. faXmark = faXmark; faPlus = faPlus;
  16. profil: string = "";
  17. profils: ParticipantEnum[] = ProfilList;
  18. journees: Journees = new Journees();
  19. PS: ParticipantEnum[] = ParticipantStatutList;
  20. PMP: ParticipantEnum[] = ParticipantModePaiementList;
  21. @ViewChild('formRef') participantForm!: NgForm;
  22. participant: Participant = new Participant();
  23. constructor(
  24. private diversService: DiversService,
  25. private participantService: ParticipantService,
  26. private router: Router,
  27. private menu: MenuComponent,
  28. private accountService: AccountService
  29. ) { }
  30. ngOnInit()
  31. {
  32. this.profil = this.accountService.getRole();
  33. this.journees = new Journees();
  34. this.diversService.getJournees().subscribe(data => { this.journees = data; });
  35. }
  36. private saveParticipant() { this.participantService.createParticipant(this.participant).subscribe(() => { this.goToListParticipant(); }); }
  37. addParticipant() { if (this.participantForm.valid) { this.saveParticipant(); } }
  38. goToListParticipant() { this.router.navigate(['/participant-list']); }
  39. }