production-list.component.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. import { TooltipModule } from 'ngx-bootstrap/tooltip';
  8. @Component({ selector: 'app-production-list', imports: [TooltipModule], templateUrl: './production-list.component.html', styleUrl: './production-list.component.css' })
  9. export class ProductionListComponent implements OnInit, AfterViewInit
  10. {
  11. productions: ProductionShort[] = [];
  12. types: ProductionEnum[] = ProductionTypeList;
  13. constructor(private productionService: ProductionService, private router: Router, private application: AppComponent) { }
  14. ngOnInit() { this.retreiveDatas(); }
  15. ngAfterViewInit()
  16. {
  17. this.application.menuActivateProds();
  18. }
  19. private retreiveDatas() { this.productionService.getListProduction().subscribe(data => { this.productions = data; }); }
  20. goToRefreshListProduction(){ this.router.navigate(['/production-list'], { queryParams: { 'refresh': this.getRandomInteger(1, 100000) } }); }
  21. private getRandomInteger(min: number, max: number) { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min)) + min; }
  22. goToNewProduction(){ this.router.navigate(['/production-create']); }
  23. formProduction(id: number) { this.router.navigate(['/production-details', id]); }
  24. getFile(id: number, nom: string) { this.productionService.getProductionFile(id).subscribe(response => { this.saveFile(response.body, nom); }); }
  25. saveFile(data: any, filename?: string) { const blob = new Blob([data], {type: 'application/zip'}); saveAs(blob, filename); }
  26. }