import { Component , Input , OnDestroy } from '@angular/core' ; import { Right } from '../../../models/right' ; import { GroupService } from '../../../services/group.service' ; import { takeUntil } from 'rxjs/operators' ; import { ReplaySubject } from 'rxjs' ; import { GroupUsersModalComponent } from '../../../groups/modals/group-users-modal/group-users-modal.component' ; import { RightGroupsModalComponent } from '../../modals/right-groups-modal/right-groups-modal.component' ; import { NgbModal , NgbModalRef } from '@ng-bootstrap/ng-bootstrap' ; @ Component ( { selector : 'cmdb-right-table-groups-cell' , templateUrl : './right-table-groups-cell.component.html' , styleUrls : [ './right-table-groups-cell.component.scss' ] } ) export class RightTableGroupsCellComponent implements OnDestroy { private private subscriber : ReplaySubject < void > = new ReplaySubject < void > ( ) ; private private modalRef : NgbModalRef ; /**
     * Right in this mod.
     */ public right : Right ; public numberOfGroups : number ; @ Input ( 'right' ) public set Right ( r ) { this . right = r ; this . groupService . countGroups ( { rights : this . right . name } ) . pipe ( takeUntil ( this . subscriber ) ) . subscribe ( ( nGroups ) => { this . numberOfGroups = nGroups ; } ) ; } constructor ( private groupService , private modalService ) { } public openGroupListModal ( ) { this . modalRef = this . modalService . open ( RightGroupsModalComponent , { size : 'lg' } ) ; this . modalRef . componentInstance . right = this . right ; } public ngOnDestroy ( ) { if ( this . modalRef ) { this . modalRef . close ( ) ; } this . subscriber . next ( ) ; this . subscriber . complete ( ) ; } }