import { AfterViewInit , Component , ElementRef , EventEmitter , Inject , Input , OnChanges , OnInit , Output , SimpleChanges , Type } from '@angular/core' ; import { DvService , DvServiceFactory , OnEval } from '@deja-vu/core' ; import { User } from '../shared/authentication.model' ; import { API_PATH } from '../authentication.config' ; import * as _ from 'lodash' ; @ Component ( { selector : 'authentication-show-user' , templateUrl : './show-user.component.html' , styleUrls : [ './show-user.component.css' ] } ) export class ShowUserComponent implements AfterViewInit , OnEval , OnInit , OnChanges { @ Input ( ) waitOn : string [ ] = [ ] ; @ Input ( ) id : string | undefined ; @ Input ( ) user : User | undefined ; @ Output ( ) loadedUser = new EventEmitter < User > ( ) ; @ Input ( ) showId = false ; @ Input ( ) showUsername = true ; private dvs : DvService ; constructor ( private readonly elem , private readonly dvf , @ Inject ( API_PATH ) private readonly apiPath ) { } ngOnInit ( ) { this . dvs = this . dvf . forComponent ( this ) . withDefaultWaiter ( ) . build ( ) ; } ngAfterViewInit ( ) { 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 : any ; } > ( this . apiPath , ( ) => ( { params : { inputs : { id : this . id } , extraInfo : { returnFields : `
                id
                username
              ` } } } ) ) ; const userById = res . data . userById ; if ( userById ) { this . user = res . data . userById ; } this . loadedUser . emit ( this . user ) ; } else if ( this . dvs ) { this . dvs . gateway . noRequest ( ) ; } } private canEval ( ) { return ! ! ( this . dvs && this . id && ! this . user ) ; } }