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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
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
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
19 public resultAttributes: string[];
21
930fe7460f6b result table shows all attributes now.
casties
parents: 20
diff changeset
20 public resultRelations: any[];
930fe7460f6b result table shows all attributes now.
casties
parents: 20
diff changeset
21 public resultColumns: any[];
20
34cd764e234b make interfaces into classes. factor out NormalizationService.
casties
parents: 7
diff changeset
22
55
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
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
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
27 setStateFromString(newStateString: string) {
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
28 try {
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
29 // state string is json
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
30 let newState = JSON.parse(newStateString);
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
31 // state should be list of steps
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
32 if (!Array.isArray(newState)) return;
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
33 let newSteps: QueryStep[] = [];
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
34 newState.forEach((elem) => {
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
35 // step is an array [mode, params]
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
36 if (!Array.isArray(elem)) return;
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
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
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
39 let qm: QueryMode = getQueryModeById(mode);
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
40 let params = elem[1];
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
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
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
43 let qs = new QueryStep(qm, params);
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
44 newSteps.push(qs);
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
45 }
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
46 });
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
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
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
49 this.steps = newSteps;
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
50 }
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
51 } catch (e) {
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
52 console.error("Unable to set state from string: "+newStateString);
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
53 }
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
54 }
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
55
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
56 getNumSteps() {
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
57 return this.steps.length;
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
58 }
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
59
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
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
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
70 * Returns the cypher query as text for display.
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
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
351c3df28602 work on result component.
casties
parents:
diff changeset
84 }