comparison app/query.service.ts @ 1:59b7c3afcc6b

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