Mercurial > hg > ng2-query-ismi
view 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 |
line wrap: on
line source
import {Injectable} from 'angular2/core'; import {Http, Headers} from 'angular2/http'; import 'rxjs/Rx'; // import all RxJS operators import {QueryMode} from './query-mode'; @Injectable() export class QueryService { public QUERY_MODES: QueryMode[] = [ {id: 'type_is', label:'Object type is'}, {id: 'att_contains', label: 'Attribute contains'}]; constructor(private _http: Http) {} getQueryModes(): QueryMode[] { return this.QUERY_MODES; } getQueryOptions(queryMode: string) { var options = ['a1', 'b1', 'c1']; if (queryMode == 'Attribute contains') { options = ['d', 'e', 'f']; } return Promise.resolve(options); } getIsmiObjectTypes() { var headers = new Headers(); headers.append('Authorization', 'Basic ' + btoa('neo4j'+':'+'neo5j')); headers.append('Content-Type', 'application/json'); headers.append('Accept', 'application/json'); var data = { 'query': `MATCH (n) WITH DISTINCT labels(n) AS labels UNWIND labels AS label RETURN DISTINCT label ORDER BY label`, 'params': {} }; console.debug("http:", this._http, " headers:", headers, " data:", data); var post = this._http.post('http://localhost:7474/db/data/cypher/', JSON.stringify(data), {'headers': headers}); console.debug("post:", post); var map = post.map(res => res.json()); console.debug("map:", map); map.subscribe( data => console.debug("neo4j data=", data), err => console.error("neo4j error=", err), () => console.debug('neo4j query Complete') ); } }