# HG changeset patch # User Robert Casties # Date 1452536753 -3600 # Node ID 59b7c3afcc6bbd806f0e4145f38be28ee0d47494 # Parent 39ec75917ef71451be84ce61f4b673beba923a78 first interface and http request. diff -r 39ec75917ef7 -r 59b7c3afcc6b app/app.component.ts --- a/app/app.component.ts Thu Jan 07 15:04:15 2016 +0100 +++ b/app/app.component.ts Mon Jan 11 19:25:53 2016 +0100 @@ -11,7 +11,9 @@ `, directives: [QuerySelectComponent] }) + export class AppComponent { public title = 'huhu!'; - public selectedOption = 'unknown'; + public selectedOption = 'unknown'; + } diff -r 39ec75917ef7 -r 59b7c3afcc6b app/query-mode.ts --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/query-mode.ts Mon Jan 11 19:25:53 2016 +0100 @@ -0,0 +1,4 @@ +export interface QueryMode { + id: string; + label: string; +} \ No newline at end of file diff -r 39ec75917ef7 -r 59b7c3afcc6b app/query-select.component.ts --- a/app/query-select.component.ts Thu Jan 07 15:04:15 2016 +0100 +++ b/app/query-select.component.ts Mon Jan 11 19:25:53 2016 +0100 @@ -1,31 +1,47 @@ -import {Component} from 'angular2/core'; +import {Component, OnInit} from 'angular2/core'; +import {HTTP_PROVIDERS} from 'angular2/http'; + +import {QueryService} from './query.service'; +import {QueryMode} from './query-mode'; + @Component({ selector: 'query-select', template: `

Selected option: {{selectedQuery}}

- ` + `, + providers: [QueryService, HTTP_PROVIDERS] }) -export class QuerySelectComponent { - public queryTypes = ['Object type is', 'Attribute contains']; + +export class QuerySelectComponent implements OnInit { + public queryModes; public selectedQuery = 'unknown'; - public query2Types = ['a', 'b', 'c']; + public query2Options; + + constructor(private _queryService: QueryService) {} + + ngOnInit() { + this.setupQueryModes(); + } + + setupQueryModes() { + this.queryModes = this._queryService.getQueryModes(); + this._queryService.getIsmiObjectTypes(); + } onSelectType(event: any) { - var selected = event.target.value - this.selectedQuery = selected; - if (selected == 'Attribute contains') { - this.query2Types = ['d', 'e', 'f']; - } + var selected = event.target.value; + this._queryService.getQueryOptions(selected).then( + options => this.query2Options = options); } } diff -r 39ec75917ef7 -r 59b7c3afcc6b app/query.service.ts --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/query.service.ts Mon Jan 11 19:25:53 2016 +0100 @@ -0,0 +1,55 @@ +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') + ); + } +} \ No newline at end of file diff -r 39ec75917ef7 -r 59b7c3afcc6b index.html --- a/index.html Thu Jan 07 15:04:15 2016 +0100 +++ b/index.html Mon Jan 11 19:25:53 2016 +0100 @@ -8,6 +8,7 @@ +