# HG changeset patch # User casties # Date 1453285951 -3600 # Node ID 402c7229dc7c82eb28e162e19ef88e20c4cc0643 # Parent fa646ee46c19fdd86b548f0c5516aa777ccb7019 more query generation. diff -r fa646ee46c19 -r 402c7229dc7c app/query-result-row.component.ts --- a/app/query-result-row.component.ts Mon Jan 18 09:52:46 2016 +0100 +++ b/app/query-result-row.component.ts Wed Jan 20 11:32:31 2016 +0100 @@ -3,8 +3,9 @@ @Component({ selector: 'query-result-row', template: ` - {{rowData.data.label}} - {{rowData}} + {{rowData.type}} + {{rowData.label}} + {{rowData}} `, inputs: ['rowData', 'rowType'] }) diff -r fa646ee46c19 -r 402c7229dc7c app/query-result.component.ts --- a/app/query-result.component.ts Mon Jan 18 09:52:46 2016 +0100 +++ b/app/query-result.component.ts Wed Jan 20 11:32:31 2016 +0100 @@ -10,11 +10,15 @@

Cypher: {{queryState.cypherQuery}}

Query results ({{queryState.numResults}}):

-
`, directives: [QueryResultRowComponent], diff -r fa646ee46c19 -r 402c7229dc7c app/query.service.ts --- a/app/query.service.ts Mon Jan 18 09:52:46 2016 +0100 +++ b/app/query.service.ts Wed Jan 20 11:32:31 2016 +0100 @@ -10,7 +10,7 @@ @Injectable() export class QueryService { - public neo4jBaseUrl = 'http://localhost:7474/db/data/cypher/'; + public neo4jBaseUrl = 'http://localhost:7474/db/data'; public state: QueryState; public ismiObjectTypes: any; @@ -44,6 +44,18 @@ getQueryOptions(queryMode: QueryMode) { var options = ['a1', 'b1', 'c1']; if (queryMode.id === 'att_contains') { + if (this.state.attributeCypherQuery) { + var res = this.fetchCypherResult(this.state.attributeCypherQuery); + res.subscribe( + data => { + console.debug("neo4j data=", data); + var atts = data.results[0].data.map(elem => elem.row[0]).filter(elem => elem[0] != "_"); + console.debug("ismi attributes=", atts); + }, + err => console.error("neo4j error=", err), + () => console.debug('neo4j query Complete') + ); + } options = ['d', 'e', 'f']; } else if (queryMode.id === 'type_is') { options = this.ismiObjectTypes; @@ -61,7 +73,7 @@ res.subscribe( data => { console.debug("neo4j data=", data); - this.ismiObjectTypes = data.data.map(elem => elem[0]).filter(elem => elem[0] != "_"); + this.ismiObjectTypes = data.results[0].data.map(elem => elem.row[0]).filter(elem => elem[0] != "_"); console.debug("ismi types=", this.ismiObjectTypes); }, err => console.error("neo4j error=", err), @@ -75,28 +87,32 @@ } createCypherQuery() { - var cypher = ''; + var resultCypher = ''; + var attCypher = ''; var returnType = ''; - for (var i=0; i < this.state.steps.length; ++i) { - var step = this.state.steps[i]; + this.state.steps.forEach((step) => { if (step.mode.id === 'type_is') { - cypher = `MATCH (e:${step.objectType}) return e`; + resultCypher = `MATCH (e:${step.objectType}) return e`; returnType = 'node'; + attCypher = `MATCH (e:${step.objectType}) WITH DISTINCT keys(e) AS atts + UNWIND atts AS att + RETURN DISTINCT att ORDER BY att`; } - } - this.state.cypherQuery = cypher; + }); + this.state.resultCypherQuery = resultCypher; + this.state.attributeCypherQuery = attCypher; this.state.resultTypes = returnType; } updateQuery() { this.createCypherQuery(); - var query = this.state.cypherQuery; + var query = this.state.resultCypherQuery; 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.results = data.results[0].data.map(elem => elem.row[0]); this.state.numResults = this.state.results.length; }, err => console.error("neo4j error=", err), @@ -112,9 +128,11 @@ // put headers in options var opts = {'headers': headers}; // create POST data from query - var data = JSON.stringify({'query': query, 'params': params}); + var data = JSON.stringify({'statements': [ + {'statement': query, 'parameters': params} + ]}); // make post request asynchronously - var resp = this._http.post(this.neo4jBaseUrl, data, opts) + var resp = this._http.post(this.neo4jBaseUrl+'/transaction/commit', data, opts) // filter result as JSON .map(res => res.json()); // return Observable