changeset 41:5353b2dffb0f

added local configuration file app/app-config.ts.
author casties
date Mon, 15 Feb 2016 17:05:07 +0100
parents 896ae7eefb33
children 99fb5a953a40
files .hgignore app/app-config.ts.template app/ismi-relation-types.ts app/normalization.service.ts app/query.service.ts index.html
diffstat 6 files changed, 46 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Mon Feb 15 11:10:08 2016 +0100
+++ b/.hgignore	Mon Feb 15 17:05:07 2016 +0100
@@ -6,4 +6,6 @@
 syntax: regexp
 ^jspm_packages$
 syntax: regexp
-^\.settings$
\ No newline at end of file
+^\.settings$
+syntax: regexp
+^app/app-config\.ts$
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/app-config.ts.template	Mon Feb 15 17:05:07 2016 +0100
@@ -0,0 +1,9 @@
+/* 
+ * app-config.ts
+ * configuration for query builder tool
+ */
+export const NEO4J_BASE_URL = 'https://ismi-dev.mpiwg-berlin.mpg.de/neo4j-ismi/db/data';
+
+export const NEO4J_AUTHENTICATION = {'user': 'bla', 'password': 'blub'};
+
+export const OPENMIND_BASE_URL = 'https://ismi-dev.mpiwg-berlin.mpg.de/om4-ismi/';
--- a/app/ismi-relation-types.ts	Mon Feb 15 11:10:08 2016 +0100
+++ b/app/ismi-relation-types.ts	Mon Feb 15 17:05:07 2016 +0100
@@ -6,7 +6,7 @@
 addRelationType('is_exemplar_of', 'title of witness', 'witnesses to title');
 addRelationType('was_created_by', 'created by', 'works of');
 addRelationType('has_subject', 'subject of title', 'titles with subject');
-addRelationType('has_role', 'role of person', 'persons with role');
+addRelationType('has_role', 'roles of person', 'persons with role');
 addRelationType('is_alias_name_of', 'person name for alias', 'alias of person');
 addRelationType('is_alias_title_of', 'title name for alias', 'alias of title');
 addRelationType('is_commentary_on', 'is commentary on', 'list of commentaries');
--- a/app/normalization.service.ts	Mon Feb 15 11:10:08 2016 +0100
+++ b/app/normalization.service.ts	Mon Feb 15 17:05:07 2016 +0100
@@ -3,12 +3,11 @@
 
 import 'rxjs/Rx'; // import all RxJS operators
 
+import {OPENMIND_BASE_URL} from './app-config';
+
 @Injectable()
 export class NormalizationService {
 
-    public openMindBaseUrl = 'https://ismi-dev.mpiwg-berlin.mpg.de/om4-ismi/';
-    //public openMindBaseUrl = 'http://localhost:18080/ismi-richfaces/';
-
     constructor(private _http: Http) {}
 
     fetchArabicTranslitNormalizedString(text: string) {
@@ -18,8 +17,8 @@
         // put headers in options
         var opts = {'headers': headers};
         // make get request asynchronously
-        var url = this.openMindBaseUrl+'jsonInterface?method=normalize_string&type=arabic_translit&text=';
-        url += text;
+        var url = OPENMIND_BASE_URL+'jsonInterface?method=normalize_string&type=arabic_translit&text=';
+        url += encodeURIComponent(text);
         var resp = this._http.get(url, opts)
         // filter result as JSON
         .map(res => res.json());
--- 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
--- a/index.html	Mon Feb 15 11:10:08 2016 +0100
+++ b/index.html	Mon Feb 15 17:05:07 2016 +0100
@@ -1,6 +1,6 @@
 <html>
-
   <head>
+    <meta charset="utf-8" /> 
     <title>ISMI Query Builder</title>
 
     <!--link to bootstrap.css-->