Mercurial > hg > ng2-query-ismi
annotate app/query.service.ts @ 2:80270f5a5735
more tinkering.
author | casties |
---|---|
date | Wed, 13 Jan 2016 11:13:07 +0100 |
parents | 59b7c3afcc6b |
children | c741a00d38de |
rev | line source |
---|---|
1
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
1 import {Injectable} from 'angular2/core'; |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
2 import {Http, Headers} from 'angular2/http'; |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
3 |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
4 import 'rxjs/Rx'; // import all RxJS operators |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
5 |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
6 import {QueryMode} from './query-mode'; |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
7 |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
8 @Injectable() |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
9 export class QueryService { |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
10 |
2 | 11 public ismiObjectTypes; |
12 | |
1
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
13 public QUERY_MODES: QueryMode[] = [ |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
14 {id: 'type_is', label:'Object type is'}, |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
15 {id: 'att_contains', label: 'Attribute contains'}]; |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
16 |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
17 constructor(private _http: Http) {} |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
18 |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
19 getQueryModes(): QueryMode[] { |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
20 return this.QUERY_MODES; |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
21 } |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
22 |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
23 getQueryOptions(queryMode: string) { |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
24 var options = ['a1', 'b1', 'c1']; |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
25 if (queryMode == 'Attribute contains') { |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
26 options = ['d', 'e', 'f']; |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
27 } |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
28 return Promise.resolve(options); |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
29 } |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
30 |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
31 getIsmiObjectTypes() { |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
32 var headers = new Headers(); |
2 | 33 headers.append('Authorization', 'Basic ' + btoa('neo4j' + ':' + 'neo5j')); |
1
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
34 headers.append('Content-Type', 'application/json'); |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
35 headers.append('Accept', 'application/json'); |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
36 var data = { |
2 | 37 'query': `MATCH (n) |
1
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
38 WITH DISTINCT labels(n) AS labels |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
39 UNWIND labels AS label |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
40 RETURN DISTINCT label |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
41 ORDER BY label`, |
2 | 42 'params': {} |
43 }; | |
44 | |
45 this._http.post('http://localhost:7474/db/data/cypher/', JSON.stringify(data), {'headers': headers}) | |
46 .map(res => res.json()) | |
47 .subscribe( | |
48 data => { | |
49 console.debug("neo4j data=", data); | |
50 this.ismiObjectTypes = data.data.map(elem => elem[0]).filter(elem => elem[0] != "_"); | |
51 }, | |
52 err => console.error("neo4j error=", err), | |
53 () => console.debug('neo4j query Complete') | |
54 ); | |
1
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
55 } |
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
diff
changeset
|
56 } |