comparison src/app/query-select.component.ts @ 57:d7c947909ab8 ng2-table

renamed query-app.module to app.module. loading query from url fragment works now.
author casties
date Wed, 29 Mar 2017 17:16:10 +0200
parents b22e52a128a8
children 6adf95d9a190
comparison
equal deleted inserted replaced
56:b22e52a128a8 57:d7c947909ab8
79 79
80 export class QuerySelectComponent implements OnInit { 80 export class QuerySelectComponent implements OnInit {
81 public queryStep: string; 81 public queryStep: string;
82 public index: number; 82 public index: number;
83 public resultInfo: string; 83 public resultInfo: string;
84 public queryModes: QueryMode[]; 84 public queryModes: Array<QueryMode>;
85 public selectedMode: QueryMode; 85 public selectedMode: QueryMode;
86 public queryOptions: string[]; 86 public queryOptions: any[];
87 public selectedOption: string; 87 public selectedOption: string;
88 public queryInput: string; 88 public queryInput: string;
89 public queryInput2: string; 89 public queryInput2: string;
90 90
91 // output queryChanged 91 // output queryChanged
99 99
100 setup() { 100 setup() {
101 console.log("query-select setup step=", this.queryStep); 101 console.log("query-select setup step=", this.queryStep);
102 var step = this._queryService.state.steps[this.index]; // i-1? 102 var step = this._queryService.state.steps[this.index]; // i-1?
103 if (step != null) { 103 if (step != null) {
104 this.selectedMode = step.mode; 104 this.setQueryStep(step);
105 if (step.mode.id === 'id_is') {
106 this.queryInput = step.params.value;
107 }
108 this.resultInfo = step.resultInfo;
109 } 105 }
110 } 106 }
111 107
112 getQueryModes(): QueryMode[] { 108 getQueryModes(): QueryMode[] {
113 this.queryModes = this._queryService.getQueryModes(this.index); 109 this.queryModes = this._queryService.getQueryModes(this.index);
127 this.onSubmit(); 123 this.onSubmit();
128 } 124 }
129 125
130 onSubmit() { 126 onSubmit() {
131 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);
132 var step: QueryStep; 128
133 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') {
134 /* 148 /*
135 * type_is 149 * type_is
136 */ 150 */
137 let opt = this.selectedOption; 151 let opt = this.selectedOption;
138 if (opt) { 152 if (opt) {
139 step = new QueryStep(this.selectedMode, {'objectType': opt}); 153 step = new QueryStep(this.selectedMode, {'objectType': opt});
140 } 154 }
141 } else if (this.selectedMode.id == 'relation_is') { 155 } else if (this.selectedMode.id === 'relation_is') {
142 /* 156 /*
143 * relation_is 157 * relation_is
144 */ 158 */
145 let opt = this.selectedOption; 159 let opt = this.selectedOption;
146 if (opt) { 160 if (opt) {
147 let rel = getRelationByName(opt); 161 let rel = getRelationByName(opt);
148 step = new QueryStep(this.selectedMode, {'relationType': rel}); 162 step = new QueryStep(this.selectedMode, {'relationType': rel});
149 } 163 }
150 } else if (this.selectedMode.id == 'id_is') { 164 } else if (this.selectedMode.id === 'id_is') {
151 /* 165 /*
152 * id is 166 * id is
153 */ 167 */
154 let val = this.queryInput; 168 let val = this.queryInput;
155 if (val) { 169 if (val) {
156 step = new QueryStep(this.selectedMode, {'value': val}); 170 step = new QueryStep(this.selectedMode, {'value': val});
157 } 171 }
158 } else if (this.selectedMode.id == 'att_contains') { 172 } else if (this.selectedMode.id === 'att_contains') {
159 /* 173 /*
160 * att_contains 174 * att_contains
161 */ 175 */
162 let att = this.selectedOption; 176 let att = this.selectedOption;
163 let val = this.queryInput; 177 let val = this.queryInput;
164 if (att && val) { 178 if (att && val) {
165 step = new QueryStep(this.selectedMode, {'attribute': att, 'value': val}); 179 step = new QueryStep(this.selectedMode, {'attribute': att, 'value': val});
166 } 180 }
167 } else if (this.selectedMode.id == 'att_num_range') { 181 } else if (this.selectedMode.id === 'att_num_range') {
168 /* 182 /*
169 * att_num_range 183 * att_num_range
170 */ 184 */
171 let att = this.selectedOption; 185 let att = this.selectedOption;
172 let nlo = this.queryInput; 186 let nlo = this.queryInput;
173 let nhi = this.queryInput2; 187 let nhi = this.queryInput2;
174 if (att && nlo && nhi) { 188 if (att && nlo && nhi) {
175 step = new QueryStep(this.selectedMode, {'attribute': att, 'numLo': nlo, 'numHi': nhi}); 189 step = new QueryStep(this.selectedMode, {'attribute': att, 'numLo': nlo, 'numHi': nhi});
176 } 190 }
177 } else if (this.selectedMode.id == 'att_contains_norm') { 191 } else if (this.selectedMode.id === 'att_contains_norm') {
178 /* 192 /*
179 * att_contains_norm 193 * att_contains_norm
180 * 194 *
181 * calls normalization service and submits event in callback 195 * calls normalization service and submits event in callback
182 */ 196 */
194 this.queryChanged.emit(this._queryService.getState()); 208 this.queryChanged.emit(this._queryService.getState());
195 }, 209 },
196 err => console.error("openmind norm error=", err), 210 err => console.error("openmind norm error=", err),
197 () => console.debug("openmind norm query Complete") 211 () => console.debug("openmind norm query Complete")
198 ); 212 );
199 // query has not been set yet 213 // query has not been set yet (gets set in callback)
200 return; 214 return null;
201 } 215 }
202 } 216 }
203 217 return step;
204 /* 218 }
205 * 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
206 */ 229 */
207 if (step != null) { 230 this.queryInput = step.params.value;
208 this._queryService.setQueryStep(this.index, step); 231
209 this.queryChanged.emit(this._queryService.getState()); 232 } else if (mode.id === 'type_is') {
210 } 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;
211 } 279 }
212 } 280 }