changeset 36:e8dc6a4c6773

only show possible incoming/outgoing relation types.
author casties
date Thu, 11 Feb 2016 17:06:40 +0100
parents b47614a9d23d
children 8e03b8fafb87
files app/query-state.ts app/query.service.ts
diffstat 2 files changed, 27 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/app/query-state.ts	Wed Feb 03 18:40:30 2016 +0100
+++ b/app/query-state.ts	Thu Feb 11 17:06:40 2016 +0100
@@ -5,7 +5,8 @@
 
     public resultCypherQuery: string;
     public attributesCypherQuery: string;
-    public relationsCypherQuery: string;
+    public outRelsCypherQuery: string;
+    public inRelsCypherQuery: string;
     public cypherQueryParams: any;
 
     public results: any[];
--- a/app/query.service.ts	Wed Feb 03 18:40:30 2016 +0100
+++ b/app/query.service.ts	Thu Feb 11 17:06:40 2016 +0100
@@ -103,7 +103,8 @@
         var queryParams = {};
         var resultQuery = '';
         var attributesQuery = '';
-        var relationsQuery = '';
+        var outRelsQuery = '';
+        var inRelsQuery = '';
         var returnType = '';
         var nIdx = 1;
         this.state.steps.forEach((step, stepIdx) => {
@@ -207,11 +208,13 @@
         attributesQuery = queryMatch + ' ' + queryWhere + ` WITH DISTINCT keys(n${nIdx}) AS atts`
             + ` UNWIND atts AS att RETURN DISTINCT att ORDER BY att`;
         // compose query for relations of result
-        relationsQuery = queryMatch + '-[r]-() ' + queryWhere + ' RETURN DISTINCT type(r)';
+        outRelsQuery = queryMatch + '-[r]->() ' + queryWhere + ' RETURN DISTINCT type(r)';
+        inRelsQuery = queryMatch + '<-[r]-() ' + queryWhere + ' RETURN DISTINCT type(r)';
         this.state.resultCypherQuery = resultQuery;
         this.state.cypherQueryParams = queryParams;
         this.state.attributesCypherQuery = attributesQuery;
-        this.state.relationsCypherQuery = relationsQuery;
+        this.state.outRelsCypherQuery = outRelsQuery;
+        this.state.inRelsCypherQuery = inRelsQuery;
         this.state.resultTypes = returnType;
     }
     
@@ -232,8 +235,12 @@
             queries.push(this.state.attributesCypherQuery);
             params.push(this.state.cypherQueryParams);
         }
-        if (this.state.relationsCypherQuery) {
-            queries.push(this.state.relationsCypherQuery);
+        if (this.state.outRelsCypherQuery) {
+            queries.push(this.state.outRelsCypherQuery);
+            params.push(this.state.cypherQueryParams);
+        }
+        if (this.state.inRelsCypherQuery) {
+            queries.push(this.state.inRelsCypherQuery);
             params.push(this.state.cypherQueryParams);
         }
         var res = this.fetchCypherResults(queries, params);
@@ -281,13 +288,20 @@
                 /*
                  * results for relations list
                  */
-                if (this.state.relationsCypherQuery) {
+                if (this.state.outRelsCypherQuery) {
+                    // outgoing aka forward relations
                     resIdx += 1;
-                    var rels = data.results[resIdx].data.map(elem => elem.row[0])
-                    .filter(elem => elem[0] != "_");
-                    // add inverse relations
-                    var invrels = rels.concat(rels.map((r) => this.invRelPrefix + r));
-                    this.state.resultRelations = invrels;
+                    let rels = data.results[resIdx].data.map(elem => elem.row[0])
+                        .filter(elem => elem[0] != "_");
+                    this.state.resultRelations = rels;
+                }
+                if (this.state.inRelsCypherQuery) {
+                    // incoming aka reverse relations
+                    resIdx += 1;
+                    let rels = data.results[resIdx].data.map(elem => elem.row[0])
+                        .filter(elem => elem[0] != "_")
+                        .map((r) => this.invRelPrefix + r);
+                    this.state.resultRelations = this.state.resultRelations.concat(rels);
                 }
             },
             err => console.error("neo4j result error=", err),