import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'filterCis'
})
export class FilterCisPipe implements PipeTransform {
public transform(cis: Structure[], baseline: Baseline): Structure[] {
if(baseline.isHideElementsActivated){
let newArray = [...cis]
let result = newArray.filter(ci => ci.checked === true).map((item,index) => {
return {
...item,
children : retreiveChildren(item.children)
}
})
console.log("Result array...." , result)
return result;
}else{
return cis;
}
}
private retreiveChildren(children: Structure[]) : Structure[] {
let filteredCis = children && children.filter((ci) =>{
if(ci.children && ci.children.length > 0){
retreiveChildren(ci.children);
}
return ci.checked === true;
}) ;
return filteredCis;
}
}