Mercurial > hg > ng2-query-ismi
annotate src/app/query-state.ts @ 57:d7c947909ab8 ng2-table
renamed query-app.module to app.module. loading query from url fragment works now.
author | casties |
---|---|
date | Wed, 29 Mar 2017 17:16:10 +0200 |
parents | 308c96f734c8 |
children |
rev | line source |
---|---|
7
6cd6c09032aa
object type query with results!
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
6
diff
changeset
|
1 import {QueryStep} from './query-step'; |
47
b65a031c4967
first step to angular2-final (2.4) version of the query browser.
casties
parents:
36
diff
changeset
|
2 import {ResultType} from './result-type'; |
55 | 3 import {QueryMode, getQueryModeById} from './query-mode'; |
7
6cd6c09032aa
object type query with results!
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
6
diff
changeset
|
4 |
20
34cd764e234b
make interfaces into classes. factor out NormalizationService.
casties
parents:
7
diff
changeset
|
5 export class QueryState { |
34cd764e234b
make interfaces into classes. factor out NormalizationService.
casties
parents:
7
diff
changeset
|
6 public steps: QueryStep[] = []; |
34cd764e234b
make interfaces into classes. factor out NormalizationService.
casties
parents:
7
diff
changeset
|
7 |
34cd764e234b
make interfaces into classes. factor out NormalizationService.
casties
parents:
7
diff
changeset
|
8 public resultCypherQuery: string; |
34cd764e234b
make interfaces into classes. factor out NormalizationService.
casties
parents:
7
diff
changeset
|
9 public attributesCypherQuery: string; |
36
e8dc6a4c6773
only show possible incoming/outgoing relation types.
casties
parents:
31
diff
changeset
|
10 public outRelsCypherQuery: string; |
e8dc6a4c6773
only show possible incoming/outgoing relation types.
casties
parents:
31
diff
changeset
|
11 public inRelsCypherQuery: string; |
20
34cd764e234b
make interfaces into classes. factor out NormalizationService.
casties
parents:
7
diff
changeset
|
12 public cypherQueryParams: any; |
34cd764e234b
make interfaces into classes. factor out NormalizationService.
casties
parents:
7
diff
changeset
|
13 |
34cd764e234b
make interfaces into classes. factor out NormalizationService.
casties
parents:
7
diff
changeset
|
14 public results: any[]; |
34cd764e234b
make interfaces into classes. factor out NormalizationService.
casties
parents:
7
diff
changeset
|
15 public numResults: number; |
34cd764e234b
make interfaces into classes. factor out NormalizationService.
casties
parents:
7
diff
changeset
|
16 public resultTypes: string; |
47
b65a031c4967
first step to angular2-final (2.4) version of the query browser.
casties
parents:
36
diff
changeset
|
17 public resultType: ResultType; |
20
34cd764e234b
make interfaces into classes. factor out NormalizationService.
casties
parents:
7
diff
changeset
|
18 public resultInfo: string; |
55 | 19 public resultAttributes: string[]; |
21 | 20 public resultRelations: any[]; |
21 public resultColumns: any[]; | |
20
34cd764e234b
make interfaces into classes. factor out NormalizationService.
casties
parents:
7
diff
changeset
|
22 |
55 | 23 |
57
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
55
diff
changeset
|
24 /** |
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
55
diff
changeset
|
25 * Sets the query state from a string. |
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
55
diff
changeset
|
26 */ |
55 | 27 setStateFromString(newStateString: string) { |
28 try { | |
29 // state string is json | |
30 let newState = JSON.parse(newStateString); | |
31 // state should be list of steps | |
32 if (!Array.isArray(newState)) return; | |
33 let newSteps: QueryStep[] = []; | |
34 newState.forEach((elem) => { | |
35 // step is an array [mode, params] | |
36 if (!Array.isArray(elem)) return; | |
37 let mode = elem[0]; | |
57
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
55
diff
changeset
|
38 // get QueryMode object |
55 | 39 let qm: QueryMode = getQueryModeById(mode); |
40 let params = elem[1]; | |
41 if (qm != null && params != null) { | |
57
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
55
diff
changeset
|
42 // construct QueryStep |
55 | 43 let qs = new QueryStep(qm, params); |
44 newSteps.push(qs); | |
45 } | |
46 }); | |
47 if (newSteps.length > 0) { | |
57
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
55
diff
changeset
|
48 // set new state |
55 | 49 this.steps = newSteps; |
50 } | |
51 } catch (e) { | |
52 console.error("Unable to set state from string: "+newStateString); | |
53 } | |
54 } | |
55 | |
56 getNumSteps() { | |
57 return this.steps.length; | |
58 } | |
59 | |
60 /** | |
57
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
55
diff
changeset
|
61 * Returns the current query state as a string. |
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
55
diff
changeset
|
62 */ |
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
55
diff
changeset
|
63 getStateAsString(): string { |
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
55
diff
changeset
|
64 let stateList = this.steps.map((qs) => [qs.mode.id, qs.params]); |
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
55
diff
changeset
|
65 let stateStr = JSON.stringify(stateList); |
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
55
diff
changeset
|
66 return stateStr; |
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
55
diff
changeset
|
67 } |
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
55
diff
changeset
|
68 |
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
55
diff
changeset
|
69 /** |
55 | 70 * Returns the cypher query as text for display. |
71 */ | |
31
4926885f8a99
selectable result columns. nicer cypher query output.
casties
parents:
21
diff
changeset
|
72 getQueryText() { |
4926885f8a99
selectable result columns. nicer cypher query output.
casties
parents:
21
diff
changeset
|
73 let text = this.resultCypherQuery; |
4926885f8a99
selectable result columns. nicer cypher query output.
casties
parents:
21
diff
changeset
|
74 let hasParams = false; |
4926885f8a99
selectable result columns. nicer cypher query output.
casties
parents:
21
diff
changeset
|
75 for (let k in this.cypherQueryParams) { |
4926885f8a99
selectable result columns. nicer cypher query output.
casties
parents:
21
diff
changeset
|
76 if (!hasParams) { |
4926885f8a99
selectable result columns. nicer cypher query output.
casties
parents:
21
diff
changeset
|
77 hasParams = true; |
4926885f8a99
selectable result columns. nicer cypher query output.
casties
parents:
21
diff
changeset
|
78 text += '\n'; |
4926885f8a99
selectable result columns. nicer cypher query output.
casties
parents:
21
diff
changeset
|
79 } |
4926885f8a99
selectable result columns. nicer cypher query output.
casties
parents:
21
diff
changeset
|
80 text += `[${k}='${this.cypherQueryParams[k]}'] `; |
4926885f8a99
selectable result columns. nicer cypher query output.
casties
parents:
21
diff
changeset
|
81 } |
4926885f8a99
selectable result columns. nicer cypher query output.
casties
parents:
21
diff
changeset
|
82 return text; |
4926885f8a99
selectable result columns. nicer cypher query output.
casties
parents:
21
diff
changeset
|
83 } |
4 | 84 } |