diff app/query.service.ts @ 41:5353b2dffb0f

added local configuration file app/app-config.ts.
author casties
date Mon, 15 Feb 2016 17:05:07 +0100
parents 896ae7eefb33
children dc4f0541f04d
line wrap: on
line diff
--- a/app/query.service.ts	Mon Feb 15 11:10:08 2016 +0100
+++ b/app/query.service.ts	Mon Feb 15 17:05:07 2016 +0100
@@ -4,6 +4,7 @@
 import 'rxjs/Rx'; // import all RxJS operators
 //import 'rxjs/add/operator/map';
 
+import {NEO4J_BASE_URL, NEO4J_AUTHENTICATION} from './app-config'; 
 import {QueryMode, QUERY_MODES, FIRST_QUERY_MODES} from './query-mode';
 import {QueryState} from './query-state';
 import {QueryStep} from './query-step';
@@ -14,9 +15,6 @@
 @Injectable()
 export class QueryService {
         
-    //public neo4jBaseUrl = 'https://ismi-dev.mpiwg-berlin.mpg.de/neo4j-ismi/db/data';
-    public neo4jBaseUrl = 'http://localhost:7474/db/data';
-    public neo4jAuthentication = {'user': 'neo4j', 'password': 'neo5j'};
     public typeAttribute = '_type';
     public excludedAttributes = {};
     public state: QueryState;
@@ -47,7 +45,7 @@
      * return the first set of options for the given query mode.
      */
     getQueryOptions(queryMode: QueryMode) {
-        var options = [];
+        let options = [];
         if (queryMode == null) return options;
         if (queryMode.id === 'type_is') {
             options = this.objectTypes;
@@ -68,11 +66,11 @@
      * fetch all object types from Neo4j and store in this.objectTypes.
      */
     setupObjectTypes() {
-        var query = `MATCH (n) WITH DISTINCT labels(n) AS labels
+        let query = `MATCH (n) WITH DISTINCT labels(n) AS labels
                 UNWIND labels AS label 
                 RETURN DISTINCT label ORDER BY label`;
 
-        var res = this.fetchCypherResults([query]);
+        let res = this.fetchCypherResults([query]);
         res.subscribe(
             data => {
                 console.debug("neo4j data=", data);
@@ -97,19 +95,19 @@
      * Updates the queries for results, attributes and relations.
      */
     createCypherQuery() {
-        var queryMatch = '';
-        var queryWhere = '';
-        var queryReturn = '';
-        var queryParams = {};
-        var resultQuery = '';
-        var attributesQuery = '';
-        var outRelsQuery = '';
-        var inRelsQuery = '';
-        var returnType = '';
-        var nIdx = 1;
+        let queryMatch = '';
+        let queryWhere = '';
+        let queryReturn = '';
+        let queryParams = {};
+        let resultQuery = '';
+        let attributesQuery = '';
+        let outRelsQuery = '';
+        let inRelsQuery = '';
+        let returnType = '';
+        let nIdx = 1;
         this.state.steps.forEach((step, stepIdx) => {
-            var mode = step.mode.id;
-            var params = step.params;
+            let mode = step.mode.id;
+            let params = step.params;
             
             /*
              * step: object type is
@@ -228,8 +226,8 @@
         /*
          * run query for result table
          */
-        var queries = [this.state.resultCypherQuery];
-        var params = [this.state.cypherQueryParams];
+        let queries = [this.state.resultCypherQuery];
+        let params = [this.state.cypherQueryParams];
         if (this.state.attributesCypherQuery) {
             queries.push(this.state.attributesCypherQuery);
             params.push(this.state.cypherQueryParams);
@@ -242,11 +240,11 @@
             queries.push(this.state.inRelsCypherQuery);
             params.push(this.state.cypherQueryParams);
         }
-        var res = this.fetchCypherResults(queries, params);
+        let res = this.fetchCypherResults(queries, params);
         res.subscribe(
             data => {
                 console.debug("neo4j result data=", data);
-                var resIdx = 0;
+                let resIdx = 0;
                 /*
                  * results for result table
                  */
@@ -263,7 +261,7 @@
                     }
                 });
                 let info = '';
-                for (var t in resTypes) {
+                for (let t in resTypes) {
                     info += t + '(' + resTypes[t] + ') ';   
                 }
                 info = info.substr(0, info.length-1);
@@ -311,7 +309,7 @@
     
     
     filterAttributes(attributes: string[], normalized=false) {
-        var atts = [];
+        let atts = [];
         if (normalized) {
             attributes.forEach((att) => {
                 if (att.substr(0, 3) == "_n_") {
@@ -331,21 +329,21 @@
      */
     fetchCypherResults(queries: string[], params=[{}]) {
         console.debug("fetching cypher queries: ", queries);
-        var headers = new Headers();
-        var auth = this.neo4jAuthentication;
+        let headers = new Headers();
+        let auth = NEO4J_AUTHENTICATION;
         headers.append('Authorization', 'Basic ' + btoa(`${auth.user}:${auth.password}`));
         headers.append('Content-Type', 'application/json');
         headers.append('Accept', 'application/json');
         // put headers in options
-        var opts = {'headers': headers};
+        let opts = {'headers': headers};
         // unpack queries into statements
-        var statements = queries.map((q, i) => {
+        let statements = queries.map((q, i) => {
             return {'statement': q, 'parameters': (params[i])?params[i]:{}};
         });
         // create POST data from query
-        var data = JSON.stringify({'statements': statements});
+        let data = JSON.stringify({'statements': statements});
         // make post request asynchronously
-        var resp = this._http.post(this.neo4jBaseUrl+'/transaction/commit', data, opts)
+        let resp = this._http.post(NEO4J_BASE_URL+'/transaction/commit', data, opts)
         // filter result as JSON
         .map(res => res.json());
         // return Observable