import { TreeElement } from "../classes/TreeElement" ; export default class TreeService { public searchTreeNode ( tree , key ) { if ( tree ) { return this . searchKeyInElement ( key , tree ) ; } else { return null ; } } public getAllSceneElementsRecursive ( tree , id ) { const node = this . searchTreeNode ( tree , id ) ; if ( node === null ) { return [ ] ; } else { return this . privateGetAllSceneElementsRecursive ( node ) ; } } public getAllFiles ( node ) { let results = [ ] ; if ( node . isFile ( ) ) { results . push ( node ) ; } for ( const child of node . children ) { const result = this . getAllFiles ( child ) ; results = results . concat ( result ) ; } return results ; } private searchKeyInElement ( key , element ) { if ( element . key === key ) { return element ; } for ( const child of element . children ) { const result = this . searchKeyInElement ( key , child ) ; if ( result ) { return result ; } } return null ; } private privateGetAllSceneElementsRecursive ( node ) { let showIds = [ ] ; showIds . push ( node . key ) ; for ( const child of node . children ) { const result = this . privateGetAllSceneElementsRecursive ( child ) ; showIds = showIds . concat ( result ) ; } return showIds ; } }