Mercurial > hg > ng2-query-ismi
view app/query.service.ts @ 2:80270f5a5735
more tinkering.
author | casties |
---|---|
date | Wed, 13 Jan 2016 11:13:07 +0100 |
parents | 59b7c3afcc6b |
children | c741a00d38de |
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 ismiObjectTypes; 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': {} }; this._http.post('http://localhost:7474/db/data/cypher/', JSON.stringify(data), {'headers': headers}) .map(res => res.json()) .subscribe( data => { console.debug("neo4j data=", data); this.ismiObjectTypes = data.data.map(elem => elem[0]).filter(elem => elem[0] != "_"); }, err => console.error("neo4j error=", err), () => console.debug('neo4j query Complete') ); } }