Mercurial > hg > ng2-query-ismi
diff app/query.service.ts @ 39:7578b21cdf2e
make relation types configurable.
relations can have custom labels for incoming or outgoing direction.
author | casties |
---|---|
date | Sun, 14 Feb 2016 19:40:07 +0100 |
parents | e8dc6a4c6773 |
children | 896ae7eefb33 |
line wrap: on
line diff
--- a/app/query.service.ts Sun Feb 14 19:38:36 2016 +0100 +++ b/app/query.service.ts Sun Feb 14 19:40:07 2016 +0100 @@ -9,16 +9,16 @@ import {QueryStep} from './query-step'; import {getResultType} from './result-type'; import {ISMI_RESULT_TYPES} from './ismi-result-types'; +import {getRelationType} from './ismi-relation-types'; @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 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 invRelPrefix = '<- '; public state: QueryState; public objectTypes: string[]; @@ -149,15 +149,14 @@ */ if (mode === 'relation_is') { nIdx += 1; - var rel = params.relationType; - if (rel.indexOf(this.invRelPrefix) == 0) { + let rel = params.relationType; + if (rel.isOutgoing()) { + queryMatch += `-[:\`${rel.getName()}\`]->(n${nIdx})`; + } else { // inverse relation - rel = rel.substr(this.invRelPrefix.length); - queryMatch += `<-[:${rel}]-(n${nIdx})`; - } else { - queryMatch += `-[:${rel}]->(n${nIdx})`; + queryMatch += `<-[:\`${rel.getName()}\`]-(n${nIdx})`; } - queryReturn = `RETURN n${nIdx}`; + queryReturn = `RETURN DISTINCT n${nIdx}`; returnType = 'node'; } @@ -292,7 +291,8 @@ // outgoing aka forward relations resIdx += 1; let rels = data.results[resIdx].data.map(elem => elem.row[0]) - .filter(elem => elem[0] != "_"); + .filter(elem => elem[0] != "_") + .map(elem => getRelationType(elem, true)); this.state.resultRelations = rels; } if (this.state.inRelsCypherQuery) { @@ -300,7 +300,7 @@ resIdx += 1; let rels = data.results[resIdx].data.map(elem => elem.row[0]) .filter(elem => elem[0] != "_") - .map((r) => this.invRelPrefix + r); + .map(elem => getRelationType(elem, false)); this.state.resultRelations = this.state.resultRelations.concat(rels); } },