import { Component , Input , OnDestroy } from '@angular/core' ; import { Group } from '../../../models/group' ; import { UserService } from '../../../services/user.service' ; import { ReplaySubject } from 'rxjs' ; import { takeUntil } from 'rxjs/operators' ; import { GroupUsersModalComponent } from '../../modals/group-users-modal/group-users-modal.component' ; import { NgbModal , NgbModalRef } from '@ng-bootstrap/ng-bootstrap' ; @ Component ( { selector : 'cmdb-group-table-user-cell' , templateUrl : './group-table-user-cell.component.html' , styleUrls : [ './group-table-user-cell.component.scss' ] } ) export class GroupTableUserCellComponent implements OnDestroy { /**
     * User list modal ref.
     */ private modalRef : NgbModalRef ; private subscriber : ReplaySubject < void > = new ReplaySubject < void > ( ) ; public group : Group ; public numberOfUsers : number ; @ Input ( 'group' ) public set Group ( group ) { this . group = group ; this . userService . countUsers ( { group_id : this . group . public_id } ) . pipe ( takeUntil ( this . subscriber ) ) . subscribe ( ( nUsers ) => { this . numberOfUsers = nUsers ; } ) ; } constructor ( private userService , private modalService ) { } public openUserListModal ( group ) { this . modalRef = this . modalService . open ( GroupUsersModalComponent ) ; this . modalRef . componentInstance . group = group ; } public ngOnDestroy ( ) { if ( this . modalRef ) { this . modalRef . close ( ) ; } this . subscriber . next ( ) ; this . subscriber . complete ( ) ; } }