Projekt

Obecné

Profil

Stáhnout (1.18 KB) Statistiky
| Větev: | Tag: | Revize:
1
import { Component, OnInit } from '@angular/core';
2
import {QueryService} from '../../../services/query.service';
3
import {HttpEventType} from '@angular/common/http';
4

    
5
@Component({
6
  selector: 'app-upload',
7
  templateUrl: './upload.component.html',
8
  styleUrls: ['./upload.component.css']
9
})
10
export class UploadComponent implements OnInit {
11
  selectedFiles: File[] = null;
12
  resultMessage: string = null;
13
  progress = 0;
14

    
15
  constructor( private queryService: QueryService ) { }
16

    
17
  ngOnInit(): void {
18
  }
19

    
20
  onFilesSelected(event) {
21
    this.selectedFiles = event.target.files;
22
    this.progress = 0;
23
    this.resultMessage = null;
24
  }
25

    
26
  onUpload() {
27
    console.log(this.selectedFiles);
28
    if (this.selectedFiles === null) {
29
      this.resultMessage = 'Select files first';
30
      return;
31
    }
32
    this.queryService.uploadFile(this.selectedFiles).subscribe( event => {
33
      if (event.type === HttpEventType.UploadProgress) {
34
        this.progress = Math.round(event.loaded / event.total * 100);
35
      } else if (event.type === HttpEventType.Response ) {
36
        this.resultMessage = 'Successfully uploaded ' + this.selectedFiles.length + ' files';
37
        this.selectedFiles = null;
38
      }
39
    });
40
  }
41
}
(4-4/4)