import { Component , EventEmitter , Input , Output } from '@angular/core' ; import { ImportService } from '../../import.service' ; import { Observable , Subscription } from 'rxjs' ; import { CmdbType } from '../../../framework/models/cmdb-type' ; import { ImporterFile } from '../import-object.models' ; import { DndDropEvent , DropEffect } from 'ngx-drag-drop' ; @ Component ( { selector : 'cmdb-type-mapping-base' , template : '' } ) export class TypeMappingBaseComponent { @ Input ( ) public parsedData : any = undefined ; @ Input ( ) public parserConfig : any = { } ; public readonly allowedEffect : any = 'move' ; @ Input ( ) public mappingControls : any = [ ] ; @ Input ( ) public currentMapping : any = [ ] ; @ Output ( ) public mappingChange = new EventEmitter ( ) ; public hasReferences : boolean = false ; public onDragged ( item , list , effect ) { if ( effect === 'move' ) { const index = list . indexOf ( item ) ; list . splice ( index , 1 ) ; } } public moveControl ( item , from , targetIdx , to ) { from . splice ( from . indexOf ( item ) , 1 ) ; item . value = targetIdx ; to . splice ( targetIdx , 1 , item ) ; } public onRemove ( index , list , original ? ) { if ( original && ( list [ index ] !== undefined ) ) { const originalData = list [ index ] ; original . splice ( original . length , 0 , originalData ) ; } list . splice ( index , 1 , '' ) ; this . mappingChange . emit ( this . currentMapping ) ; } public onDrop ( event , list , index ? , original ? ) { if ( typeof index === undefined ) { index = list . length ; } else { if ( original && ( list [ index ] !== undefined ) ) { const originalData = list [ index ] ; original . splice ( original . length , 0 , originalData ) ; } } event . data . value = index ; list . splice ( index , 1 , event . data ) ; this . mappingChange . emit ( this . currentMapping ) ; } }