Mercurial > hg > ugly-duckling
comparison src/app/feature-extraction-menu/feature-extraction-menu.component.ts @ 74:2c3fe51ad1f0
Wire up methods in the FeatureExtractionService for offloading to the worker and consume them from the feature extraction menu.
author | Lucas Thompson <dev@lucas.im> |
---|---|
date | Wed, 18 Jan 2017 10:19:35 +0000 |
parents | 8619f25ff52a |
children | bf8826d4e2c6 |
comparison
equal
deleted
inserted
replaced
73:d3abd81e8ab6 | 74:2c3fe51ad1f0 |
---|---|
1 import {Component, OnInit, Output, EventEmitter, Input} from '@angular/core'; | 1 import { |
2 Component, OnInit, Output, EventEmitter, Input, | |
3 OnDestroy | |
4 } from '@angular/core'; | |
2 import {FeatureExtractionService} from "../services/feature-extraction/feature-extraction.service"; | 5 import {FeatureExtractionService} from "../services/feature-extraction/feature-extraction.service"; |
6 import {ListResponse} from "piper"; | |
7 import {Subscription} from "rxjs"; | |
3 | 8 |
4 export interface ExtractorOutputInfo { | 9 export interface ExtractorOutputInfo { |
5 extractorKey: string; | 10 extractorKey: string; |
6 combinedKey: string; | 11 combinedKey: string; |
7 outputId: string; | 12 outputId: string; |
11 @Component({ | 16 @Component({ |
12 selector: 'app-feature-extraction-menu', | 17 selector: 'app-feature-extraction-menu', |
13 templateUrl: './feature-extraction-menu.component.html', | 18 templateUrl: './feature-extraction-menu.component.html', |
14 styleUrls: ['./feature-extraction-menu.component.css'] | 19 styleUrls: ['./feature-extraction-menu.component.css'] |
15 }) | 20 }) |
16 export class FeatureExtractionMenuComponent implements OnInit { | 21 export class FeatureExtractionMenuComponent implements OnInit, OnDestroy { |
17 | 22 |
18 @Input() | 23 @Input() |
19 set disabled(isDisabled: boolean) { | 24 set disabled(isDisabled: boolean) { |
20 this.isDisabled = isDisabled; | 25 this.isDisabled = isDisabled; |
21 } | 26 } |
26 | 31 |
27 @Output() requestOutput: EventEmitter<ExtractorOutputInfo>; | 32 @Output() requestOutput: EventEmitter<ExtractorOutputInfo>; |
28 | 33 |
29 private isDisabled: boolean; | 34 private isDisabled: boolean; |
30 private extractorsMap: Map<string, ExtractorOutputInfo>; | 35 private extractorsMap: Map<string, ExtractorOutputInfo>; |
36 private populateExtractors: (available: ListResponse) => void; | |
31 extractors: Iterable<ExtractorOutputInfo>; | 37 extractors: Iterable<ExtractorOutputInfo>; |
38 private librariesUpdatedSubscription: Subscription; | |
32 | 39 |
33 constructor(private piperService: FeatureExtractionService) { | 40 constructor(private piperService: FeatureExtractionService) { |
34 this.extractorsMap = new Map(); | 41 this.extractorsMap = new Map(); |
35 this.extractors = []; | 42 this.extractors = []; |
36 this.requestOutput = new EventEmitter<ExtractorOutputInfo>(); | 43 this.requestOutput = new EventEmitter<ExtractorOutputInfo>(); |
37 this.isDisabled = true; | 44 this.isDisabled = true; |
38 } | 45 this.populateExtractors = available => { |
39 | |
40 ngOnInit() { | |
41 this.piperService.list().then(available => { | |
42 const maxCharacterLimit = 50; | 46 const maxCharacterLimit = 50; |
43 available.available.forEach(staticData => { | 47 available.available.forEach(staticData => { |
44 const isSingleOutputExtractor = staticData.basicOutputInfo.length === 1; | 48 const isSingleOutputExtractor = staticData.basicOutputInfo.length === 1; |
45 staticData.basicOutputInfo.forEach(output => { | 49 staticData.basicOutputInfo.forEach(output => { |
46 const combinedKey = `${staticData.key}:${output.identifier}`; | 50 const combinedKey = `${staticData.key}:${output.identifier}`; |
55 outputId: output.identifier | 59 outputId: output.identifier |
56 }); | 60 }); |
57 }); | 61 }); |
58 }); | 62 }); |
59 this.extractors = [...this.extractorsMap.values()]; | 63 this.extractors = [...this.extractorsMap.values()]; |
60 }); | 64 }; |
65 } | |
66 | |
67 ngOnInit() { | |
68 this.piperService.list().then(this.populateExtractors); | |
69 this.librariesUpdatedSubscription = this.piperService.librariesUpdated$.subscribe(this.populateExtractors); | |
61 } | 70 } |
62 | 71 |
63 extract(combinedKey: string): void { | 72 extract(combinedKey: string): void { |
64 this.requestOutput.emit(this.extractorsMap.get(combinedKey)); | 73 this.requestOutput.emit(this.extractorsMap.get(combinedKey)); |
65 } | 74 } |
66 | 75 |
76 load(): void { | |
77 this.piperService.updateAvailableLibraries().subscribe(res => { | |
78 Object.keys(res).forEach(key => this.piperService.load(key)); | |
79 }); | |
80 } | |
81 | |
82 ngOnDestroy(): void { | |
83 this.librariesUpdatedSubscription.unsubscribe(); | |
84 } | |
67 } | 85 } |