Mercurial > hg > ng2-query-ismi
comparison 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 |
comparison
equal
deleted
inserted
replaced
6:9f5473536a98 | 7:6cd6c09032aa |
---|---|
8 import {QueryStep} from './query-step'; | 8 import {QueryStep} from './query-step'; |
9 | 9 |
10 @Injectable() | 10 @Injectable() |
11 export class QueryService { | 11 export class QueryService { |
12 | 12 |
13 public queryState: QueryState; | 13 public state: QueryState; |
14 | 14 |
15 public ismiObjectTypes; | 15 public ismiObjectTypes; |
16 | 16 |
17 public QUERY_MODES: QueryMode[] = [ | 17 public QUERY_MODES: QueryMode[] = [ |
18 {id: 'type_is', label:'Object type is'}, | 18 {id: 'type_is', label:'Object type is'}, |
19 {id: 'att_contains', label: 'Attribute contains'}]; | 19 {id: 'att_contains', label: 'Attribute contains'}]; |
20 | 20 |
21 constructor(private _http: Http) { | 21 constructor(private _http: Http) { |
22 this.queryState = { | 22 this.state = { |
23 'steps': [], | 23 'steps': [], |
24 'cypherQuery': '', | 24 'cypherQuery': '', |
25 'cyperParams': {}, | 25 'cypherParams': {}, |
26 'results': [], | 26 'results': [], |
27 numResults: 0}; | 27 'resultTypes': '', |
28 'numResults': 0 | |
29 }; | |
30 } | |
31 | |
32 getState() { | |
33 return this.state; | |
28 } | 34 } |
29 | 35 |
30 getQueryModes(): QueryMode[] { | 36 getQueryModes(): QueryMode[] { |
31 return this.QUERY_MODES; | 37 return this.QUERY_MODES; |
32 } | 38 } |
58 () => console.debug('neo4j query Complete') | 64 () => console.debug('neo4j query Complete') |
59 ); | 65 ); |
60 } | 66 } |
61 | 67 |
62 setQueryStep(index: number, step: QueryStep) { | 68 setQueryStep(index: number, step: QueryStep) { |
63 this.queryState.steps[index] = step; | 69 this.state.steps[index] = step; |
64 this.createCypherQuery(); | 70 this.createCypherQuery(); |
65 } | 71 } |
66 | 72 |
67 createCypherQuery() { | 73 createCypherQuery() { |
68 var cypher = ''; | 74 var cypher = ''; |
69 var step = this.queryState.steps[0]; | 75 var returnType = ''; |
76 var step = this.state.steps[0]; | |
70 if (step.mode.id === 'type_is') { | 77 if (step.mode.id === 'type_is') { |
71 cypher = `MATCH (e:${step.objectType}) return e`; | 78 cypher = `MATCH (e:${step.objectType}) return e`; |
79 returnType = 'node'; | |
72 } | 80 } |
73 | 81 |
74 this.queryState.cypherQuery = cypher; | 82 this.state.cypherQuery = cypher; |
83 this.state.resultTypes = returnType; | |
84 } | |
85 | |
86 updateQuery() { | |
87 this.createCypherQuery(); | |
88 var query = this.state.cypherQuery; | |
89 var params = this.state.cypherParams; | |
90 var res = this.fetchCypherResult(query, params); | |
91 res.subscribe( | |
92 data => { | |
93 console.debug("neo4j data=", data); | |
94 this.state.results = data.data.map(elem => elem[0]); | |
95 this.state.numResults = this.state.results.length; | |
96 }, | |
97 err => console.error("neo4j error=", err), | |
98 () => console.debug('neo4j query Complete') | |
99 ); | |
75 } | 100 } |
76 | 101 |
77 fetchCypherResult(query: string, params = {}) { | 102 fetchCypherResult(query: string, params = {}) { |
78 var headers = new Headers(); | 103 var headers = new Headers(); |
79 headers.append('Authorization', 'Basic ' + btoa('neo4j' + ':' + 'neo5j')); | 104 headers.append('Authorization', 'Basic ' + btoa('neo4j' + ':' + 'neo5j')); |