@@ -6,8 +6,8 @@ import {TranslateService} from '@ngx-translate/core';
66import { ResizeEvent } from 'angular-resizable-element' ;
77import { NgxSpinnerService } from 'ngx-spinner' ;
88import { LocalStorageService } from 'ngx-webstorage' ;
9- import { Observable , Subject } from 'rxjs' ;
10- import { filter , takeUntil , tap } from 'rxjs/operators' ;
9+ import { Observable , Subject , throwError , timer , Subscription } from 'rxjs' ;
10+ import { concatMap , filter , retryWhen , takeUntil , tap , finalize } from 'rxjs/operators' ;
1111import { UtmToastService } from '../../../shared/alert/utm-toast.service' ;
1212import {
1313 ElasticFilterDefaultTime
@@ -64,7 +64,8 @@ import {ElasticDataTypesEnum} from "../../../shared/enums/elastic-data-types.enu
6464 styleUrls : [ './alert-view.component.scss' ]
6565} )
6666export class AlertViewComponent implements OnInit , OnDestroy {
67-
67+ private lastRequest :Subscription | null = null
68+ private lastTimeout :any = - 1
6869
6970 constructor ( private elasticDataService : ElasticDataService ,
7071 private modalService : NgbModal ,
@@ -343,10 +344,24 @@ export class AlertViewComponent implements OnInit, OnDestroy {
343344 this . getAlert ( 'on time filter change' ) ;
344345 }
345346
347+ get searching ( ) : boolean {
348+ return this . lastRequest != null ;
349+ }
350+
346351 getAlert ( calledFrom ?: string , filtersParam ?: ElasticFilterType [ ] ) {
347- this . elasticDataService . search ( this . page , this . itemsPerPage ,
352+ if ( this . lastTimeout != - 1 ) {
353+ clearTimeout ( this . lastTimeout )
354+ if ( this . lastRequest ) {
355+ this . lastRequest . unsubscribe ( )
356+ this . lastRequest = null
357+ }
358+ }
359+ this . lastTimeout = setTimeout ( ( ) => {
360+ this . lastRequest = this . elasticDataService . search ( this . page , this . itemsPerPage ,
348361 MAX_SEARCH_RESULTS , this . dataNature ,
349- sanitizeFilters ( this . filters ) , this . sortBy , true ) . subscribe (
362+ sanitizeFilters ( this . filters ) , this . sortBy , true )
363+ . pipe ( finalize ( ( ) => this . lastRequest = null ) )
364+ . subscribe (
350365 ( res : HttpResponse < any > ) => {
351366 this . totalItems = Number ( res . headers . get ( 'X-Total-Count' ) ) ;
352367 this . alerts = res . body ;
@@ -355,8 +370,11 @@ export class AlertViewComponent implements OnInit, OnDestroy {
355370 } ,
356371 ( res : HttpResponse < any > ) => {
357372 this . utmToastService . showError ( 'Error' , 'An error occurred while listing the alerts. Please try again later.' ) ;
373+ this . loading = false ;
374+ this . refreshingAlert = false ;
358375 }
359376 ) ;
377+ } , 100 )
360378 }
361379
362380 saveReport ( ) {
0 commit comments