Mercurial > hg > ng2-query-ismi
comparison app/query-select.component.ts @ 14:7dc7ea95ca26
show result types below query steps.
author | Robert Casties <casties@mpiwg-berlin.mpg.de> |
---|---|
date | Thu, 21 Jan 2016 16:49:55 +0100 |
parents | 98b435bb6c0c |
children | f84ff6781e57 |
comparison
equal
deleted
inserted
replaced
13:98b435bb6c0c | 14:7dc7ea95ca26 |
---|---|
7 | 7 |
8 | 8 |
9 @Component({ | 9 @Component({ |
10 selector: 'query-select', | 10 selector: 'query-select', |
11 template: ` | 11 template: ` |
12 <p *ngIf="resultInfo"> result: {{resultInfo}}</p> | |
12 <div> | 13 <div> |
13 <form (ngSubmit)="onSubmit()"> | 14 <form (ngSubmit)="onSubmit()"> |
14 <select (change)="onSelectMode($event)"> | 15 <select (change)="onSelectMode($event)"> |
15 <option></option> | 16 <option></option> |
16 <option *ngFor="#mode of queryModes" [value]="mode.id"> | 17 <option *ngFor="#mode of queryModes" [value]="mode.id"> |
39 </span> | 40 </span> |
40 <button type="submit">Submit</button> | 41 <button type="submit">Submit</button> |
41 </form> | 42 </form> |
42 </div> | 43 </div> |
43 `, | 44 `, |
44 inputs: ['index'] | 45 inputs: ['queryStep', 'index'] |
45 //outputs: ['queryChanged'] // this should work but doesn't | 46 //outputs: ['queryChanged'] // this should work but doesn't |
46 }) | 47 }) |
47 | 48 |
48 export class QuerySelectComponent implements OnInit { | 49 export class QuerySelectComponent implements OnInit { |
49 public queryStep: QueryStep; | 50 public queryStep: QueryStep; |
50 public index: number; | 51 public index: number; |
52 public resultInfo: string; | |
51 public queryModes: QueryMode[]; | 53 public queryModes: QueryMode[]; |
52 public selectedMode: QueryMode; | 54 public selectedMode: QueryMode; |
53 public queryOptions: string[]; | 55 public queryOptions: string[]; |
54 public selectedOption: string; | 56 public selectedOption: string; |
55 public queryInput: string; | 57 public queryInput: string; |
63 } | 65 } |
64 | 66 |
65 setup() { | 67 setup() { |
66 console.log("query-select setup step=", this.queryStep); | 68 console.log("query-select setup step=", this.queryStep); |
67 this.queryModes = this._queryService.getQueryModes(); | 69 this.queryModes = this._queryService.getQueryModes(); |
70 var step = this._queryService.state.steps[this.index-1]; | |
71 if (step != null) { | |
72 this.resultInfo = step.resultInfo; | |
73 } | |
68 // select first mode (too early?) | 74 // select first mode (too early?) |
69 this.selectedMode = this.queryModes[0]; | 75 this.selectedMode = this.queryModes[0]; |
70 this.query2Options = this._queryService.getQueryOptions(this.selectedMode); | 76 this.query2Options = this._queryService.getQueryOptions(this.selectedMode); |
71 } | 77 } |
72 | 78 |
104 } | 110 } |
105 } else if (this.selectedMode.id == 'att_contains_norm') { | 111 } else if (this.selectedMode.id == 'att_contains_norm') { |
106 var att = this.selectedOption; | 112 var att = this.selectedOption; |
107 var val = this.queryInput; | 113 var val = this.queryInput; |
108 if (att && val) { | 114 if (att && val) { |
115 // run search term through normalizer | |
109 this._queryService.fetchNormalizedString(val) | 116 this._queryService.fetchNormalizedString(val) |
110 .subscribe( | 117 .subscribe( |
111 data => { | 118 data => { |
112 console.debug("openmind norm data=", data); | 119 console.debug("openmind norm data=", data); |
113 step = {'mode': this.selectedMode, 'attribute': att, 'value': val, 'normValue': data.normalized_text}; | 120 step = {'mode': this.selectedMode, 'attribute': att, 'value': val, 'normValue': data.normalized_text}; |
114 this._queryService.setQueryStep(this.index, step); | 121 this._queryService.setQueryStep(this.index, step); |
122 // query has changed now | |
115 this.queryChanged.emit(this._queryService.getState()); | 123 this.queryChanged.emit(this._queryService.getState()); |
116 }, | 124 }, |
117 err => console.error("openmind norm error=", err), | 125 err => console.error("openmind norm error=", err), |
118 () => console.debug("openmind norm query Complete") | 126 () => console.debug("openmind norm query Complete") |
119 ); | 127 ); |
128 // query has not been set yet | |
120 return; | 129 return; |
121 } | 130 } |
122 } | 131 } |
123 | 132 |
124 if (step != null) { | 133 if (step != null) { |