diff --git a/src-ui/src/app/components/dashboard/widgets/upload-file-widget/upload-file-widget.component.html b/src-ui/src/app/components/dashboard/widgets/upload-file-widget/upload-file-widget.component.html index cb114e49e..013486a47 100644 --- a/src-ui/src/app/components/dashboard/widgets/upload-file-widget/upload-file-widget.component.html +++ b/src-ui/src/app/components/dashboard/widgets/upload-file-widget/upload-file-widget.component.html @@ -1,15 +1,18 @@ - - + + + - - + + + + Uploading {{uploadStatus.length}} file(s) + 0"> + + + \ No newline at end of file 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 1003f31db..90bfbf1e5 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 @@ -1,8 +1,16 @@ +import { HttpEventType } from '@angular/common/http'; import { Component, OnInit } from '@angular/core'; import { FileSystemFileEntry, NgxFileDropEntry } from 'ngx-file-drop'; import { DocumentService } from 'src/app/services/rest/document.service'; import { Toast, ToastService } from 'src/app/services/toast.service'; + +interface UploadStatus { + file: string + loaded: number + total: number +} + @Component({ selector: 'app-upload-file-widget', templateUrl: './upload-file-widget.component.html', @@ -21,16 +29,40 @@ export class UploadFileWidgetComponent implements OnInit { public fileLeave(event){ } + uploadStatus: UploadStatus[] = [] + + uploadVisible = false + + get loadedSum() { + return this.uploadStatus.map(s => s.loaded).reduce((a,b) => a+b, 1) + } + + get totalSum() { + return this.uploadStatus.map(s => s.total).reduce((a,b) => a+b, 1) + } + public dropped(files: NgxFileDropEntry[]) { for (const droppedFile of files) { if (droppedFile.fileEntry.isFile) { const fileEntry = droppedFile.fileEntry as FileSystemFileEntry; fileEntry.file((file: File) => { - const formData = new FormData() + let formData = new FormData() formData.append('document', file, file.name) - this.documentService.uploadDocument(formData).subscribe(result => { - this.toastService.showToast(Toast.make("Information", "The document has been uploaded and will be processed by the consumer shortly.")) + + 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.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) switch (error.status) { case 400: { this.toastService.showToast(Toast.makeError(`There was an error while uploading the document: ${error.error.document}`)) diff --git a/src-ui/src/app/services/rest/document.service.ts b/src-ui/src/app/services/rest/document.service.ts index 5bf2308d4..81693ec68 100644 --- a/src-ui/src/app/services/rest/document.service.ts +++ b/src-ui/src/app/services/rest/document.service.ts @@ -94,7 +94,7 @@ export class DocumentService extends AbstractPaperlessService } uploadDocument(formData) { - return this.http.post(this.getResourceUrl(null, 'post_document'), formData) + return this.http.post(this.getResourceUrl(null, 'post_document'), formData, {reportProgress: true, observe: "events"}) } getMetadata(id: number): Observable {
Uploading {{uploadStatus.length}} file(s)