[AAE-1977] Fix file uploaded after cancelling upload (#5532)

* [AAE-1977] Fix file uploaded after cancelling upload

* Add constants
This commit is contained in:
davidcanonieto
2020-03-03 18:47:29 +00:00
committed by GitHub
parent 45f023c93a
commit 2b1a321baf
4 changed files with 111 additions and 52 deletions

View File

@@ -73,8 +73,7 @@ export class FileUploadingDialogComponent implements OnInit, OnDestroy {
private uploadService: UploadService,
private changeDetector: ChangeDetectorRef,
private userPreferencesService: UserPreferencesService,
private elementRef: ElementRef
) {
private elementRef: ElementRef) {
}
ngOnInit() {
@@ -104,9 +103,9 @@ export class FileUploadingDialogComponent implements OnInit, OnDestroy {
});
this.counterSubscription = merge(
this.uploadService.fileUploadComplete,
this.uploadService.fileUploadDeleted
)
this.uploadService.fileUploadComplete,
this.uploadService.fileUploadDeleted
)
.pipe(takeUntil(this.onDestroy$))
.subscribe(event => {
this.totalCompleted = event.totalComplete;
@@ -130,11 +129,11 @@ export class FileUploadingDialogComponent implements OnInit, OnDestroy {
.pipe(takeUntil(this.onDestroy$))
.subscribe(objId => {
if (this.filesUploadingList) {
const file = this.filesUploadingList.find((item) => {
return item.data.entry.id === objId;
const uploadedFile = this.filesUploadingList.find((file) => {
return file.data ? file.data.entry.id === objId : false;
});
if (file) {
file.status = FileUploadStatus.Cancelled;
if (uploadedFile) {
uploadedFile.status = FileUploadStatus.Cancelled;
this.changeDetector.detectChanges();
}
}

View File

@@ -54,8 +54,8 @@ export class FileUploadingListComponent {
constructor(
private uploadService: UploadService,
private nodesApi: NodesApiService,
private translateService: TranslationService
) {}
private translateService: TranslationService) {
}
/**
* Cancel file upload
@@ -91,16 +91,18 @@ export class FileUploadingListComponent {
}
/**
* Call the appropriate method for each file, depending on state
* Calls the appropriate methods for each file, depending on state
*/
cancelAllFiles(): void {
this.getUploadingFiles().forEach((file) =>
this.uploadService.cancelUpload(file)
);
const deletedFiles: Observable<FileModel>[] = [];
const deletedFiles = this.files
.filter((file) => file.status === FileUploadStatus.Complete)
.map((file) => this.deleteNode(file));
this.files.forEach((file) => {
if (this.isUploadingFile(file)) {
this.uploadService.cancelUpload(file);
} else if (file.status === FileUploadStatus.Complete) {
deletedFiles.push(this.deleteNode(file));
}
});
forkJoin(...deletedFiles).subscribe((files: FileModel[]) => {
const errors = files.filter(
@@ -192,12 +194,9 @@ export class FileUploadingListComponent {
this.error.emit(messageError);
}
private getUploadingFiles(): FileModel[] {
return this.files.filter(
item =>
item.status === FileUploadStatus.Pending ||
item.status === FileUploadStatus.Progress ||
item.status === FileUploadStatus.Starting
);
private isUploadingFile(file: FileModel): boolean {
return file.status === FileUploadStatus.Pending ||
file.status === FileUploadStatus.Starting ||
file.status === FileUploadStatus.Progress;
}
}