annotate src/app/query-state.ts @ 55:308c96f734c8 ng2-table

first steps to importing state from URL.
author casties
date Mon, 27 Mar 2017 14:17:55 +0200
parents b65a031c4967
children d7c947909ab8
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
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
24 setStateFromString(newStateString: string) {
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
25 try {
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
26 // state string is json
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
27 let newState = JSON.parse(newStateString);
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
28 // state should be list of steps
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
29 if (!Array.isArray(newState)) return;
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
30 let newSteps: QueryStep[] = [];
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
31 newState.forEach((elem) => {
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
32 // step is an array [mode, params]
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
33 if (!Array.isArray(elem)) return;
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
34 let mode = elem[0];
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
35 let qm: QueryMode = getQueryModeById(mode);
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
36 let params = elem[1];
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
37 if (qm != null && params != null) {
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
38 let qs = new QueryStep(qm, params);
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
39 newSteps.push(qs);
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
40 }
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
41 });
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
42 if (newSteps.length > 0) {
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
43 // set state
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
44 this.steps = newSteps;
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 } catch (e) {
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
47 console.error("Unable to set state from string: "+newStateString);
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
48 }
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
49 }
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 getNumSteps() {
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
52 return this.steps.length;
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 * Returns the cypher query as text for display.
308c96f734c8 first steps to importing state from URL.
casties
parents: 47
diff changeset
57 */
31
4926885f8a99 selectable result columns. nicer cypher query output.
casties
parents: 21
diff changeset
58 getQueryText() {
4926885f8a99 selectable result columns. nicer cypher query output.
casties
parents: 21
diff changeset
59 let text = this.resultCypherQuery;
4926885f8a99 selectable result columns. nicer cypher query output.
casties
parents: 21
diff changeset
60 let hasParams = false;
4926885f8a99 selectable result columns. nicer cypher query output.
casties
parents: 21
diff changeset
61 for (let k in this.cypherQueryParams) {
4926885f8a99 selectable result columns. nicer cypher query output.
casties
parents: 21
diff changeset
62 if (!hasParams) {
4926885f8a99 selectable result columns. nicer cypher query output.
casties
parents: 21
diff changeset
63 hasParams = true;
4926885f8a99 selectable result columns. nicer cypher query output.
casties
parents: 21
diff changeset
64 text += '\n';
4926885f8a99 selectable result columns. nicer cypher query output.
casties
parents: 21
diff changeset
65 }
4926885f8a99 selectable result columns. nicer cypher query output.
casties
parents: 21
diff changeset
66 text += `[${k}='${this.cypherQueryParams[k]}'] `;
4926885f8a99 selectable result columns. nicer cypher query output.
casties
parents: 21
diff changeset
67 }
4926885f8a99 selectable result columns. nicer cypher query output.
casties
parents: 21
diff changeset
68 return text;
4926885f8a99 selectable result columns. nicer cypher query output.
casties
parents: 21
diff changeset
69 }
4
351c3df28602 work on result component.
casties
parents:
diff changeset
70 }