import { Component, Input, OnInit, Output, EventEmitter } from '@angular/core'; import { CallVector, setCallVectorsReferences } from '@creedinteractive/onguard-models'; @Component({ selector: 'onguard-call-vector-summary', templateUrl: './call-vector-summary.component.html', styleUrls: ['./call-vector-summary.component.scss'], }) export class CallVectorSummaryComponent implements OnInit { @Input() callVectors: CallVector[] = []; @Output() selectCallVectorEvent = new EventEmitter(); vectorsThatJumpToThemselves: CallVector[] = []; vectorsWithoutSteps: CallVector[] = []; vectorsThatReferenceNoneExistingVectors: CallVector[] = []; vectorsThatJump: CallVector[] = []; vectorsThatDoNotJump: CallVector[] = []; vectorsThatAreReferenced: CallVector[] = []; vectorsThatAreNotReferenced: CallVector[] = []; constructor() {} ngOnInit(): void { this._partitionVectors(); } selectCallVector(callVector: CallVector): void { this.selectCallVectorEvent.emit(callVector); } /** * Split Call Vectors into lists to be displayed. */ private _partitionVectors(): void { this.callVectors.forEach((callVector: CallVector) => { if (callVector.linkedTo.some((x) => x?.Number === callVector.Number)) { this.vectorsThatJumpToThemselves.push(callVector); } if (callVector.stepsParsed.length === 0) { this.vectorsWithoutSteps.push(callVector); } if (callVector.stepsParsed.some((stepParsed) => stepParsed.linkedVector === null)) { this.vectorsThatReferenceNoneExistingVectors.push(callVector); } // Partition vectors on an exclusive comparision. (callVector.linkedTo.length > 0 && // Check to see if the only vector referenced is itself. callVector.linkedTo.every((x) => x?.Number !== callVector?.Number) ? this.vectorsThatJump : this.vectorsThatDoNotJump ).push(callVector); (callVector.linkedBy.length > 0 ? this.vectorsThatAreReferenced : this.vectorsThatAreNotReferenced ).push(callVector); }); } }