participant-create.component.ts 1.5 KB

12345678910111213141516171819202122232425262728293031
  1. import { Component, OnInit, ViewChild } from '@angular/core';
  2. import { Participant, ParticipantEnum, ParticipantStatusList, ParticipantModePaiementList } from '../participant';
  3. import { ParticipantService } from '../participant.service';
  4. import { Router } from '@angular/router';
  5. import { FormsModule, NgForm } from '@angular/forms';
  6. @Component({ selector: 'app-participant-create', imports: [FormsModule], templateUrl: './participant-create.component.html', styleUrl: './participant-create.component.css' })
  7. export class ParticipantCreateComponent implements OnInit
  8. {
  9. PS: ParticipantEnum[] = ParticipantStatusList;
  10. PMP: ParticipantEnum[] = ParticipantModePaiementList;
  11. @ViewChild('formRef') participantForm!: NgForm;
  12. participant: Participant = new Participant();
  13. constructor(private participantService: ParticipantService, private router: Router) { }
  14. ngOnInit(): void { }
  15. private saveParticipant() { this.participantService.createParticipant(this.participant).subscribe({ next: () => { this.goToListParticipant(); }, error: (err: any) => { console.log(err); }, complete: () => { } }); }
  16. addParticipant() { if (this.participantForm.valid) { this.saveParticipant(); } }
  17. goToListParticipant() {this.router.navigate(['/participant-list'], { queryParams: { 'refresh': this.getRandomInteger(1, 100000) } }); }
  18. private getRandomInteger(min: number, max: number) { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min)) + min; }
  19. }