show-list.component.ts 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { Component, OnInit } 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 { saveAs } from 'file-saver-es';
  6. import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
  7. import { faRotate, faFileCode, faFilePdf, faCheckToSlot, faLink, faDownload, faUserTie, faSquareXmark, faSquareCheck, faSquareArrowUpRight } from '@fortawesome/free-solid-svg-icons';
  8. import { MenuComponent } from '../menu/menu.component';
  9. import { Categorie } from '../../interfaces/categorie';
  10. import { CategorieService } from '../../services/categorie.service';
  11. import { ProductionShort, ProductionEnum, ProductionTypeList } from '../../interfaces/production';
  12. import { PresentationService } from '../../services/presentation.service';
  13. import { ProductionService } from '../../services/production.service';
  14. @Component({ selector: 'app-show-list', imports: [FontAwesomeModule, FormsModule, TooltipModule, MenuComponent], templateUrl: './show-list.component.html', styleUrl: './show-list.component.css' })
  15. export class ShowListComponent implements OnInit
  16. {
  17. faRotate = faRotate; faFileCode = faFileCode; faFilePdf = faFilePdf; faCheckToSlot = faCheckToSlot; faLink = faLink; faDownload = faDownload; faUserTie = faUserTie;
  18. faSquareXmark = faSquareXmark; faSquareCheck = faSquareCheck; faSquareArrowUpRight = faSquareArrowUpRight;
  19. categories: Categorie[] = [];
  20. types: ProductionEnum[] = ProductionTypeList;
  21. productions: ProductionShort[] = [];
  22. constructor(
  23. private categorieService: CategorieService,
  24. private presentationService: PresentationService,
  25. private productionService: ProductionService,
  26. private router: Router,
  27. private route: ActivatedRoute
  28. ) { }
  29. ngOnInit() { this.goToRefreshListCategorie(); }
  30. private retreiveDatas()
  31. {
  32. this.categorieService.getListCategorie(false).subscribe(data => { this.categories = data; });
  33. this.presentationService.getListProduction().subscribe(data => { this.productions = data; });
  34. }
  35. 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'];
  36. indexLettre: number = 0;
  37. resetLettre() { this.indexLettre = 0; }
  38. nextLettre(): string { if ((this.indexLettre >= 0) && (this.indexLettre < 26)) { this.indexLettre++; return "#" + this.lettresOrdre[this.indexLettre - 1]; } return ""; }
  39. goToRefreshListCategorie() { this.retreiveDatas(); }
  40. lierProductions(id: number) { this.router.navigate(['/show-links', id]); }
  41. formPresentation(id: number) { this.router.navigate(['/show-upload', id]); }
  42. getVersionPDF() { this.presentationService.getPresentationPDF().subscribe(response => { this.savePDF(response.body, 'shows.all.pdf'); }); }
  43. savePDF(data: any, filename?: string) { const blob = new Blob([data], {type: 'application/pdf'}); saveAs(blob, filename); }
  44. getDiaporama(id: number, nom: string) { this.presentationService.getPresentationHTML(id).subscribe(response => { this.saveHTML(response.body, 'shows.' + nom + '.html'); }); }
  45. saveHTML(data: any, filename?: string) { const blob = new Blob([data], {type: 'text/html'}); saveAs(blob, filename); }
  46. getFile(id: number, nom: string) { this.productionService.getProductionFile(id).subscribe(response => { this.saveFile(response.body, nom); }); }
  47. saveFile(data: any, filename?: string) { const blob = new Blob([data], {type: 'application/zip'}); saveAs(blob, filename); }
  48. ouvrirScrutin(id: number) { this.categorieService.ouvrirScrutin(id).subscribe(() => { this.goToRefreshListCategorie(); }); }
  49. }