participant-update.component.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { Component, OnInit, ViewChild } from '@angular/core';
  2. import { ActivatedRoute, Router } from '@angular/router';
  3. import { Participant, ParticipantStatusEnum, ParticipantModePaiementEnum } from '../participant';
  4. import { ParticipantService } from '../participant.service';
  5. import { FormsModule, NgForm } from '@angular/forms';
  6. @Component({ selector: 'app-participant-update', imports: [FormsModule], templateUrl: './participant-update.component.html', styleUrl: './participant-update.component.css' })
  7. export class ParticipantUpdateComponent implements OnInit
  8. {
  9. PS = ParticipantStatusEnum;
  10. PMP = ParticipantModePaiementEnum;
  11. @ViewChild('formRef') participantForm!: NgForm;
  12. numeroParticipant: number = 0;
  13. participant: Participant = new Participant();
  14. constructor(private participantService: ParticipantService, private route: ActivatedRoute, private router: Router) { }
  15. ngOnInit(): void
  16. {
  17. this.numeroParticipant = this.route.snapshot.params['numeroParticipant'];
  18. this.participantService.getByIdParticipant(this.numeroParticipant).subscribe(data => { this.participant = data; });
  19. }
  20. updateConfirmed() { if (this.participantForm.valid) { this.participantService.updateParticipant(this.numeroParticipant, this.participant).subscribe(() => { this.goToListParticipant(); }); } }
  21. deleteConfirmed() { this.participantService.deleteParticipant(this.numeroParticipant).subscribe(() => { this.goToListParticipant(); }); }
  22. goToListParticipant(){ this.router.navigate(['/participant-list'], { queryParams: { 'refresh': this.getRandomInteger(1, 100000) } }); }
  23. private getRandomInteger(min: number, max: number) { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min)) + min; }
  24. }