Mercurial > hg > ugly-duckling
comparison src/app/feature-extraction-menu/feature-extraction-menu.component.ts @ 47:933c64ebcd13
Some extraction logic in place.
author | Lucas Thompson <dev@lucas.im> |
---|---|
date | Mon, 05 Dec 2016 16:57:34 +0000 |
parents | 88052122ec01 |
children | af0b4b05311c |
comparison
equal
deleted
inserted
replaced
46:88052122ec01 | 47:933c64ebcd13 |
---|---|
1 import {Component, OnInit} from '@angular/core'; | 1 import {Component, OnInit, Output, EventEmitter} from '@angular/core'; |
2 import {FeatureExtractionService} from "../services/feature-extraction/feature-extraction.service"; | 2 import {FeatureExtractionService} from "../services/feature-extraction/feature-extraction.service"; |
3 | 3 |
4 interface ExtractorInfo { | 4 export interface ExtractorOutputInfo { |
5 key: string; | 5 extractorKey: string; |
6 combinedKey: string; | |
7 outputId: string; | |
6 name: string; | 8 name: string; |
7 } | 9 } |
8 | 10 |
9 @Component({ | 11 @Component({ |
10 selector: 'app-feature-extraction-menu', | 12 selector: 'app-feature-extraction-menu', |
11 templateUrl: './feature-extraction-menu.component.html', | 13 templateUrl: './feature-extraction-menu.component.html', |
12 styleUrls: ['./feature-extraction-menu.component.css'] | 14 styleUrls: ['./feature-extraction-menu.component.css'] |
13 }) | 15 }) |
14 export class FeatureExtractionMenuComponent implements OnInit { | 16 export class FeatureExtractionMenuComponent implements OnInit { |
15 | 17 |
16 extractors: ExtractorInfo[]; | 18 @Output() requestOutput: EventEmitter<ExtractorOutputInfo>; |
19 | |
20 private extractorsMap: Map<string, ExtractorOutputInfo>; | |
21 extractors: Iterable<ExtractorOutputInfo>; | |
17 | 22 |
18 constructor(private piperService: FeatureExtractionService) { | 23 constructor(private piperService: FeatureExtractionService) { |
24 this.extractorsMap = new Map(); | |
19 this.extractors = []; | 25 this.extractors = []; |
26 this.requestOutput = new EventEmitter(); | |
20 } | 27 } |
21 | 28 |
22 ngOnInit() { | 29 ngOnInit() { |
23 this.piperService.list().then(available => { | 30 this.piperService.list().then(available => { |
24 const maxCharacterLimit = 50; | 31 const maxCharacterLimit = 50; |
25 available.available.forEach(staticData => { | 32 available.available.forEach(staticData => { |
26 if (staticData.basicOutputInfo.length > 1) | 33 const isSingleOutputExtractor = staticData.basicOutputInfo.length === 1; |
27 staticData.basicOutputInfo.forEach(output => this.extractors.push({ | 34 staticData.basicOutputInfo.forEach(output => { |
28 key: `${staticData.key}:${output.identifier}`, | 35 const combinedKey = `${staticData.key}:${output.identifier}`; |
29 name: `${staticData.basic.name}: ${output.name}`.substr(0, maxCharacterLimit) + '...' | 36 this.extractorsMap.set(combinedKey, { |
30 }) | 37 extractorKey: staticData.key, |
31 ); | 38 combinedKey: combinedKey, |
32 else | 39 name: ( |
33 this.extractors.push({ | 40 isSingleOutputExtractor |
34 key: staticData.key, | 41 ? staticData.basic.name |
35 name: staticData.basic.name.substr(0, maxCharacterLimit) + '...' | 42 : `${staticData.basic.name}: ${output.name}` |
43 ).substr(0, maxCharacterLimit) + '...', | |
44 outputId: output.identifier | |
36 }); | 45 }); |
46 }); | |
37 }); | 47 }); |
48 this.extractors = [...this.extractorsMap.values()]; | |
38 }); | 49 }); |
39 } | 50 } |
40 | 51 |
52 extract(combinedKey: string): void { | |
53 this.requestOutput.emit(this.extractorsMap.get(combinedKey)); | |
54 } | |
55 | |
41 } | 56 } |