import { Component , EventEmitter , Input , Output } from '@angular/core' ; import { CmdbCategoryNode , CmdbCategoryTree } from '../../../models/cmdb-category' ; import { DndDropEvent , DropEffect } from 'ngx-drag-drop' ; import { CmdbMode } from '../../../modes.enum' ; @ Component ( { selector : 'cmdb-category-tree' , templateUrl : './category-tree.component.html' , styleUrls : [ './category-tree.component.scss' ] } ) export class CategoryTreeComponent { /**
     * Edit mode of tree
     */ @ Input ( ) public mode : CmdbMode = CmdbMode . View ; /**
     * Root element of the category tree
     */ @ Input ( ) public tree : CmdbCategoryTree ; /**
     * Possible dnd effect
     */ public effect : DropEffect = 'move' ; /**
     * Tree change emitter
     */ @ Output ( ) public change : EventEmitter < { type : string ; value : any ; } > ; /**
     * Constructor of CategoryTreeComponent
     */ public constructor ( ) { this . change = new EventEmitter < { type : string ; value : any ; } > ( ) ; } param item param tree param effect public onDragged ( item , tree , effect ) { if ( effect === 'move' ) { const index = tree . indexOf ( item ) ; tree . splice ( index , 1 ) ; } } param event param tree public onDrop ( event , tree ? ) { let index = event . index ; if ( typeof index === 'undefined' ) { index = tree . length ; } tree . splice ( index , 0 , event . data ) ; this . updateTree ( tree ) ; } param tree public updateTree ( tree ) { for ( let i = 0 ; i < tree . length ; i ++ ) { const node = tree [ i ] ; node . category . meta . order = i ; } return tree ; } }