Fixed bug on loading spinner
This commit is contained in:
parent
9e6e11ecae
commit
46719a5e62
|
@ -45,7 +45,7 @@ describe('ConfigurationComponent', () => {
|
|||
name: 'server.ports',
|
||||
properties: {
|
||||
'local.server.port': {
|
||||
value: '8080',
|
||||
value: '9000',
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
@ -55,7 +55,7 @@ describe('Logs Service', () => {
|
|||
name: 'server.ports',
|
||||
properties: {
|
||||
'local.server.port': {
|
||||
value: '8080',
|
||||
value: '9000',
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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(
|
||||
|
@ -67,14 +67,11 @@ export class HomeComponent implements OnInit {
|
|||
namefield: ['', [Validators.required,AutofillValidator]],
|
||||
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
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -13,76 +13,52 @@ 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(req: HttpRequest<any>, next: HttpHandler) {
|
||||
const started = Date.now();
|
||||
let ok: string;
|
||||
// extend server response observable with logging
|
||||
return next.handle(req)
|
||||
.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
|
||||
finalize(() => {
|
||||
const elapsed = Date.now() - started;
|
||||
const msg = `${req.method} "${req.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);
|
||||
})
|
||||
);
|
||||
}else{
|
||||
return new Observable<HttpEvent<any>>();
|
||||
|
||||
}
|
||||
/*
|
||||
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(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
||||
const started = Date.now();
|
||||
let ok: string;
|
||||
// extend server response observable with logging
|
||||
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
|
||||
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);
|
||||
})
|
||||
);
|
||||
}else{
|
||||
return next.handle(request);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue