2018-03-21 14:15:06 +01:00
|
|
|
import { Component, Input, OnInit } from "@angular/core";
|
2018-05-14 08:44:35 +02:00
|
|
|
import { FileUploader } from "../../../shared/components/file-uploader/FileUploader";
|
2018-03-21 14:15:06 +01:00
|
|
|
import { FormControl } from "@angular/forms";
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-fileuploader-component',
|
|
|
|
templateUrl: './file-uploader.component.html'
|
|
|
|
})
|
|
|
|
export class FileUploaderComponent implements OnInit {
|
2018-05-14 08:44:35 +02:00
|
|
|
|
2018-03-21 14:15:06 +01:00
|
|
|
files: File | FileList;
|
|
|
|
disabled: boolean = false;
|
|
|
|
|
|
|
|
fileSelectMultipleMsg: string = 'No file(s) selected yet.';
|
|
|
|
|
|
|
|
@Input()
|
|
|
|
public label: string = 'FILE-UPLOADER.DEFAULT';
|
|
|
|
|
|
|
|
@Input()
|
|
|
|
public fileUploader: FileUploader;
|
|
|
|
|
|
|
|
@Input()
|
|
|
|
form: FormControl;
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
console.log(this.form)
|
|
|
|
}
|
|
|
|
|
|
|
|
selectEvent(files: FileList | File): void {
|
|
|
|
this.label = 'FILE-UPLOADER.UPLOAD'
|
|
|
|
if (files instanceof FileList) {
|
|
|
|
let names: string[] = [];
|
|
|
|
for (let i: number = 0; i < files.length; i++) {
|
|
|
|
names.push(files[i].name);
|
|
|
|
}
|
|
|
|
this.fileSelectMultipleMsg = names.join(',');
|
|
|
|
} else {
|
|
|
|
this.fileSelectMultipleMsg = files.name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uploadEvent(files: FileList | File): void {
|
|
|
|
let formdata: FormData = new FormData();
|
|
|
|
|
|
|
|
if (files instanceof FileList) {
|
|
|
|
for (let i: number = 0; i < files.length; i++) {
|
|
|
|
formdata.append('file', files[i]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
formdata.append('file', files);
|
|
|
|
}
|
|
|
|
this.fileUploader.uploadFile(formdata).subscribe(files => this.form.patchValue(files));
|
|
|
|
}
|
|
|
|
|
|
|
|
cancelEvent(): void {
|
|
|
|
}
|
|
|
|
}
|