import { Component , OnInit , OnDestroy , forwardRef , AfterContentInit , OnChanges , SimpleChanges , AfterViewInit } from '@angular/core' ; import { TypeMappingBaseComponent } from '../type-mapping-base.component' ; import { FormControl , FormGroup } from '@angular/forms' ; import { Subscription } from 'rxjs' ; @ Component ( { selector : 'cmdb-csv-mapping' , templateUrl : './csv-mapping.component.html' , styleUrls : [ './csv-mapping.component.scss' ] , providers : [ { provide : TypeMappingBaseComponent , useExisting : forwardRef ( ( ) => CsvMappingComponent ) } ] } ) export class CsvMappingComponent extends TypeMappingBaseComponent implements OnInit , AfterViewInit , OnDestroy { public previewIndex : number = 0 ; public previewIndexSelectionForm : FormGroup ; private previewSelectionSubscription : Subscription ; constructor ( ) { super ( ) ; this . previewIndexSelectionForm = new FormGroup ( { indexSelection : new FormControl ( 0 ) } ) ; this . previewSelectionSubscription = this . previewIndexSelectionForm . get ( 'indexSelection' ) . valueChanges . subscribe ( ( change ) => { this . previewIndex = + change ; } ) ; } public ngOnInit ( ) { for ( let i = 0 ; i < this . parsedData . entry_length ; i ++ ) { this . currentMapping . push ( { } ) ; } } public ngOnDestroy ( ) { this . previewSelectionSubscription . unsubscribe ( ) ; } public ngAfterViewInit ( ) { const moveList = [ ] ; if ( this . parserConfig . header && this . parsedData ) { for ( const control of this . mappingControls ) { if ( control . type === 'ref' ) { continue ; } if ( this . parsedData . header . indexOf ( control . name ) > - 1 ) { moveList . push ( { index : this . parsedData . header . indexOf ( control . name ) , item : control } ) ; } } for ( const moveControl of moveList ) { this . moveControl ( moveControl . item , this . mappingControls , moveControl . index , this . currentMapping ) ; } this . mappingChange . emit ( this . currentMapping ) ; } } }