changeset 6:9f5473536a98

more query generation.
author casties
date Thu, 14 Jan 2016 17:19:35 +0100
parents b06a5d61afed
children 6cd6c09032aa
files app/app.component.ts app/query-select.component.ts app/query-state.ts app/query-step.ts app/query.service.ts query-step.ts
diffstat 6 files changed, 30 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/app/app.component.ts	Wed Jan 13 18:57:31 2016 +0100
+++ b/app/app.component.ts	Thu Jan 14 17:19:35 2016 +0100
@@ -10,7 +10,7 @@
     template: `
         <h1>My Angular 2 Text: {{title}}</h1>
         <p>Selected option: {{selectedOption}}</p>
-        <query-select [selectedOption]="selectedOption"></query-select>
+        <query-select></query-select>
         <query-result></query-result>
         `,
     directives: [QuerySelectComponent, QueryResultComponent],
--- a/app/query-select.component.ts	Wed Jan 13 18:57:31 2016 +0100
+++ b/app/query-select.component.ts	Thu Jan 14 17:19:35 2016 +0100
@@ -53,6 +53,6 @@
         this.selectedQuery = selected;
         console.debug("selected option:", selected);
         var query = {'mode': this.selectedMode, 'objectType': selected};
-        this._queryService.queryState.queries.push(query);    
+        this._queryService.setQueryStep(0, query);    
     }
 }
--- a/app/query-state.ts	Wed Jan 13 18:57:31 2016 +0100
+++ b/app/query-state.ts	Thu Jan 14 17:19:35 2016 +0100
@@ -1,5 +1,7 @@
 export interface QueryState {
-    queries: QueryStep[];
+    steps: QueryStep[];
+    cypherQuery: string;
+    cypherParams: any;
     results: any[];
     numResults: number;
 }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/query-step.ts	Thu Jan 14 17:19:35 2016 +0100
@@ -0,0 +1,4 @@
+export interface QueryStep {
+    mode: string;
+    objectType?: string;
+}
\ No newline at end of file
--- a/app/query.service.ts	Wed Jan 13 18:57:31 2016 +0100
+++ b/app/query.service.ts	Thu Jan 14 17:19:35 2016 +0100
@@ -19,7 +19,12 @@
         {id: 'att_contains', label: 'Attribute contains'}];
         
     constructor(private _http: Http) {
-        this.queryState = {'queries': [], 'results': [], numResults: 0};
+        this.queryState = {
+            'steps': [],
+            'cypherQuery': '',
+            'cyperParams': {}, 
+            'results': [], 
+            numResults: 0};
     }
     
     getQueryModes(): QueryMode[] {
@@ -54,6 +59,21 @@
         );
     }
     
+    setQueryStep(index: number, step: QueryStep) {
+        this.queryState.steps[index] = step;
+        this.createCypherQuery();
+    }
+    
+    createCypherQuery() {
+        var cypher = '';
+        var step = this.queryState.steps[0];
+        if (step.mode.id === 'type_is') {
+            cypher = `MATCH (e:${step.objectType}) return e`;
+        }
+        
+        this.queryState.cypherQuery = cypher;
+    }
+    
     fetchCypherResult(query: string, params = {}) {
         var headers = new Headers();
         headers.append('Authorization', 'Basic ' + btoa('neo4j' + ':' + 'neo5j'));
--- a/query-step.ts	Wed Jan 13 18:57:31 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,4 +0,0 @@
-export interface QueryStep {
-    mode: string;
-    objectType?: string;
-}
\ No newline at end of file