import { AfterViewInit , Component , ElementRef , EventEmitter , Inject , Input , OnChanges , OnDestroy , OnInit , Output , SimpleChanges , Type } from '@angular/core' ; import { ComponentValue , DvService , DvServiceFactory , OnEval , RunService } from '@deja-vu/core' ; import { Group } from '../shared/group.model' ; import { ShowMemberComponent } from '../show-member/show-member.component' ; import * as _ from 'lodash' ; @ Component ( { selector : 'group-show-group' , templateUrl : './show-group.component.html' , styleUrls : [ './show-group.component.css' ] } ) export class ShowGroupComponent implements AfterViewInit , OnEval , OnInit , OnChanges , OnDestroy { @ Input ( ) waitOn : string [ ] = [ ] ; @ Input ( ) group : Group | undefined ; @ Input ( ) id : string | undefined ; @ Input ( ) showMembers = true ; @ Input ( ) showGroupId = true ; @ Input ( ) showMember : ComponentValue = { type : < Type < Component > > ShowMemberComponent } ; @ Output ( ) loadedGroup = new EventEmitter < Group > ( ) ; showGroup ; private dvs : DvService ; constructor ( private readonly elem , private readonly dvf ) { this . showGroup = this ; } ngOnInit ( ) { this . dvs = this . dvf . forComponent ( this ) . withDefaultWaiter ( ) . withRefreshCallback ( ( ) => { this . load ( ) ; } ) . build ( ) ; } ngAfterViewInit ( ) { if ( ! this . group && ! ! this . id ) { this . load ( ) ; } } ngOnChanges ( changes ) { if ( this . dvs && this . dvs . waiter . processChanges ( changes ) ) { this . load ( ) ; } } load ( ) { if ( this . canEval ( ) ) { this . dvs . eval ( ) ; } } async dvOnEval ( ) { if ( this . canEval ( ) ) { const res = await this . dvs . waitAndGet < { data : { group : Group ; } ; } > ( '/graphql' , ( ) => ( { params : { inputs : { id : this . id } , extraInfo : { returnFields : `
              id
              memberIds
            ` } } } ) ) ; this . group = res . data . group ; this . loadedGroup . emit ( this . group ) ; } else if ( this . dvs ) { this . dvs . noRequest ( ) ; } } ngOnDestroy ( ) { this . dvs . onDestroy ( ) ; } private canEval ( ) { return ! ! ( this . dvs ) ; } }