comparison app/query.service.ts @ 2:80270f5a5735

more tinkering.
author casties
date Wed, 13 Jan 2016 11:13:07 +0100
parents 59b7c3afcc6b
children c741a00d38de
comparison
equal deleted inserted replaced
1:59b7c3afcc6b 2:80270f5a5735
6 import {QueryMode} from './query-mode'; 6 import {QueryMode} from './query-mode';
7 7
8 @Injectable() 8 @Injectable()
9 export class QueryService { 9 export class QueryService {
10 10
11 public ismiObjectTypes;
12
11 public QUERY_MODES: QueryMode[] = [ 13 public QUERY_MODES: QueryMode[] = [
12 {id: 'type_is', label:'Object type is'}, 14 {id: 'type_is', label:'Object type is'},
13 {id: 'att_contains', label: 'Attribute contains'}]; 15 {id: 'att_contains', label: 'Attribute contains'}];
14 16
15 constructor(private _http: Http) {} 17 constructor(private _http: Http) {}
26 return Promise.resolve(options); 28 return Promise.resolve(options);
27 } 29 }
28 30
29 getIsmiObjectTypes() { 31 getIsmiObjectTypes() {
30 var headers = new Headers(); 32 var headers = new Headers();
31 headers.append('Authorization', 'Basic ' + btoa('neo4j'+':'+'neo5j')); 33 headers.append('Authorization', 'Basic ' + btoa('neo4j' + ':' + 'neo5j'));
32 headers.append('Content-Type', 'application/json'); 34 headers.append('Content-Type', 'application/json');
33 headers.append('Accept', 'application/json'); 35 headers.append('Accept', 'application/json');
34 var data = { 36 var data = {
35 'query': `MATCH (n) 37 'query': `MATCH (n)
36 WITH DISTINCT labels(n) AS labels 38 WITH DISTINCT labels(n) AS labels
37 UNWIND labels AS label 39 UNWIND labels AS label
38 RETURN DISTINCT label 40 RETURN DISTINCT label
39 ORDER BY label`, 41 ORDER BY label`,
40 'params': {} 42 'params': {}
41 }; 43 };
42 44
43 console.debug("http:", this._http, " headers:", headers, " data:", data); 45 this._http.post('http://localhost:7474/db/data/cypher/', JSON.stringify(data), {'headers': headers})
44 46 .map(res => res.json())
45 var post = this._http.post('http://localhost:7474/db/data/cypher/', JSON.stringify(data), {'headers': headers}); 47 .subscribe(
46 console.debug("post:", post); 48 data => {
47 var map = post.map(res => res.json()); 49 console.debug("neo4j data=", data);
48 console.debug("map:", map); 50 this.ismiObjectTypes = data.data.map(elem => elem[0]).filter(elem => elem[0] != "_");
49 map.subscribe( 51 },
50 data => console.debug("neo4j data=", data), 52 err => console.error("neo4j error=", err),
51 err => console.error("neo4j error=", err), 53 () => console.debug('neo4j query Complete')
52 () => console.debug('neo4j query Complete') 54 );
53 );
54 } 55 }
55 } 56 }