From e428a8a0087d4bf067539d44ac0031c30e80c63c Mon Sep 17 00:00:00 2001 From: jonaswinkler Date: Tue, 8 Dec 2020 17:35:51 +0100 Subject: [PATCH] file upload improvements --- .../upload-file-widget.component.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src-ui/src/app/components/dashboard/widgets/upload-file-widget/upload-file-widget.component.ts b/src-ui/src/app/components/dashboard/widgets/upload-file-widget/upload-file-widget.component.ts index 90bfbf1e5..2ea4825f1 100644 --- a/src-ui/src/app/components/dashboard/widgets/upload-file-widget/upload-file-widget.component.ts +++ b/src-ui/src/app/components/dashboard/widgets/upload-file-widget/upload-file-widget.component.ts @@ -6,7 +6,6 @@ import { Toast, ToastService } from 'src/app/services/toast.service'; interface UploadStatus { - file: string loaded: number total: number } @@ -30,11 +29,12 @@ export class UploadFileWidgetComponent implements OnInit { } uploadStatus: UploadStatus[] = [] + completedFiles = 0 uploadVisible = false get loadedSum() { - return this.uploadStatus.map(s => s.loaded).reduce((a,b) => a+b, 1) + return this.uploadStatus.map(s => s.loaded).reduce((a,b) => a+b, this.completedFiles > 0 ? 1 : 0) } get totalSum() { @@ -44,32 +44,35 @@ export class UploadFileWidgetComponent implements OnInit { public dropped(files: NgxFileDropEntry[]) { for (const droppedFile of files) { if (droppedFile.fileEntry.isFile) { - const fileEntry = droppedFile.fileEntry as FileSystemFileEntry; + let uploadStatusObject: UploadStatus = {loaded: 0, total: 1} + this.uploadStatus.push(uploadStatusObject) + this.uploadVisible = true + + const fileEntry = droppedFile.fileEntry as FileSystemFileEntry; fileEntry.file((file: File) => { let formData = new FormData() formData.append('document', file, file.name) - let uploadStatusObject: UploadStatus = {file: file.name, loaded: 0, total: 1} - this.uploadStatus.push(uploadStatusObject) - this.uploadVisible = true this.documentService.uploadDocument(formData).subscribe(event => { if (event.type == HttpEventType.UploadProgress) { uploadStatusObject.loaded = event.loaded uploadStatusObject.total = event.total } else if (event.type == HttpEventType.Response) { this.uploadStatus.splice(this.uploadStatus.indexOf(uploadStatusObject), 1) + this.completedFiles += 1 this.toastService.showToast(Toast.make("Information", "The document has been uploaded and will be processed by the consumer shortly.")) } }, error => { this.uploadStatus.splice(this.uploadStatus.indexOf(uploadStatusObject), 1) + this.completedFiles += 1 switch (error.status) { case 400: { this.toastService.showToast(Toast.makeError(`There was an error while uploading the document: ${error.error.document}`)) break; } default: { - this.toastService.showToast(Toast.makeError("An error has occured while uploading the document. Sorry!")) + this.toastService.showToast(Toast.makeError("An error has occurred while uploading the document. Sorry!")) break; } }