Mercurial > hg > ng2-query-ismi
comparison src/app/query-select.component.ts @ 58:3b4046e0cc02 default
Merge from ng2-table branch.
d7c947909ab888c013171b8c037e4f9fab30fe57
author | casties |
---|---|
date | Wed, 29 Mar 2017 17:19:12 +0200 |
parents | d7c947909ab8 |
children | 6adf95d9a190 |
comparison
equal
deleted
inserted
replaced
49:781a5387ca93 | 58:3b4046e0cc02 |
---|---|
15 <p *ngIf="resultInfo"> result: {{resultInfo}}</p> | 15 <p *ngIf="resultInfo"> result: {{resultInfo}}</p> |
16 <div> | 16 <div> |
17 <form (ngSubmit)="onSubmit()"> | 17 <form (ngSubmit)="onSubmit()"> |
18 <select name="mode" (change)="onSelectMode($event)"> | 18 <select name="mode" (change)="onSelectMode($event)"> |
19 <option></option> | 19 <option></option> |
20 <option *ngFor="let mode of getQueryModes()" [value]="mode.id"> | 20 <option *ngFor="let mode of getQueryModes()" |
21 [selected]="mode.id==selectedMode?.id" [value]="mode.id"> | |
21 {{mode.label}} | 22 {{mode.label}} |
22 </option> | 23 </option> |
23 </select> | 24 </select> |
24 | 25 |
25 <span *ngIf="selectedMode?.id=='type_is'"> | 26 <span *ngIf="selectedMode?.id=='type_is'"> |
78 | 79 |
79 export class QuerySelectComponent implements OnInit { | 80 export class QuerySelectComponent implements OnInit { |
80 public queryStep: string; | 81 public queryStep: string; |
81 public index: number; | 82 public index: number; |
82 public resultInfo: string; | 83 public resultInfo: string; |
83 public queryModes: QueryMode[]; | 84 public queryModes: Array<QueryMode>; |
84 public selectedMode: QueryMode; | 85 public selectedMode: QueryMode; |
85 public queryOptions: string[]; | 86 public queryOptions: any[]; |
86 public selectedOption: string; | 87 public selectedOption: string; |
87 public queryInput: string; | 88 public queryInput: string; |
88 public queryInput2: string; | 89 public queryInput2: string; |
89 | 90 |
90 // output queryChanged | 91 // output queryChanged |
96 this.setup(); | 97 this.setup(); |
97 } | 98 } |
98 | 99 |
99 setup() { | 100 setup() { |
100 console.log("query-select setup step=", this.queryStep); | 101 console.log("query-select setup step=", this.queryStep); |
101 var step = this._queryService.state.steps[this.index-1]; | 102 var step = this._queryService.state.steps[this.index]; // i-1? |
102 if (step != null) { | 103 if (step != null) { |
103 this.resultInfo = step.resultInfo; | 104 this.setQueryStep(step); |
104 } | 105 } |
105 } | 106 } |
106 | 107 |
107 getQueryModes(): QueryMode[] { | 108 getQueryModes(): QueryMode[] { |
108 this.queryModes = this._queryService.getQueryModes(this.index); | 109 this.queryModes = this._queryService.getQueryModes(this.index); |
122 this.onSubmit(); | 123 this.onSubmit(); |
123 } | 124 } |
124 | 125 |
125 onSubmit() { | 126 onSubmit() { |
126 console.debug("Submit! selectedMode=", this.selectedMode, " selectedOption=", this.selectedOption, " queryInput=", this.queryInput); | 127 console.debug("Submit! selectedMode=", this.selectedMode, " selectedOption=", this.selectedOption, " queryInput=", this.queryInput); |
127 var step: QueryStep; | 128 |
128 if (this.selectedMode.id == 'type_is') { | 129 let step = this.getQueryStep(); |
130 | |
131 /* | |
132 * set step and submit change event | |
133 */ | |
134 if (step != null) { | |
135 this._queryService.setQueryStep(this.index, step); | |
136 this.queryChanged.emit(this._queryService.getState()); | |
137 } | |
138 return false; | |
139 } | |
140 | |
141 /** | |
142 * Returns QueryStep from current form state. | |
143 */ | |
144 getQueryStep(): QueryStep { | |
145 let step: QueryStep = null; | |
146 | |
147 if (this.selectedMode.id === 'type_is') { | |
129 /* | 148 /* |
130 * type_is | 149 * type_is |
131 */ | 150 */ |
132 let opt = this.selectedOption; | 151 let opt = this.selectedOption; |
133 if (opt) { | 152 if (opt) { |
134 step = new QueryStep(this.selectedMode, {'objectType': opt}); | 153 step = new QueryStep(this.selectedMode, {'objectType': opt}); |
135 } | 154 } |
136 } else if (this.selectedMode.id == 'relation_is') { | 155 } else if (this.selectedMode.id === 'relation_is') { |
137 /* | 156 /* |
138 * relation_is | 157 * relation_is |
139 */ | 158 */ |
140 let opt = this.selectedOption; | 159 let opt = this.selectedOption; |
141 if (opt) { | 160 if (opt) { |
142 let rel = getRelationByName(opt); | 161 let rel = getRelationByName(opt); |
143 step = new QueryStep(this.selectedMode, {'relationType': rel}); | 162 step = new QueryStep(this.selectedMode, {'relationType': rel}); |
144 } | 163 } |
145 } else if (this.selectedMode.id == 'id_is') { | 164 } else if (this.selectedMode.id === 'id_is') { |
146 /* | 165 /* |
147 * id is | 166 * id is |
148 */ | 167 */ |
149 let val = this.queryInput; | 168 let val = this.queryInput; |
150 if (val) { | 169 if (val) { |
151 step = new QueryStep(this.selectedMode, {'value': val}); | 170 step = new QueryStep(this.selectedMode, {'value': val}); |
152 } | 171 } |
153 } else if (this.selectedMode.id == 'att_contains') { | 172 } else if (this.selectedMode.id === 'att_contains') { |
154 /* | 173 /* |
155 * att_contains | 174 * att_contains |
156 */ | 175 */ |
157 let att = this.selectedOption; | 176 let att = this.selectedOption; |
158 let val = this.queryInput; | 177 let val = this.queryInput; |
159 if (att && val) { | 178 if (att && val) { |
160 step = new QueryStep(this.selectedMode, {'attribute': att, 'value': val}); | 179 step = new QueryStep(this.selectedMode, {'attribute': att, 'value': val}); |
161 } | 180 } |
162 } else if (this.selectedMode.id == 'att_num_range') { | 181 } else if (this.selectedMode.id === 'att_num_range') { |
163 /* | 182 /* |
164 * att_num_range | 183 * att_num_range |
165 */ | 184 */ |
166 let att = this.selectedOption; | 185 let att = this.selectedOption; |
167 let nlo = this.queryInput; | 186 let nlo = this.queryInput; |
168 let nhi = this.queryInput2; | 187 let nhi = this.queryInput2; |
169 if (att && nlo && nhi) { | 188 if (att && nlo && nhi) { |
170 step = new QueryStep(this.selectedMode, {'attribute': att, 'numLo': nlo, 'numHi': nhi}); | 189 step = new QueryStep(this.selectedMode, {'attribute': att, 'numLo': nlo, 'numHi': nhi}); |
171 } | 190 } |
172 } else if (this.selectedMode.id == 'att_contains_norm') { | 191 } else if (this.selectedMode.id === 'att_contains_norm') { |
173 /* | 192 /* |
174 * att_contains_norm | 193 * att_contains_norm |
175 * | 194 * |
176 * calls normalization service and submits event in callback | 195 * calls normalization service and submits event in callback |
177 */ | 196 */ |
189 this.queryChanged.emit(this._queryService.getState()); | 208 this.queryChanged.emit(this._queryService.getState()); |
190 }, | 209 }, |
191 err => console.error("openmind norm error=", err), | 210 err => console.error("openmind norm error=", err), |
192 () => console.debug("openmind norm query Complete") | 211 () => console.debug("openmind norm query Complete") |
193 ); | 212 ); |
194 // query has not been set yet | 213 // query has not been set yet (gets set in callback) |
195 return; | 214 return null; |
196 } | 215 } |
197 } | 216 } |
198 | 217 return step; |
199 /* | 218 } |
200 * set step and submit change event | 219 |
220 /** | |
221 * Sets form state from given QueryStep. | |
222 */ | |
223 setQueryStep(step: QueryStep) { | |
224 let mode = step.mode; | |
225 this.selectedMode = mode; | |
226 if (mode.id === 'id_is') { | |
227 /* | |
228 * id_is | |
201 */ | 229 */ |
202 if (step != null) { | 230 this.queryInput = step.params.value; |
203 this._queryService.setQueryStep(this.index, step); | 231 |
204 this.queryChanged.emit(this._queryService.getState()); | 232 } else if (mode.id === 'type_is') { |
205 } | 233 /* |
234 * type_is | |
235 */ | |
236 let name = step.params.objectType; | |
237 this.queryOptions = [name]; | |
238 this.selectedOption = name; | |
239 | |
240 } else if (this.selectedMode.id === 'relation_is') { | |
241 /* | |
242 * relation_is | |
243 */ | |
244 let name = step.params.relationType.name | |
245 let rel = getRelationByName(name); | |
246 this.queryOptions = [rel]; | |
247 this.selectedOption = name; | |
248 | |
249 } else if (this.selectedMode.id === 'att_contains') { | |
250 /* | |
251 * att_contains | |
252 */ | |
253 let name = step.params.attribute | |
254 this.queryOptions = [name]; | |
255 this.selectedOption = name; | |
256 this.queryInput = step.params.value; | |
257 | |
258 } else if (this.selectedMode.id === 'att_num_range') { | |
259 /* | |
260 * att_num_range | |
261 */ | |
262 let name = step.params.attribute | |
263 this.queryOptions = [name]; | |
264 this.selectedOption = name; | |
265 this.queryInput = step.params.numLo; | |
266 this.queryInput2 = step.params.numHi; | |
267 | |
268 } else if (this.selectedMode.id === 'att_contains_norm') { | |
269 /* | |
270 * att_contains_norm | |
271 */ | |
272 let name = step.params.attribute | |
273 this.queryOptions = [name]; | |
274 this.selectedOption = name; | |
275 this.queryInput = step.params.value; | |
276 } | |
277 // TODO: implement other modes | |
278 this.resultInfo = step.resultInfo; | |
206 } | 279 } |
207 } | 280 } |