From aff4df706b5d48f01921d1c5b27462ebb0cd822d Mon Sep 17 00:00:00 2001 From: mariateresa Date: Thu, 23 Nov 2023 17:05:11 +0100 Subject: [PATCH] added OnDestroy method --- src/main/webapp/app/home/home.component.html | 6 ++---- src/main/webapp/app/home/home.component.ts | 21 ++++++++++++------- .../app/shared/spinnercontrol.interceptor.ts | 4 +++- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/main/webapp/app/home/home.component.html b/src/main/webapp/app/home/home.component.html index f062c19..4e38dfc 100644 --- a/src/main/webapp/app/home/home.component.html +++ b/src/main/webapp/app/home/home.component.html @@ -1,9 +1,7 @@ -
***{{isLoading}}*** -
diff --git a/src/main/webapp/app/home/home.component.ts b/src/main/webapp/app/home/home.component.ts index 59dab17..1210f91 100644 --- a/src/main/webapp/app/home/home.component.ts +++ b/src/main/webapp/app/home/home.component.ts @@ -5,14 +5,14 @@ /* eslint-disable @typescript-eslint/no-unnecessary-condition */ /* eslint-disable @typescript-eslint/restrict-plus-operands */ // eslint-disable-next-line @typescript-eslint/no-unsafe-return -import { Component, OnInit } from '@angular/core'; +import { Component, OnDestroy, OnInit } from '@angular/core'; import { LoginService } from 'app/login/login.service'; import { AccountService } from 'app/core/auth/account.service'; import { Account } from 'app/core/auth/account.model'; import { FormBuilder, FormControl, FormGroup, ValidationErrors, ValidatorFn, Validators } from '@angular/forms'; import { Clipboard } from '@angular/cdk/clipboard' -import { Observable, delay, map, startWith } from 'rxjs'; +import { Observable, Subject, Subscription, delay, map, startWith, takeUntil } from 'rxjs'; import { ContextsLoaderService } from 'app/services/contexts-loader.service'; import { IContextNode } from 'app/services/i-context-node'; import { AutofillValidator, instanceOfContext } from './autofill-validator'; @@ -26,7 +26,7 @@ import { SpinnerLoadingService } from 'app/services/spinner-loading.service'; providers: [ContextsLoaderService], }) -export class HomeComponent implements OnInit { +export class HomeComponent implements OnInit, OnDestroy { account: Account | null = null; myContext: IContextNode | null = null; //stringCtxs: string[]; @@ -36,6 +36,8 @@ export class HomeComponent implements OnInit { chooseContextForm: FormGroup | any; resType: string; isLoading: boolean = false; + subscriptions: Subscription[] = []; + constructor( @@ -67,12 +69,12 @@ export class HomeComponent implements OnInit { namefield: ['', [Validators.required,AutofillValidator]], uidfield: [''], }); - - this.progressService.getState() - .pipe(delay(0)) + + this.subscriptions.push(this.progressService.getState() + .pipe() .subscribe(res => { this.isLoading = res; - }); + })); // per la form dei contesti this.ctxLoaderService.fetchAll().subscribe(res => { @@ -85,6 +87,11 @@ export class HomeComponent implements OnInit { ); } + //TODO: CHECK WHY UNSUBSCRIBE DOES NOT WORK + ngOnDestroy(): void { + //alert(this.subscriptions.length); + this.subscriptions.forEach(sub => sub.unsubscribe()); + } //mettere ANY come tipo dell'argomento per evitare errore TypeScript nella map!! filterContexts(/*ctx: IContextNode,*/ item: any): IContextNode[] { diff --git a/src/main/webapp/app/shared/spinnercontrol.interceptor.ts b/src/main/webapp/app/shared/spinnercontrol.interceptor.ts index fcdb524..68d974c 100644 --- a/src/main/webapp/app/shared/spinnercontrol.interceptor.ts +++ b/src/main/webapp/app/shared/spinnercontrol.interceptor.ts @@ -36,6 +36,7 @@ export class SpinnercontrolInterceptor implements HttpInterceptor { let ok: string; // extend server response observable with logging if(request.url.includes('resourceinstances')){ + this.myService.setState(true); return next.handle(request) .pipe( tap({ @@ -46,12 +47,13 @@ export class SpinnercontrolInterceptor implements HttpInterceptor { }), // Log when response observable either completes or errors finalize(() => { + /* const elapsed = Date.now() - started; const msg = `${request.method} "${request.urlWithParams}" ${ok} in ${elapsed} ms.`; console.debug("***** MSG INIZIO ******"); console.debug(msg); - console.debug("***** MSG FINE - ORA METTO A FALSE ******"); + */ this.myService.setState(false); }) );