show-links.component.ts 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 { MenuComponent } from '../menu/menu.component';
  5. import { Categorie } from '../../interfaces/categorie';
  6. import { CategorieService } from '../../services/categorie.service';
  7. import { ProductionItem, ProductionEnum } from '../../interfaces/production';
  8. import { PresentationService } from '../../services/presentation.service';
  9. @Component({ selector: 'app-show-links', imports: [FormsModule, MenuComponent], templateUrl: './show-links.component.html', styleUrl: './show-links.component.css' })
  10. export class ShowLinksComponent implements OnInit
  11. {
  12. @ViewChild('boutonLier', {static: false}) boutonLier!: ElementRef;
  13. @ViewChild('boutonRetirer', {static: false}) boutonRetirer!: ElementRef;
  14. @ViewChild('boutonAvancer', {static: false}) boutonAvancer!: ElementRef;
  15. @ViewChild('boutonReculer', {static: false}) boutonReculer!: ElementRef;
  16. numeroCategorie: number = 0;
  17. categorie: Categorie = new Categorie();
  18. numeroProduction: number = 0;
  19. linkedProductions: ProductionItem[] = [];
  20. unlinkedProductions: ProductionItem[] = [];
  21. constructor(
  22. private categorieService: CategorieService,
  23. private presentationService: PresentationService,
  24. private route: ActivatedRoute,
  25. private router: Router,
  26. private menu: MenuComponent,
  27. private renderer: Renderer2
  28. ) { }
  29. ngOnInit()
  30. {
  31. this.numeroCategorie = this.route.snapshot.params['numeroCategorie'];
  32. this.categorie = new Categorie();
  33. this.categorieService.getByIdCategorie(this.numeroCategorie).subscribe( data => { this.categorie = data; });
  34. this.retreiveDatas();
  35. this.resetEtatBoutonsUnlinked();
  36. this.resetEtatBoutonsLinked();
  37. }
  38. private retreiveDatas()
  39. {
  40. this.presentationService.getLinkedProductions(this.numeroCategorie).subscribe(data => { this.linkedProductions = data; });
  41. this.presentationService.getUnlinkedProductions().subscribe(data => { this.unlinkedProductions = data; });
  42. }
  43. lettresOrdre: string[] = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
  44. indexLettre: number = 0;
  45. resetLettre() { this.indexLettre = 0; }
  46. nextLettre(): string { if ((this.indexLettre >= 0) && (this.indexLettre < 26)) { this.indexLettre++; return "#" + this.lettresOrdre[this.indexLettre - 1]; } return ""; }
  47. goToListPresentations() { this.router.navigate(['/show-list', this.menu.getRandomInteger(1, 100000)]); }
  48. changeEtatBoutonsUnlinked(event: any)
  49. {
  50. this.numeroProduction = event.target.value;
  51. var b: boolean = (this.numeroProduction != 0);
  52. if (this.boutonLier) { if (b) { this.renderer.removeClass(this.boutonLier.nativeElement, 'disabled'); } else { this.renderer.addClass(this.boutonLier.nativeElement, 'disabled'); } }
  53. }
  54. resetEtatBoutonsUnlinked()
  55. {
  56. if (this.boutonLier) { this.renderer.addClass(this.boutonLier.nativeElement, 'disabled'); }
  57. }
  58. changeEtatBoutonsLinked(event: any)
  59. {
  60. this.numeroProduction = -event.target.value;
  61. var b: boolean = (this.numeroProduction != 0);
  62. if (this.boutonRetirer) { if (b) { this.renderer.removeClass(this.boutonRetirer.nativeElement, 'disabled'); } else { this.renderer.addClass(this.boutonRetirer.nativeElement, 'disabled'); } }
  63. if (this.boutonAvancer) { if (b) { this.renderer.removeClass(this.boutonAvancer.nativeElement, 'disabled'); } else { this.renderer.addClass(this.boutonAvancer.nativeElement, 'disabled'); } }
  64. if (this.boutonReculer) { if (b) { this.renderer.removeClass(this.boutonReculer.nativeElement, 'disabled'); } else { this.renderer.addClass(this.boutonReculer.nativeElement, 'disabled'); } }
  65. }
  66. resetEtatBoutonsLinked()
  67. {
  68. if (this.boutonRetirer) { this.renderer.addClass(this.boutonRetirer.nativeElement, 'disabled'); }
  69. if (this.boutonAvancer) { this.renderer.addClass(this.boutonAvancer.nativeElement, 'disabled'); }
  70. if (this.boutonReculer) { this.renderer.addClass(this.boutonReculer.nativeElement, 'disabled'); }
  71. }
  72. lierProduction() { if (this.numeroProduction > 0) { this.presentationService.lierProduction(this.numeroCategorie, this.numeroProduction).subscribe(() => { this.retreiveDatas(); this.resetEtatBoutonsUnlinked(); }); } }
  73. retirerProduction() { if (this.numeroProduction < 0) { this.presentationService.retirerProduction(this.numeroCategorie, this.numeroProduction).subscribe(() => { this.retreiveDatas(); this.resetEtatBoutonsLinked(); }); } }
  74. avancerProduction() { if (this.numeroProduction < 0) { this.presentationService.avancerProduction(this.numeroCategorie, this.numeroProduction).subscribe(() => { this.retreiveDatas(); }); } }
  75. reculerProduction() { if (this.numeroProduction < 0) { this.presentationService.reculerProduction(this.numeroCategorie, this.numeroProduction).subscribe(() => { this.retreiveDatas(); }); } }
  76. }