production-upload.component.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { Component, OnInit } from '@angular/core';
  2. import { ActivatedRoute, Router } from '@angular/router';
  3. import { FormsModule } from '@angular/forms';
  4. import { MenuComponent } from '../menu/menu.component';
  5. import { ProductionFile } from '../../interfaces/production';
  6. import { ProductionService } from '../../services/production.service';
  7. @Component({ selector: 'app-production-upload', imports: [FormsModule, MenuComponent], templateUrl: './production-upload.component.html', styleUrl: './production-upload.component.css' })
  8. export class ProductionUploadComponent implements OnInit
  9. {
  10. production: ProductionFile = new ProductionFile();
  11. numeroProduction: number = 0;
  12. constructor(private productionService: ProductionService, private route: ActivatedRoute, private router: Router, private menu: MenuComponent) { }
  13. ngOnInit()
  14. {
  15. this.numeroProduction = this.route.snapshot.params['numeroProduction'];
  16. this.productionService.getByIdProductionFile(this.numeroProduction).subscribe(data => { this.production = data; });
  17. }
  18. onArchiveSelected(event: any)
  19. {
  20. const et = event.target;
  21. const reader = new FileReader();
  22. if (et.files && et.files.length > 0)
  23. {
  24. const file = et.files[0];
  25. this.production.nomArchive = file.name;
  26. reader.onloadend = async (e: any) => { if (e.target.result) { this.production.archive = e.target.result; } }
  27. reader.readAsDataURL(file);
  28. }
  29. }
  30. private saveProduction() { this.productionService.uploadProductionFile(this.numeroProduction, this.production).subscribe(); this.goToListProduction(); }
  31. addProductionFile() { this.saveProduction(); }
  32. goToListProduction() {this.router.navigate(['/production-list'], { queryParams: { 'refresh': this.menu.getRandomInteger(1, 100000) } }); }
  33. }