diff --git a/src/app/common/uploading-processbar/upload-service.service.ts b/src/app/common/uploading-processbar/upload-service.service.ts index 8a2bb38b..71efc849 100644 --- a/src/app/common/uploading-processbar/upload-service.service.ts +++ b/src/app/common/uploading-processbar/upload-service.service.ts @@ -1,14 +1,14 @@ import { Injectable } from '@angular/core'; -import { BehaviorSubject } from 'rxjs'; +import { BehaviorSubject, Subject } from 'rxjs'; @Injectable({ providedIn: 'root' }) export class UploadServiceService { - private countSource = new BehaviorSubject(0); + private countSource = new Subject(); currentCount = this.countSource.asObservable(); - private cancelItem = new BehaviorSubject(false); + private cancelItem = new Subject(); currentCancelItemDetails = this.cancelItem.asObservable(); constructor() { } diff --git a/src/app/common/uploading-processbar/uploading-processbar.component.ts b/src/app/common/uploading-processbar/uploading-processbar.component.ts index 913f3eb5..a77c85d7 100644 --- a/src/app/common/uploading-processbar/uploading-processbar.component.ts +++ b/src/app/common/uploading-processbar/uploading-processbar.component.ts @@ -21,7 +21,7 @@ export class UploadingProcessbarComponent implements OnInit { ) { } ngOnInit() { - this.subscription = this._US.currentCount.subscribe((count) => { + this.subscription = this._US.currentCount.subscribe((count:number) => { this.uploadProgress = count; if (this.uploadProgress === 100) { this.dismiss() diff --git a/src/app/components/preferences/dynamips/add-ios-template/add-ios-template.component.ts b/src/app/components/preferences/dynamips/add-ios-template/add-ios-template.component.ts index cdac0bc7..17d7d25d 100644 --- a/src/app/components/preferences/dynamips/add-ios-template/add-ios-template.component.ts +++ b/src/app/components/preferences/dynamips/add-ios-template/add-ios-template.component.ts @@ -1,11 +1,12 @@ import { Location } from '@angular/common'; -import { Component, OnInit } from '@angular/core'; +import { Component, OnDestroy, OnInit } from '@angular/core'; import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'; import { MatSnackBar } from '@angular/material/snack-bar'; import { ActivatedRoute, Router } from '@angular/router'; import { UploadServiceService } from 'app/common/uploading-processbar/upload-service.service'; import { UploadingProcessbarComponent } from 'app/common/uploading-processbar/uploading-processbar.component'; import { FileItem, FileUploader, ParsedResponseHeaders } from 'ng2-file-upload'; +import { Subscription } from 'rxjs'; import { v4 as uuid } from 'uuid'; import { Compute } from '../../../../models/compute'; import { IosImage } from '../../../../models/images/ios-image'; @@ -23,7 +24,7 @@ import { ToasterService } from '../../../../services/toaster.service'; templateUrl: './add-ios-template.component.html', styleUrls: ['./add-ios-template.component.scss', '../../preferences.component.scss'], }) -export class AddIosTemplateComponent implements OnInit { +export class AddIosTemplateComponent implements OnInit, OnDestroy { server: Server; iosTemplate: IosTemplate; isEtherSwitchRouter: boolean = false; @@ -51,6 +52,7 @@ export class AddIosTemplateComponent implements OnInit { uploader: FileUploader; isLocalComputerChosen: boolean = true; uploadProgress:number = 0; + subscription: Subscription; constructor( private route: ActivatedRoute, @@ -103,7 +105,7 @@ export class AddIosTemplateComponent implements OnInit { this.uploadProgress = progress['progress']; this.uploadServiceService.processBarCount(this.uploadProgress) }; - this.uploadServiceService.currentCancelItemDetails.subscribe((isCancel) => { + this.subscription = this.uploadServiceService.currentCancelItemDetails.subscribe((isCancel) => { if (isCancel) { this.cancelUploading() } @@ -274,8 +276,11 @@ export class AddIosTemplateComponent implements OnInit { this.uploader.clearQueue(); this.uploadServiceService.processBarCount(100) this.toasterService.warning('Image upload cancelled'); - this.uploadServiceService.cancelFileUploading(false) - window.location.reload() + // this.uploadServiceService.cancelFileUploading(false) + // window.location.reload() } + ngOnDestroy() { + this.subscription.unsubscribe(); + } } diff --git a/src/app/components/preferences/ios-on-unix/add-iou-template/add-iou-template.component.ts b/src/app/components/preferences/ios-on-unix/add-iou-template/add-iou-template.component.ts index 835156ef..55cb18be 100644 --- a/src/app/components/preferences/ios-on-unix/add-iou-template/add-iou-template.component.ts +++ b/src/app/components/preferences/ios-on-unix/add-iou-template/add-iou-template.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnDestroy, OnInit } from '@angular/core'; import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'; import { MatSnackBar } from '@angular/material/snack-bar'; import { ActivatedRoute, Router } from '@angular/router'; @@ -22,7 +22,7 @@ import { ToasterService } from '../../../../services/toaster.service'; templateUrl: './add-iou-template.component.html', styleUrls: ['./add-iou-template.component.scss', '../../preferences.component.scss'], }) -export class AddIouTemplateComponent implements OnInit { +export class AddIouTemplateComponent implements OnInit, OnDestroy { server: Server; iouTemplate: IouTemplate; isRemoteComputerChosen: boolean = false; @@ -68,7 +68,6 @@ export class AddIouTemplateComponent implements OnInit { }; this.uploader.onErrorItem = (item: FileItem, response: string, status: number, headers: ParsedResponseHeaders) => { this.toasterService.error('An error occured: ' + response); - this.setDiskImage('existingImage') }; this.uploader.onProgressItem = (progress: any) => { this.uploadProgress = progress['progress']; @@ -93,7 +92,7 @@ export class AddIouTemplateComponent implements OnInit { this.iouTemplate = iouTemplate; }); }); - this.uploadServiceService.currentCancelItemDetails.subscribe((isCancel) => { + this.subscription = this.uploadServiceService.currentCancelItemDetails.subscribe((isCancel) => { if (isCancel) { this.cancelUploading() } @@ -138,9 +137,8 @@ export class AddIouTemplateComponent implements OnInit { this.uploader.clearQueue(); this.uploadServiceService.processBarCount(100) this.toasterService.warning('Image upload cancelled'); - this.uploadServiceService.cancelFileUploading(false) - window.location.reload() - + // this.uploadServiceService.cancelFileUploading(false) + // window.location.reload() } @@ -174,4 +172,8 @@ export class AddIouTemplateComponent implements OnInit { this.toasterService.error(`Fill all required fields`); } } + + ngOnDestroy() { + this.subscription.unsubscribe(); + } }