diff app/query.service.ts @ 21:930fe7460f6b

result table shows all attributes now.
author casties
date Fri, 22 Jan 2016 20:33:26 +0100
parents 34cd764e234b
children 9343e43a17d1
line wrap: on
line diff
--- a/app/query.service.ts	Fri Jan 22 17:32:33 2016 +0100
+++ b/app/query.service.ts	Fri Jan 22 20:33:26 2016 +0100
@@ -44,13 +44,13 @@
         if (queryMode.id === 'type_is') {
             options = this.objectTypes;
         } else if (queryMode.id === 'relation_is') {
-            options = this.state.nextQueryRelations;
+            options = this.state.resultRelations;
         } else if (queryMode.id === 'att_contains') {
-            options = this.state.nextQueryAttributes;
+            options = this.filterAttributes(this.state.resultAttributes);
         } else if (queryMode.id === 'att_contains_norm') {
-            options = this.state.nextQueryAttributes;
+            options = this.filterAttributes(this.state.resultAttributes, true);
         } else if (queryMode.id === 'att_num_range') {
-            options = this.state.nextQueryAttributes;
+            options = this.filterAttributes(this.state.resultAttributes);
         }
         console.debug("getQueryOptions returns: ", options);
         return options;
@@ -237,8 +237,9 @@
                  */
                 if (this.state.attributesCypherQuery) {
                     resIdx += 1;
-                    this.state.nextQueryAttributes = data.results[resIdx].data.map(elem => elem.row[0])
-                    .filter(elem => elem[0] != "_" && !this.excludedAttributes[elem]);
+                    var atts = data.results[resIdx].data.map(elem => elem.row[0]);
+                    this.state.resultAttributes = atts;                   
+                    this.state.resultColumns = this.getColumns(atts);
                 }
                 /*
                  * results for relations list
@@ -249,7 +250,7 @@
                     .filter(elem => elem[0] != "_");
                     // add inverse relations
                     var invrels = rels.concat(rels.map((r) => this.invRelPrefix + r));
-                    this.state.nextQueryRelations = invrels;
+                    this.state.resultRelations = invrels;
                 }
             },
             err => console.error("neo4j result error=", err),
@@ -257,6 +258,41 @@
         );
     }
     
+    
+    filterAttributes(attributes: string[], normalized=false) {
+        var atts = [];
+        if (normalized) {
+            attributes.forEach((att) => {
+                if (att.substr(0, 3) == "_n_") {
+                    atts.push(att.substr(3));
+                }
+            });
+        } else {
+            atts = attributes.filter(elem => elem[0] != "_" && !this.excludedAttributes[elem]);
+        }
+        return atts;
+    }
+    
+    /**
+     * Return nice column objects  
+     */
+    getColumns(attributes: string[]) {
+        var cols = [];
+        if (attributes.indexOf('ismi_id') > -1) {
+            cols.push({'name': 'ismi_id', 'label': 'ISMI ID'});
+        }
+        if (attributes.indexOf('label') > -1) {
+            cols.push({'name': 'label', 'label': 'Label'});
+        }
+        attributes.forEach((att) => {
+            if (att != 'ismi_id' && att != 'label' && att != 'type' && att[0] != '_') {
+                cols.push({'name': att, 'label': att});
+            }
+        });
+           
+        return cols;
+    }
+    
     /**
      * Run the given queries on the Neo4J server.
      *