mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-09 09:58:20 -05:00
upload status addresses #100
This commit is contained in:
parent
c4a939dbcc
commit
5321ff1f20
@ -1,15 +1,18 @@
|
|||||||
<app-widget-frame title="Upload new documents">
|
<app-widget-frame title="Upload new documents">
|
||||||
|
|
||||||
<form content>
|
<div content>
|
||||||
<ngx-file-drop
|
<form>
|
||||||
dropZoneLabel="Drop documents here or" (onFileDrop)="dropped($event)"
|
<ngx-file-drop dropZoneLabel="Drop documents here or" (onFileDrop)="dropped($event)"
|
||||||
(onFileOver)="fileOver($event)" (onFileLeave)="fileLeave($event)"
|
(onFileOver)="fileOver($event)" (onFileLeave)="fileLeave($event)" dropZoneClassName="bg-light card"
|
||||||
dropZoneClassName="bg-light card"
|
multiple="true" contentClassName="justify-content-center d-flex align-items-center p-5" [showBrowseBtn]=true
|
||||||
multiple="true"
|
browseBtnClassName="btn btn-sm btn-outline-primary ml-2">
|
||||||
contentClassName="justify-content-center d-flex align-items-center p-5"
|
|
||||||
[showBrowseBtn]=true
|
|
||||||
browseBtnClassName="btn btn-sm btn-outline-primary ml-2">
|
|
||||||
|
|
||||||
</ngx-file-drop>
|
</ngx-file-drop>
|
||||||
</form>
|
</form>
|
||||||
|
<div *ngIf="uploadVisible" class="mt-3">
|
||||||
|
<p>Uploading {{uploadStatus.length}} file(s)</p>
|
||||||
|
<ngb-progressbar [value]="loadedSum" [max]="totalSum" [striped]="true" [animated]="uploadStatus.length > 0">
|
||||||
|
</ngb-progressbar>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</app-widget-frame>
|
</app-widget-frame>
|
@ -1,8 +1,16 @@
|
|||||||
|
import { HttpEventType } from '@angular/common/http';
|
||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { FileSystemFileEntry, NgxFileDropEntry } from 'ngx-file-drop';
|
import { FileSystemFileEntry, NgxFileDropEntry } from 'ngx-file-drop';
|
||||||
import { DocumentService } from 'src/app/services/rest/document.service';
|
import { DocumentService } from 'src/app/services/rest/document.service';
|
||||||
import { Toast, ToastService } from 'src/app/services/toast.service';
|
import { Toast, ToastService } from 'src/app/services/toast.service';
|
||||||
|
|
||||||
|
|
||||||
|
interface UploadStatus {
|
||||||
|
file: string
|
||||||
|
loaded: number
|
||||||
|
total: number
|
||||||
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-upload-file-widget',
|
selector: 'app-upload-file-widget',
|
||||||
templateUrl: './upload-file-widget.component.html',
|
templateUrl: './upload-file-widget.component.html',
|
||||||
@ -21,16 +29,40 @@ export class UploadFileWidgetComponent implements OnInit {
|
|||||||
public fileLeave(event){
|
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[]) {
|
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;
|
const fileEntry = droppedFile.fileEntry as FileSystemFileEntry;
|
||||||
fileEntry.file((file: File) => {
|
fileEntry.file((file: File) => {
|
||||||
const formData = new FormData()
|
let formData = new FormData()
|
||||||
formData.append('document', file, file.name)
|
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 => {
|
}, error => {
|
||||||
|
this.uploadStatus.splice(this.uploadStatus.indexOf(uploadStatusObject), 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}`))
|
||||||
|
@ -94,7 +94,7 @@ export class DocumentService extends AbstractPaperlessService<PaperlessDocument>
|
|||||||
}
|
}
|
||||||
|
|
||||||
uploadDocument(formData) {
|
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<PaperlessDocumentMetadata> {
|
getMetadata(id: number): Observable<PaperlessDocumentMetadata> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user