import { Injectable } from '@angular/core' ; import { of , timer , Observable , Subject } from 'rxjs' ; import { finalize , tap } from 'rxjs/operators' ; /**
 * Activity service
 */ @ Injectable ( { providedIn : 'root' , } ) export class ActivityService { private counter : number = 0 ; private subject : Subject < number > = new Subject ( ) ; /**
     * Retrieve the status of progress bar
     */ public getProgressBar ( ) { return this . subject . asObservable ( ) ; } param { boolean } status public setProgressBar ( status ) { if ( status ) { this . counter ++ ; } if ( ! status ) { this . counter -- ; } if ( this . counter === 0 && status === false ) { timer ( 500 ) . subscribe ( ( ) => this . subject . next ( this . counter ) ) ; } else { this . subject . next ( this . counter ) ; } return this . counter ; } /**
     * Starts the oberservable chain and finishes when complete
     */ public start ( ) { return of ( 0 ) . pipe ( tap ( ( ) => this . setProgressBar ( true ) ) , finalize ( ( ) => this . setProgressBar ( false ) ) ) ; } }