1 import {Component, EventEmitter, Input, Output} from "@angular/core";
2 import {IDType, ITreeNode} from "angular-tree-component/dist/defs/api";
3 import * as _ from 'lodash';
6 selector: 'search-component',
7 templateUrl: './search.component.html',
8 styleUrls: ['./search.component.scss']
10 export class SearchComponent {
13 @Input() inputTestId: string;
15 @Output() updateNodes: EventEmitter<any> = new EventEmitter();
17 searchTree(searchText: string): void {
18 if(_.isNil(searchText)){
22 let results: ITreeNode[] = [];
23 this.nodes.forEach( (node) => {
24 __this.searchTreeNode(node, searchText, results);
26 results.forEach(function (result) {
27 __this.expandParentByNodeId(result.id)
29 this.updateNodes.emit({
31 filterValue: searchText
36 expandParentByNodeId(id: IDType): void {
37 this.tree.treeModel.getNodeById(id).parent.expand();
40 searchTreeNode(node, searchText: string, results): void {
41 if (node.name.toLowerCase().indexOf(searchText.toLowerCase()) != -1) {
44 if (node.children != null) {
45 for (let i = 0; i < node.children.length; i++) {
46 this.searchTreeNode(node.children[i], searchText, results);