import { AfterViewInit , Component , Input , OnChanges , OnDestroy , OnInit } from '@angular/core' ; import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap' ; import { CmdbType } from '../../../models/cmdb-type' ; import { TypeService } from '../../../services/type.service' ; import { ObjectService } from '../../../services/object.service' ; import { UserService } from '../../../../management/services/user.service' ; import { ReplaySubject } from 'rxjs' ; import { takeUntil } from 'rxjs/operators' ; @ Component ( { selector : 'cmdb-cleanup-modal' , templateUrl : './cleanup-modal.component.html' , styleUrls : [ './cleanup-modal.component.scss' ] } ) export class CleanupModalComponent implements AfterViewInit , OnDestroy { /**
     * Component un-subscriber.
     */ private subscriber : ReplaySubject < void > = new ReplaySubject < void > ( ) ; /**
     * Type instance of the cleanable objects.
     */ @ Input ( ) public type : CmdbType ; /**
     * Number of uncleaned objects.
     */ public numberOfObjects : number = 0 ; /**
     * In current cleaning operation
     */ public cleaning : boolean = false ; constructor ( private typeService , private objectService , public userService , public activeModal ) { } public ngAfterViewInit ( ) { this . objectService . countUncleanObjects ( this . type . public_id ) . pipe ( takeUntil ( this . subscriber ) ) . subscribe ( ( count ) => { this . numberOfObjects = count ; } ) ; } /**
     * Triggers the api clean call.
     */ public clean ( ) { this . cleaning = true ; this . objectService . cleanObjects ( this . type . public_id ) . pipe ( takeUntil ( this . subscriber ) ) . subscribe ( ( ) => { this . cleaning = false ; this . activeModal . close ( 'Clean' ) ; } ) ; } public ngOnDestroy ( ) { this . subscriber . next ( ) ; this . subscriber . complete ( ) ; } }