Skip to content
Snippets Groups Projects
output-tabs.component.ts 1.99 KiB
Newer Older
  • Learn to ignore specific revisions
  • François Agneray's avatar
    François Agneray committed
    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[];
    
    François Agneray's avatar
    François Agneray committed
        @Input() datasetAttributeList : Attribute[];
    
    François Agneray's avatar
    François Agneray committed
        @Input() datasetOutputFamilyList: DatasetOutputFamily[];
        @Input() outputList: number[];
        @Output() changed: EventEmitter<number[]> = new EventEmitter();
    
        isLoading() {
            if (this.outputFamilyList.length > 0 &&
                this.categoryList.length > 0 &&
    
    François Agneray's avatar
    François Agneray committed
                this.datasetAttributeList.length > 0 &&
    
    François Agneray's avatar
    François Agneray committed
                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) {
    
    François Agneray's avatar
    François Agneray committed
            return this.datasetAttributeList.find(attribute => attribute.id === id);
    
    François Agneray's avatar
    François Agneray committed
        }
    
        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);
        }
    }