Resolve progress bar and add dependencies in spec file

This commit is contained in:
Rajnikant 2022-06-07 11:19:01 +05:30
parent b7e314deeb
commit 088b128b57
2 changed files with 12 additions and 14 deletions

View File

@ -14,6 +14,7 @@ import { AddImageDialogComponent } from './add-image-dialog.component';
import { NO_ERRORS_SCHEMA } from '@angular/core'; import { NO_ERRORS_SCHEMA } from '@angular/core';
import { ToasterService } from 'app/services/toaster.service'; import { ToasterService } from 'app/services/toaster.service';
import { MockedToasterService } from 'app/services/toaster.service.spec'; import { MockedToasterService } from 'app/services/toaster.service.spec';
import { MatSnackBarModule } from '@angular/material/snack-bar';
export class MockedImageManagerService { export class MockedImageManagerService {
public getImages(server: Server) { public getImages(server: Server) {
@ -37,7 +38,8 @@ describe('AddImageDialogComponent', () => {
MatToolbarModule, MatToolbarModule,
MatMenuModule, MatMenuModule,
MatCheckboxModule, MatCheckboxModule,
MatDialogModule MatDialogModule,
MatSnackBarModule
], ],
providers: [ providers: [
{ provide: ServerService, useValue: mockedServerService }, { provide: ServerService, useValue: mockedServerService },

View File

@ -2,14 +2,14 @@ import { animate, state, style, transition, trigger } from '@angular/animations'
import { Component, DoCheck, Inject, OnInit } from '@angular/core'; import { Component, DoCheck, Inject, OnInit } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { MatSnackBar } from '@angular/material/snack-bar'; import { MatSnackBar } from '@angular/material/snack-bar';
import { ToasterService } from '../../../services/toaster.service';
import { UploadServiceService } from 'app/common/uploading-processbar/upload-service.service'; import { UploadServiceService } from 'app/common/uploading-processbar/upload-service.service';
import { UploadingProcessbarComponent } from 'app/common/uploading-processbar/uploading-processbar.component'; 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 { catchError } from 'rxjs/operators';
import { ImageData } from '../../../models/images'; import { ImageData } from '../../../models/images';
import { Server } from '../../../models/server'; import { Server } from '../../../models/server';
import { ImageManagerService } from '../../../services/image-manager.service'; import { ImageManagerService } from '../../../services/image-manager.service';
import { ToasterService } from '../../../services/toaster.service';
@Component({ @Component({
selector: 'app-add-image-dialog', selector: 'app-add-image-dialog',
@ -32,8 +32,8 @@ export class AddImageDialogComponent implements OnInit, DoCheck {
selectFile: any = []; selectFile: any = [];
uploadFileMessage: ImageData = []; uploadFileMessage: ImageData = [];
uploadProgress: number = 0; uploadProgress: number = 0;
cancelRequsts: any;
cancelRequsts = new Map(); forkObservable: Observable<any>[] = [];
constructor( constructor(
@Inject(MAT_DIALOG_DATA) public data: any, @Inject(MAT_DIALOG_DATA) public data: any,
public dialogRef: MatDialogRef<AddImageDialogComponent>, public dialogRef: MatDialogRef<AddImageDialogComponent>,
@ -72,13 +72,11 @@ export class AddImageDialogComponent implements OnInit, DoCheck {
this.selectFile.forEach((imgElement) => { this.selectFile.forEach((imgElement) => {
const object = this.imageService const object = this.imageService
.uploadedImage(this.server, this.install_appliance, imgElement.name, imgElement) .uploadedImage(this.server, this.install_appliance, imgElement.name, imgElement)
.pipe(catchError((error) => of(error))) .pipe(catchError((error) => of(error)));
.subscribe(); this.forkObservable.push(object);
this.cancelRequsts.set(imgElement.name, object);
}); });
this.uploadProgress = this.forkObservable.length;
this.uploadProgress = this.cancelRequsts.size; this.cancelRequsts = forkJoin(this.forkObservable).subscribe((responses) => {
Observable.forkJoin(this.cancelRequsts.values).subscribe((responses) => {
this.uploadFileMessage = responses; this.uploadFileMessage = responses;
this.uploadServiceService.processBarCount(100); this.uploadServiceService.processBarCount(100);
this.uploadedFile = false; this.uploadedFile = false;
@ -95,9 +93,7 @@ export class AddImageDialogComponent implements OnInit, DoCheck {
}, 10000); }, 10000);
} }
cancelUploading() { cancelUploading() {
this.cancelRequsts.forEach((obj) => { this.cancelRequsts.unsubscribe();
obj.unsubscribe();
});
this.dialogRef.close(); this.dialogRef.close();
this.uploadServiceService.processBarCount(100); this.uploadServiceService.processBarCount(100);
this.toasterService.warning('Image upload cancelled'); this.toasterService.warning('Image upload cancelled');