Mercurial > hg > ng2-query-ismi
view src/app/query-state.ts @ 61:6adf95d9a190 webpack
fix missing resultInfo. add column template for WITNESS.
author | Robert Casties <casties@mpiwg-berlin.mpg.de> |
---|---|
date | Mon, 24 Apr 2017 19:39:25 +0200 |
parents | d7c947909ab8 |
children |
line wrap: on
line source
import {QueryStep} from './query-step'; import {ResultType} from './result-type'; import {QueryMode, getQueryModeById} from './query-mode'; export class QueryState { public steps: QueryStep[] = []; public resultCypherQuery: string; public attributesCypherQuery: string; public outRelsCypherQuery: string; public inRelsCypherQuery: string; public cypherQueryParams: any; public results: any[]; public numResults: number; public resultTypes: string; public resultType: ResultType; public resultInfo: string; public resultAttributes: string[]; public resultRelations: any[]; public resultColumns: any[]; /** * Sets the query state from a string. */ setStateFromString(newStateString: string) { try { // state string is json let newState = JSON.parse(newStateString); // state should be list of steps if (!Array.isArray(newState)) return; let newSteps: QueryStep[] = []; newState.forEach((elem) => { // step is an array [mode, params] if (!Array.isArray(elem)) return; let mode = elem[0]; // get QueryMode object let qm: QueryMode = getQueryModeById(mode); let params = elem[1]; if (qm != null && params != null) { // construct QueryStep let qs = new QueryStep(qm, params); newSteps.push(qs); } }); if (newSteps.length > 0) { // set new state this.steps = newSteps; } } catch (e) { console.error("Unable to set state from string: "+newStateString); } } getNumSteps() { return this.steps.length; } /** * Returns the current query state as a string. */ getStateAsString(): string { let stateList = this.steps.map((qs) => [qs.mode.id, qs.params]); let stateStr = JSON.stringify(stateList); return stateStr; } /** * Returns the cypher query as text for display. */ getQueryText() { let text = this.resultCypherQuery; let hasParams = false; for (let k in this.cypherQueryParams) { if (!hasParams) { hasParams = true; text += '\n'; } text += `[${k}='${this.cypherQueryParams[k]}'] `; } return text; } }