production-list.component.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { Component, OnInit, AfterViewInit } from '@angular/core';
  2. import { Router } from '@angular/router';
  3. import { AppComponent } from '../../app.component';
  4. import { ProductionShort, ProductionEnum, ProductionTypeList } from '../../interfaces/production';
  5. import { ProductionService } from '../../services/production.service';
  6. import { saveAs } from 'file-saver';
  7. @Component({ selector: 'app-production-list', imports: [], templateUrl: './production-list.component.html', styleUrl: './production-list.component.css' })
  8. export class ProductionListComponent implements OnInit, AfterViewInit
  9. {
  10. productions: ProductionShort[] = [];
  11. types: ProductionEnum[] = ProductionTypeList;
  12. constructor(private productionService: ProductionService, private router: Router, private application: AppComponent) { }
  13. ngOnInit(): void { this.retreiveDatas(); }
  14. ngAfterViewInit() { this.application.menuActivateProds(); }
  15. private retreiveDatas() { this.productionService.getListProduction().subscribe(data => { this.productions = data; }); }
  16. goToRefreshListProduction(){ this.router.navigate(['/production-list'], { queryParams: { 'refresh': this.getRandomInteger(1, 100000) } }); }
  17. private getRandomInteger(min: number, max: number) { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min)) + min; }
  18. goToNewProduction(){ this.router.navigate(['/production-create']); }
  19. formProduction(id: number) { this.router.navigate(['/production-details', id]); }
  20. getFile(id: number, nom: string) { this.productionService.getProductionFile(id).subscribe(response => { this.saveFile(response.body, nom); }); }
  21. saveFile(data: any, filename?: string) { const blob = new Blob([data], {type: 'application/zip'}); saveAs(blob, filename); }
  22. }