Mercurial > hg > ng2-query-ismi
comparison app/query.service.ts @ 36:e8dc6a4c6773
only show possible incoming/outgoing relation types.
author | casties |
---|---|
date | Thu, 11 Feb 2016 17:06:40 +0100 |
parents | b47614a9d23d |
children | 7578b21cdf2e |
comparison
equal
deleted
inserted
replaced
35:b47614a9d23d | 36:e8dc6a4c6773 |
---|---|
101 var queryWhere = ''; | 101 var queryWhere = ''; |
102 var queryReturn = ''; | 102 var queryReturn = ''; |
103 var queryParams = {}; | 103 var queryParams = {}; |
104 var resultQuery = ''; | 104 var resultQuery = ''; |
105 var attributesQuery = ''; | 105 var attributesQuery = ''; |
106 var relationsQuery = ''; | 106 var outRelsQuery = ''; |
107 var inRelsQuery = ''; | |
107 var returnType = ''; | 108 var returnType = ''; |
108 var nIdx = 1; | 109 var nIdx = 1; |
109 this.state.steps.forEach((step, stepIdx) => { | 110 this.state.steps.forEach((step, stepIdx) => { |
110 var mode = step.mode.id; | 111 var mode = step.mode.id; |
111 var params = step.params; | 112 var params = step.params; |
205 resultQuery = queryMatch + (queryWhere ? '\n'+queryWhere : '') + '\n' + queryReturn; | 206 resultQuery = queryMatch + (queryWhere ? '\n'+queryWhere : '') + '\n' + queryReturn; |
206 // compose query for attributes of result | 207 // compose query for attributes of result |
207 attributesQuery = queryMatch + ' ' + queryWhere + ` WITH DISTINCT keys(n${nIdx}) AS atts` | 208 attributesQuery = queryMatch + ' ' + queryWhere + ` WITH DISTINCT keys(n${nIdx}) AS atts` |
208 + ` UNWIND atts AS att RETURN DISTINCT att ORDER BY att`; | 209 + ` UNWIND atts AS att RETURN DISTINCT att ORDER BY att`; |
209 // compose query for relations of result | 210 // compose query for relations of result |
210 relationsQuery = queryMatch + '-[r]-() ' + queryWhere + ' RETURN DISTINCT type(r)'; | 211 outRelsQuery = queryMatch + '-[r]->() ' + queryWhere + ' RETURN DISTINCT type(r)'; |
212 inRelsQuery = queryMatch + '<-[r]-() ' + queryWhere + ' RETURN DISTINCT type(r)'; | |
211 this.state.resultCypherQuery = resultQuery; | 213 this.state.resultCypherQuery = resultQuery; |
212 this.state.cypherQueryParams = queryParams; | 214 this.state.cypherQueryParams = queryParams; |
213 this.state.attributesCypherQuery = attributesQuery; | 215 this.state.attributesCypherQuery = attributesQuery; |
214 this.state.relationsCypherQuery = relationsQuery; | 216 this.state.outRelsCypherQuery = outRelsQuery; |
217 this.state.inRelsCypherQuery = inRelsQuery; | |
215 this.state.resultTypes = returnType; | 218 this.state.resultTypes = returnType; |
216 } | 219 } |
217 | 220 |
218 /** | 221 /** |
219 * Create and run the cypher queries for the current query state. | 222 * Create and run the cypher queries for the current query state. |
230 var params = [this.state.cypherQueryParams]; | 233 var params = [this.state.cypherQueryParams]; |
231 if (this.state.attributesCypherQuery) { | 234 if (this.state.attributesCypherQuery) { |
232 queries.push(this.state.attributesCypherQuery); | 235 queries.push(this.state.attributesCypherQuery); |
233 params.push(this.state.cypherQueryParams); | 236 params.push(this.state.cypherQueryParams); |
234 } | 237 } |
235 if (this.state.relationsCypherQuery) { | 238 if (this.state.outRelsCypherQuery) { |
236 queries.push(this.state.relationsCypherQuery); | 239 queries.push(this.state.outRelsCypherQuery); |
240 params.push(this.state.cypherQueryParams); | |
241 } | |
242 if (this.state.inRelsCypherQuery) { | |
243 queries.push(this.state.inRelsCypherQuery); | |
237 params.push(this.state.cypherQueryParams); | 244 params.push(this.state.cypherQueryParams); |
238 } | 245 } |
239 var res = this.fetchCypherResults(queries, params); | 246 var res = this.fetchCypherResults(queries, params); |
240 res.subscribe( | 247 res.subscribe( |
241 data => { | 248 data => { |
279 this.state.resultColumns = this.state.resultType.getColumns(atts); | 286 this.state.resultColumns = this.state.resultType.getColumns(atts); |
280 } | 287 } |
281 /* | 288 /* |
282 * results for relations list | 289 * results for relations list |
283 */ | 290 */ |
284 if (this.state.relationsCypherQuery) { | 291 if (this.state.outRelsCypherQuery) { |
292 // outgoing aka forward relations | |
285 resIdx += 1; | 293 resIdx += 1; |
286 var rels = data.results[resIdx].data.map(elem => elem.row[0]) | 294 let rels = data.results[resIdx].data.map(elem => elem.row[0]) |
287 .filter(elem => elem[0] != "_"); | 295 .filter(elem => elem[0] != "_"); |
288 // add inverse relations | 296 this.state.resultRelations = rels; |
289 var invrels = rels.concat(rels.map((r) => this.invRelPrefix + r)); | 297 } |
290 this.state.resultRelations = invrels; | 298 if (this.state.inRelsCypherQuery) { |
299 // incoming aka reverse relations | |
300 resIdx += 1; | |
301 let rels = data.results[resIdx].data.map(elem => elem.row[0]) | |
302 .filter(elem => elem[0] != "_") | |
303 .map((r) => this.invRelPrefix + r); | |
304 this.state.resultRelations = this.state.resultRelations.concat(rels); | |
291 } | 305 } |
292 }, | 306 }, |
293 err => console.error("neo4j result error=", err), | 307 err => console.error("neo4j result error=", err), |
294 () => console.debug('neo4j result query Complete') | 308 () => console.debug('neo4j result query Complete') |
295 ); | 309 ); |