added OnDestroy method

This commit is contained in:
Maria Teresa Paratore 2023-11-23 17:05:11 +01:00
parent 46719a5e62
commit aff4df706b
3 changed files with 19 additions and 12 deletions

View File

@ -1,9 +1,7 @@
<div class="row" >***{{isLoading}}***
<!--
<div *ngIf="loading" class="loader-container">
<div class="row" >
<div *ngIf="isLoading" class="loader-container">
<mat-spinner mode="indeterminate" style="top: 50%; left: 50%;"></mat-spinner>
</div>
-->
<div class="d-flex flex-row py-4">
<div id="btn-group" class="col-md-3 mt-3">
<button mat-raised-button color="primary"><mat-icon>source</mat-icon> <span>File</span></button>

View File

@ -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(
@ -68,11 +70,11 @@ export class HomeComponent implements OnInit {
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[] {

View File

@ -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);
})
);