diff --git a/src/app/components/image-manager/add-image-dialog/add-image-dialog.component.spec.ts b/src/app/components/image-manager/add-image-dialog/add-image-dialog.component.spec.ts index cf51111b..d56eb2d5 100644 --- a/src/app/components/image-manager/add-image-dialog/add-image-dialog.component.spec.ts +++ b/src/app/components/image-manager/add-image-dialog/add-image-dialog.component.spec.ts @@ -14,6 +14,7 @@ import { AddImageDialogComponent } from './add-image-dialog.component'; import { NO_ERRORS_SCHEMA } from '@angular/core'; import { ToasterService } from 'app/services/toaster.service'; import { MockedToasterService } from 'app/services/toaster.service.spec'; +import { MatSnackBarModule } from '@angular/material/snack-bar'; export class MockedImageManagerService { public getImages(server: Server) { @@ -37,7 +38,8 @@ describe('AddImageDialogComponent', () => { MatToolbarModule, MatMenuModule, MatCheckboxModule, - MatDialogModule + MatDialogModule, + MatSnackBarModule ], providers: [ { provide: ServerService, useValue: mockedServerService }, diff --git a/src/app/components/image-manager/add-image-dialog/add-image-dialog.component.ts b/src/app/components/image-manager/add-image-dialog/add-image-dialog.component.ts index b174fce6..0287dc95 100644 --- a/src/app/components/image-manager/add-image-dialog/add-image-dialog.component.ts +++ b/src/app/components/image-manager/add-image-dialog/add-image-dialog.component.ts @@ -2,14 +2,14 @@ import { animate, state, style, transition, trigger } from '@angular/animations' import { Component, DoCheck, Inject, OnInit } from '@angular/core'; import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; import { MatSnackBar } from '@angular/material/snack-bar'; -import { ToasterService } from '../../../services/toaster.service'; import { UploadServiceService } from 'app/common/uploading-processbar/upload-service.service'; import { UploadingProcessbarComponent } from 'app/common/uploading-processbar/uploading-processbar.component'; -import { Observable, of } from 'rxjs'; +import { forkJoin, Observable, of } from 'rxjs'; import { catchError } from 'rxjs/operators'; import { ImageData } from '../../../models/images'; import { Server } from '../../../models/server'; import { ImageManagerService } from '../../../services/image-manager.service'; +import { ToasterService } from '../../../services/toaster.service'; @Component({ selector: 'app-add-image-dialog', @@ -32,8 +32,8 @@ export class AddImageDialogComponent implements OnInit, DoCheck { selectFile: any = []; uploadFileMessage: ImageData = []; uploadProgress: number = 0; - - cancelRequsts = new Map(); + cancelRequsts: any; + forkObservable: Observable[] = []; constructor( @Inject(MAT_DIALOG_DATA) public data: any, public dialogRef: MatDialogRef, @@ -72,13 +72,11 @@ export class AddImageDialogComponent implements OnInit, DoCheck { this.selectFile.forEach((imgElement) => { const object = this.imageService .uploadedImage(this.server, this.install_appliance, imgElement.name, imgElement) - .pipe(catchError((error) => of(error))) - .subscribe(); - this.cancelRequsts.set(imgElement.name, object); + .pipe(catchError((error) => of(error))); + this.forkObservable.push(object); }); - - this.uploadProgress = this.cancelRequsts.size; - Observable.forkJoin(this.cancelRequsts.values).subscribe((responses) => { + this.uploadProgress = this.forkObservable.length; + this.cancelRequsts = forkJoin(this.forkObservable).subscribe((responses) => { this.uploadFileMessage = responses; this.uploadServiceService.processBarCount(100); this.uploadedFile = false; @@ -95,9 +93,7 @@ export class AddImageDialogComponent implements OnInit, DoCheck { }, 10000); } cancelUploading() { - this.cancelRequsts.forEach((obj) => { - obj.unsubscribe(); - }); + this.cancelRequsts.unsubscribe(); this.dialogRef.close(); this.uploadServiceService.processBarCount(100); this.toasterService.warning('Image upload cancelled');