Fixed bug on loading spinner

This commit is contained in:
Maria Teresa Paratore 2023-11-23 13:20:38 +01:00
parent 9e6e11ecae
commit 46719a5e62
7 changed files with 69 additions and 90 deletions

View File

@ -45,7 +45,7 @@ describe('ConfigurationComponent', () => {
name: 'server.ports',
properties: {
'local.server.port': {
value: '8080',
value: '9000',
},
},
},

View File

@ -55,7 +55,7 @@ describe('Logs Service', () => {
name: 'server.ports',
properties: {
'local.server.port': {
value: '8080',
value: '9000',
},
},
},

View File

@ -1,7 +1,9 @@
<div class="row" >
<div class="row" >***{{isLoading}}***
<!--
<div *ngIf="loading" 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

@ -10,9 +10,9 @@ import { Component, 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 { AbstractControl, FormBuilder, FormControl, FormGroup, ValidationErrors, ValidatorFn, Validators } from '@angular/forms';
import { FormBuilder, FormControl, FormGroup, ValidationErrors, ValidatorFn, Validators } from '@angular/forms';
import { Clipboard } from '@angular/cdk/clipboard'
import { BehaviorSubject, Observable, delay, map, startWith } from 'rxjs';
import { Observable, delay, map, startWith } from 'rxjs';
import { ContextsLoaderService } from 'app/services/contexts-loader.service';
import { IContextNode } from 'app/services/i-context-node';
import { AutofillValidator, instanceOfContext } from './autofill-validator';
@ -23,7 +23,7 @@ import { SpinnerLoadingService } from 'app/services/spinner-loading.service';
selector: 'jhi-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.scss'],
providers: [ContextsLoaderService, SpinnerLoadingService],
providers: [ContextsLoaderService],
})
export class HomeComponent implements OnInit {
@ -35,7 +35,7 @@ export class HomeComponent implements OnInit {
//public filteredContextsStr: Observable<string[]>| undefined;
chooseContextForm: FormGroup | any;
resType: string;
loading: boolean = false;
isLoading: boolean = false;
constructor(
@ -68,13 +68,10 @@ export class HomeComponent implements OnInit {
uidfield: [''],
});
//TODO: DEBUG HERE
//sembra tutto giusto, ma non viene rilevato l'aggiornamento del valore booleano
this.progressService.getState()
.subscribe((loading) => {
this.loading = loading;
console.debug("**********this.loading..."+this.loading);
.pipe(delay(0))
.subscribe(res => {
this.isLoading = res;
});
// per la form dei contesti

View File

@ -11,17 +11,21 @@ import { BehaviorSubject, Observable } from 'rxjs';
export class SpinnerLoadingService {
private state: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(true);
//TODO: a regime inizializzare a true
private state: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(true);
constructor() { }
constructor() {
}
getState():Observable<boolean>{
console.debug("*******Getting observable state in SpinnerLoadingService");
// console.debug("*******Getting observable state in SpinnerLoadingService");
return this.state.asObservable();
};
setState(newState : boolean) : void{
console.debug("******Setting state in SpinnerLoadingService: ");
// console.debug("******Setting state in SpinnerLoadingService: ");
// console.debug(newState);
// console.debug("******");
this.state.next(newState);
};

View File

@ -66,7 +66,7 @@ describe('Alert Error Component', () => {
it('Should display an alert on status 400 for generic error', () => {
// GIVEN
const response = new HttpErrorResponse({
url: 'http://localhost:8080/api/foos',
url: 'http://localhost:9000/api/foos',
headers: new HttpHeaders(),
status: 400,
statusText: 'Bad Request',
@ -87,7 +87,7 @@ describe('Alert Error Component', () => {
it('Should display an alert on status 400 for generic error without message', () => {
// GIVEN
const response = new HttpErrorResponse({
url: 'http://localhost:8080/api/foos',
url: 'http://localhost:9000/api/foos',
headers: new HttpHeaders(),
status: 400,
error: 'Bad Request',
@ -101,7 +101,7 @@ describe('Alert Error Component', () => {
it('Should display an alert on status 400 for invalid parameters', () => {
// GIVEN
const response = new HttpErrorResponse({
url: 'http://localhost:8080/api/foos',
url: 'http://localhost:9000/api/foos',
headers: new HttpHeaders(),
status: 400,
statusText: 'Bad Request',
@ -123,7 +123,7 @@ describe('Alert Error Component', () => {
it('Should display an alert on status 400 for error headers', () => {
// GIVEN
const response = new HttpErrorResponse({
url: 'http://localhost:8080/api/foos',
url: 'http://localhost:9000/api/foos',
headers: new HttpHeaders().append('app-error', 'Error Message').append('app-params', 'foo'),
status: 400,
statusText: 'Bad Request',
@ -141,7 +141,7 @@ describe('Alert Error Component', () => {
it('Should display an alert on status 500 with detail', () => {
// GIVEN
const response = new HttpErrorResponse({
url: 'http://localhost:8080/api/foos',
url: 'http://localhost:9000/api/foos',
headers: new HttpHeaders(),
status: 500,
statusText: 'Internal server error',

View File

@ -13,26 +13,30 @@ import { SpinnerLoadingService } from 'app/services/spinner-loading.service';
@Injectable()
export class SpinnercontrolInterceptor implements HttpInterceptor {
/*
Like intercept(), the handle() method transforms an HTTP request into an Observable
of HttpEvents which ultimately include the server's response.
The intercept() method could inspect that observable and alter it before returning
it to the caller.
*/
private myService : SpinnerLoadingService;
constructor(private spinnerLoaderServ: SpinnerLoadingService) {
this.myService = spinnerLoaderServ;
constructor(private myService: SpinnerLoadingService) {
}
/*
intercept(request: HttpRequest<any>,next: HttpHandler): Observable<HttpEvent<any>> {
//console.log('********Outgoing HTTP request', request);
if(request.url.includes('resourceinstances')){
finalize(() => {
console.debug("***setting to false");
this.myService.setState(false);
})
return next.handle(request);
}
return next.handle(request);
}
*/
/*
intercept(req: HttpRequest<any>, next: HttpHandler) {
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const started = Date.now();
let ok: string;
// extend server response observable with logging
return next.handle(req)
if(request.url.includes('resourceinstances')){
return next.handle(request)
.pipe(
tap({
// Succeeds when there is a response; ignore other events
@ -43,46 +47,18 @@ export class SpinnercontrolInterceptor implements HttpInterceptor {
// Log when response observable either completes or errors
finalize(() => {
const elapsed = Date.now() - started;
const msg = `${req.method} "${req.urlWithParams}"
const msg = `${request.method} "${request.urlWithParams}"
${ok} in ${elapsed} ms.`;
console.debug("***** MSG INIZIO ******");
console.debug(msg);
console.debug("***** MSG FINE ******");
this.spinnerLoaderServ.setState(false);
})
);
}
*/
intercept(
request: HttpRequest<any>,next: HttpHandler): Observable<HttpEvent<Response>> {
let ok: string;
//console.log('********Outgoing HTTP request', request);
if(request.url.includes('resourceinstances')){
return next.handle(request).pipe(
tap({
// Succeeds when there is a response; ignore other events
next: (event) => (ok = event instanceof HttpResponse ? 'succeeded' : ''),
// Operation failed; error is an HttpErrorResponse
error: (_error) => (ok = 'failed')
}),
// Log when response observable either completes or errors
//TODO: aggiungere booleano per gestione errore risposta REST (div errore con messaggio)
finalize(() => {
/*
const msg = '${request.method} "${request.urlWithParams}"';
console.debug("***** MSG INIZIO ******");
console.debug(msg);
console.debug("***** MSG FINE ******");
*/
this.spinnerLoaderServ.setState(false);
console.debug("***** MSG FINE - ORA METTO A FALSE ******");
this.myService.setState(false);
})
);
}else{
return new Observable<HttpEvent<any>>();
return next.handle(request);
}
}
}