import { Component , Input , OnDestroy } from '@angular/core' ; import { Group } from '../../../models/group' ; import { GroupService } from '../../../services/group.service' ; import { ReplaySubject } from 'rxjs' ; import { takeUntil } from 'rxjs/operators' ; @ Component ( { selector : 'cmdb-user-table-group-cell' , templateUrl : './user-table-group-cell.component.html' , styleUrls : [ './user-table-group-cell.component.scss' ] } ) export class UserTableGroupCellComponent implements OnDestroy { private private subscriber : ReplaySubject < void > = new ReplaySubject < void > ( ) ; /**
     * List of a loaded groups.
     */ @ Input ( ) public groups : Array < Group > = [ ] ; /**
     * Selected groupID.
     */ public groupID : number ; /**
     * Lazy loaded group.
     */ @ Input ( ) public group : Group ; /**
     * Is the group currently loading.
     */ @ Input ( ) public groupLoadingStack : Array < number > = [ ] ; @ Input ( 'groupID' ) public set GroupID ( groupID ) { this . groupID = groupID ; if ( ! this . groups . some ( g => g . public_id === groupID ) ) { if ( ! this . groupLoadingStack . includes ( groupID ) ) { this . groupLoadingStack . push ( groupID ) ; this . groupService . getGroup ( this . groupID ) . pipe ( takeUntil ( this . subscriber ) ) . subscribe ( ( group ) => { this . groups . push ( group ) ; } ) ; } } } constructor ( private groupService ) { } public ngOnDestroy ( ) { this . subscriber . next ( ) ; this . subscriber . complete ( ) ; } }