import { AfterContentInit , ChangeDetectorRef , Component , DoCheck , Input , KeyValueDiffer , KeyValueDiffers , OnDestroy , OnInit , ViewChild } from '@angular/core' ; import { BuilderComponent } from '../../builder/builder.component' ; import { CmdbMode } from '../../../modes.enum' ; import { TypeBuilderStepComponent } from '../type-builder-step.component' ; import { ReplaySubject } from 'rxjs' ; import { takeUntil } from 'rxjs/operators' ; import { CmdbType } from '../../../models/cmdb-type' ; @ Component ( { selector : 'cmdb-type-fields-step' , templateUrl : './type-fields-step.component.html' , styleUrls : [ './type-fields-step.component.scss' ] } ) export class TypeFieldsStepComponent extends TypeBuilderStepComponent implements OnInit , DoCheck , OnDestroy { private subscriber : ReplaySubject < void > = new ReplaySubject < void > ( ) ; private typeInstanceDiffer : KeyValueDiffer < string , any > ; public builderValid : boolean = true ; @ Input ( 'typeInstance' ) public set TypeInstance ( instance ) { if ( instance ) { this . typeInstance = instance ; this . typeInstanceDiffer = this . differs . find ( this . typeInstance ) . create ( ) ; } } public constructor ( private differs ) { super ( ) ; } public ngOnInit ( ) { this . typeInstanceDiffer = this . differs . find ( this . typeInstance ) . create ( ) ; } public get status ( ) : boolean { const hasFields = this . typeInstance . fields . length > 0 ; const hasSections = this . typeInstance . render_meta . sections . length > 0 ; return hasFields && hasSections && this . builderValid ; } public ngDoCheck ( ) { const changes = this . typeInstanceDiffer . diff ( this . typeInstance ) ; if ( changes ) { this . valid = this . status ; this . validateChange . emit ( this . valid ) ; } } public onBuilderValidChange ( status ) { this . builderValid = status ; this . valid = this . status ; this . validateChange . emit ( this . valid ) ; } public ngOnDestroy ( ) { this . subscriber . next ( ) ; this . subscriber . complete ( ) ; } }