mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-03 03:16:10 -06:00 
			
		
		
		
	file upload improvements
This commit is contained in:
		@@ -6,7 +6,6 @@ import { Toast, ToastService } from 'src/app/services/toast.service';
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
interface UploadStatus {
 | 
					interface UploadStatus {
 | 
				
			||||||
  file: string
 | 
					 | 
				
			||||||
  loaded: number
 | 
					  loaded: number
 | 
				
			||||||
  total: number 
 | 
					  total: number 
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -30,11 +29,12 @@ export class UploadFileWidgetComponent implements OnInit {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  uploadStatus: UploadStatus[] = []
 | 
					  uploadStatus: UploadStatus[] = []
 | 
				
			||||||
 | 
					  completedFiles = 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  uploadVisible = false
 | 
					  uploadVisible = false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  get loadedSum() {
 | 
					  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() {
 | 
					  get totalSum() {
 | 
				
			||||||
@@ -44,32 +44,35 @@ export class UploadFileWidgetComponent implements OnInit {
 | 
				
			|||||||
  public dropped(files: NgxFileDropEntry[]) {
 | 
					  public dropped(files: NgxFileDropEntry[]) {
 | 
				
			||||||
    for (const droppedFile of files) {
 | 
					    for (const droppedFile of files) {
 | 
				
			||||||
      if (droppedFile.fileEntry.isFile) {
 | 
					      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) => {
 | 
					        fileEntry.file((file: File) => {
 | 
				
			||||||
          let formData = new FormData()
 | 
					          let formData = new FormData()
 | 
				
			||||||
          formData.append('document', file, file.name)
 | 
					          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 => {
 | 
					          this.documentService.uploadDocument(formData).subscribe(event => {
 | 
				
			||||||
            if (event.type == HttpEventType.UploadProgress) {
 | 
					            if (event.type == HttpEventType.UploadProgress) {
 | 
				
			||||||
              uploadStatusObject.loaded = event.loaded
 | 
					              uploadStatusObject.loaded = event.loaded
 | 
				
			||||||
              uploadStatusObject.total = event.total
 | 
					              uploadStatusObject.total = event.total
 | 
				
			||||||
            } else if (event.type == HttpEventType.Response) {
 | 
					            } else if (event.type == HttpEventType.Response) {
 | 
				
			||||||
              this.uploadStatus.splice(this.uploadStatus.indexOf(uploadStatusObject), 1)
 | 
					              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."))
 | 
					              this.toastService.showToast(Toast.make("Information", "The document has been uploaded and will be processed by the consumer shortly."))
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
          }, error => {
 | 
					          }, error => {
 | 
				
			||||||
            this.uploadStatus.splice(this.uploadStatus.indexOf(uploadStatusObject), 1)
 | 
					            this.uploadStatus.splice(this.uploadStatus.indexOf(uploadStatusObject), 1)
 | 
				
			||||||
 | 
					            this.completedFiles += 1
 | 
				
			||||||
            switch (error.status) {
 | 
					            switch (error.status) {
 | 
				
			||||||
              case 400: {
 | 
					              case 400: {
 | 
				
			||||||
                this.toastService.showToast(Toast.makeError(`There was an error while uploading the document: ${error.error.document}`))
 | 
					                this.toastService.showToast(Toast.makeError(`There was an error while uploading the document: ${error.error.document}`))
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
              }
 | 
					              }
 | 
				
			||||||
              default: {
 | 
					              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;
 | 
					                break;
 | 
				
			||||||
              }
 | 
					              }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user