Mercurial > hg > ng2-query-ismi
diff 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 |
line wrap: on
line diff
--- a/src/app/query-select.component.ts Tue Mar 28 20:03:36 2017 +0200 +++ b/src/app/query-select.component.ts Wed Mar 29 17:16:10 2017 +0200 @@ -81,9 +81,9 @@ public queryStep: string; public index: number; public resultInfo: string; - public queryModes: QueryMode[]; + public queryModes: Array<QueryMode>; public selectedMode: QueryMode; - public queryOptions: string[]; + public queryOptions: any[]; public selectedOption: string; public queryInput: string; public queryInput2: string; @@ -101,11 +101,7 @@ console.log("query-select setup step=", this.queryStep); var step = this._queryService.state.steps[this.index]; // i-1? if (step != null) { - this.selectedMode = step.mode; - if (step.mode.id === 'id_is') { - this.queryInput = step.params.value; - } - this.resultInfo = step.resultInfo; + this.setQueryStep(step); } } @@ -129,8 +125,26 @@ onSubmit() { console.debug("Submit! selectedMode=", this.selectedMode, " selectedOption=", this.selectedOption, " queryInput=", this.queryInput); - var step: QueryStep; - if (this.selectedMode.id == 'type_is') { + + let step = this.getQueryStep(); + + /* + * set step and submit change event + */ + if (step != null) { + this._queryService.setQueryStep(this.index, step); + this.queryChanged.emit(this._queryService.getState()); + } + return false; + } + + /** + * Returns QueryStep from current form state. + */ + getQueryStep(): QueryStep { + let step: QueryStep = null; + + if (this.selectedMode.id === 'type_is') { /* * type_is */ @@ -138,7 +152,7 @@ if (opt) { step = new QueryStep(this.selectedMode, {'objectType': opt}); } - } else if (this.selectedMode.id == 'relation_is') { + } else if (this.selectedMode.id === 'relation_is') { /* * relation_is */ @@ -147,7 +161,7 @@ let rel = getRelationByName(opt); step = new QueryStep(this.selectedMode, {'relationType': rel}); } - } else if (this.selectedMode.id == 'id_is') { + } else if (this.selectedMode.id === 'id_is') { /* * id is */ @@ -155,7 +169,7 @@ if (val) { step = new QueryStep(this.selectedMode, {'value': val}); } - } else if (this.selectedMode.id == 'att_contains') { + } else if (this.selectedMode.id === 'att_contains') { /* * att_contains */ @@ -164,7 +178,7 @@ if (att && val) { step = new QueryStep(this.selectedMode, {'attribute': att, 'value': val}); } - } else if (this.selectedMode.id == 'att_num_range') { + } else if (this.selectedMode.id === 'att_num_range') { /* * att_num_range */ @@ -174,7 +188,7 @@ if (att && nlo && nhi) { step = new QueryStep(this.selectedMode, {'attribute': att, 'numLo': nlo, 'numHi': nhi}); } - } else if (this.selectedMode.id == 'att_contains_norm') { + } else if (this.selectedMode.id === 'att_contains_norm') { /* * att_contains_norm * @@ -196,17 +210,71 @@ err => console.error("openmind norm error=", err), () => console.debug("openmind norm query Complete") ); - // query has not been set yet - return; + // query has not been set yet (gets set in callback) + return null; } } - - /* - * set step and submit change event + return step; + } + + /** + * Sets form state from given QueryStep. + */ + setQueryStep(step: QueryStep) { + let mode = step.mode; + this.selectedMode = mode; + if (mode.id === 'id_is') { + /* + * id_is */ - if (step != null) { - this._queryService.setQueryStep(this.index, step); - this.queryChanged.emit(this._queryService.getState()); + this.queryInput = step.params.value; + + } else if (mode.id === 'type_is') { + /* + * type_is + */ + let name = step.params.objectType; + this.queryOptions = [name]; + this.selectedOption = name; + + } else if (this.selectedMode.id === 'relation_is') { + /* + * relation_is + */ + let name = step.params.relationType.name + let rel = getRelationByName(name); + this.queryOptions = [rel]; + this.selectedOption = name; + + } else if (this.selectedMode.id === 'att_contains') { + /* + * att_contains + */ + let name = step.params.attribute + this.queryOptions = [name]; + this.selectedOption = name; + this.queryInput = step.params.value; + + } else if (this.selectedMode.id === 'att_num_range') { + /* + * att_num_range + */ + let name = step.params.attribute + this.queryOptions = [name]; + this.selectedOption = name; + this.queryInput = step.params.numLo; + this.queryInput2 = step.params.numHi; + + } else if (this.selectedMode.id === 'att_contains_norm') { + /* + * att_contains_norm + */ + let name = step.params.attribute + this.queryOptions = [name]; + this.selectedOption = name; + this.queryInput = step.params.value; } + // TODO: implement other modes + this.resultInfo = step.resultInfo; } }