import { Component, Input, Output, EventEmitter, ChangeDetectionStrategy } from '@angular/core'; import { OutputFamily, Category, Attribute, DatasetOutputFamily } from '../../metamodel/model'; @Component({ selector: 'app-output-tabs', templateUrl: 'output-tabs.component.html', changeDetection: ChangeDetectionStrategy.OnPush }) export class OutputTabsComponent { @Input() outputFamilyList: OutputFamily[]; @Input() categoryList: Category[]; @Input() datasetAttributeList : Attribute[]; @Input() datasetOutputFamilyList: DatasetOutputFamily[]; @Input() outputList: number[]; @Output() changed: EventEmitter<number[]> = new EventEmitter(); isLoading() { if (this.outputFamilyList.length > 0 && this.categoryList.length > 0 && this.datasetAttributeList.length > 0 && this.datasetOutputFamilyList.length > 0 ) { return false; } else { return true; } } getFamily(id: number) { return this.outputFamilyList.find(family => family.id === id); } getCategory(id: number) { return this.categoryList.find(category => category.id === id); } getAttribute(id: number) { return this.datasetAttributeList.find(attribute => attribute.id === id); } isSelected(id: number) { return this.outputList.filter(i => i === id).length > 0; } change(options): void { const clonedOutputList = Object.assign([], this.outputList); Array.apply(null, options).forEach(option => { if (option.selected && clonedOutputList.filter(i => i === +option.value).length < 1) { clonedOutputList.push(+option.value); } else if (!option.selected && clonedOutputList.filter(i => i === +option.value).length > 0) { const index = clonedOutputList.indexOf(+option.value); clonedOutputList.splice(index, 1); } }); this.changed.emit(clonedOutputList); } }