Mercurial > hg > ng2-query-ismi
diff app/query.service.ts @ 7:6cd6c09032aa
object type query with results!
author | Robert Casties <casties@mpiwg-berlin.mpg.de> |
---|---|
date | Fri, 15 Jan 2016 20:00:47 +0100 |
parents | 9f5473536a98 |
children | fa646ee46c19 |
line wrap: on
line diff
--- a/app/query.service.ts Thu Jan 14 17:19:35 2016 +0100 +++ b/app/query.service.ts Fri Jan 15 20:00:47 2016 +0100 @@ -10,7 +10,7 @@ @Injectable() export class QueryService { - public queryState: QueryState; + public state: QueryState; public ismiObjectTypes; @@ -19,12 +19,18 @@ {id: 'att_contains', label: 'Attribute contains'}]; constructor(private _http: Http) { - this.queryState = { + this.state = { 'steps': [], 'cypherQuery': '', - 'cyperParams': {}, - 'results': [], - numResults: 0}; + 'cypherParams': {}, + 'results': [], + 'resultTypes': '', + 'numResults': 0 + }; + } + + getState() { + return this.state; } getQueryModes(): QueryMode[] { @@ -60,18 +66,37 @@ } setQueryStep(index: number, step: QueryStep) { - this.queryState.steps[index] = step; + this.state.steps[index] = step; this.createCypherQuery(); } createCypherQuery() { var cypher = ''; - var step = this.queryState.steps[0]; + var returnType = ''; + var step = this.state.steps[0]; if (step.mode.id === 'type_is') { cypher = `MATCH (e:${step.objectType}) return e`; + returnType = 'node'; } - this.queryState.cypherQuery = cypher; + this.state.cypherQuery = cypher; + this.state.resultTypes = returnType; + } + + updateQuery() { + this.createCypherQuery(); + var query = this.state.cypherQuery; + var params = this.state.cypherParams; + var res = this.fetchCypherResult(query, params); + res.subscribe( + data => { + console.debug("neo4j data=", data); + this.state.results = data.data.map(elem => elem[0]); + this.state.numResults = this.state.results.length; + }, + err => console.error("neo4j error=", err), + () => console.debug('neo4j query Complete') + ); } fetchCypherResult(query: string, params = {}) {