Mercurial > hg > ugly-duckling
view src/app/feature-extraction-menu/feature-extraction-menu.component.ts @ 431:686cf74aa0a2
Allow clicking whole list item to extract. Kinda makes the plus button redundant. Add guard in extract method.
author | Lucas Thompson <dev@lucas.im> |
---|---|
date | Wed, 07 Jun 2017 08:46:30 +0100 |
parents | 8fee76ab8e90 |
children | 48904aa87ba3 |
line wrap: on
line source
import { Component, OnInit, Output, EventEmitter, Input, OnDestroy } from '@angular/core'; import { FeatureExtractionService } from '../services/feature-extraction/feature-extraction.service'; import {ListResponse} from 'piper'; import {Subscription} from 'rxjs/Subscription'; import {MdSelect} from '@angular/material'; export interface ExtractorOutputInfo { extractorKey: string; combinedKey: string; outputId: string; name: string; } interface ExtractorInfo { name: string; outputs: ExtractorOutputInfo[]; } @Component({ selector: 'ugly-feature-extraction-menu', templateUrl: './feature-extraction-menu.component.html', styleUrls: ['./feature-extraction-menu.component.css'] }) export class FeatureExtractionMenuComponent implements OnInit, OnDestroy { @Input() set disabled(isDisabled: boolean) { this.isDisabled = isDisabled; } get disabled() { return this.isDisabled; } @Input() onRequestOutput: () => void; @Output() requestOutput: EventEmitter<ExtractorOutputInfo>; private isDisabled: boolean; private populateExtractors: (available: ListResponse) => void; extractors: Iterable<ExtractorInfo>; private librariesUpdatedSubscription: Subscription; constructor(private piperService: FeatureExtractionService) { this.extractors = []; this.requestOutput = new EventEmitter<ExtractorOutputInfo>(); this.isDisabled = true; this.populateExtractors = available => { this.extractors = available.available.reduce((acc, staticData) => { const name = staticData.basic.name; const outputs: ExtractorOutputInfo[] = staticData.basicOutputInfo.map(output => { const combinedKey = `${staticData.key}:${output.identifier}`; return { extractorKey: staticData.key, combinedKey: combinedKey, name: output.name, outputId: output.identifier }; }); acc.push({name, outputs}); return acc; }, [] as ExtractorInfo[]); }; } private getFirstSelectedItemOrEmpty(select: MdSelect): string { const selected = select.selected; if (selected) { return selected instanceof Array ? selected[0].value : selected.value; } return ''; } ngOnInit() { this.librariesUpdatedSubscription = this.piperService.librariesUpdated$.subscribe(this.populateExtractors); this.piperService.list().then(this.populateExtractors); } extract(info: ExtractorOutputInfo): void { if (this.onRequestOutput) { this.onRequestOutput(); } if (info && !this.disabled) { this.requestOutput.emit(info); } } load(): void { this.piperService.updateAvailableLibraries(); } ngOnDestroy(): void { this.librariesUpdatedSubscription.unsubscribe(); } }