Mercurial > hg > ng2-query-ismi
annotate src/app/query-app.component.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 | b22e52a128a8 |
children |
rev | line source |
---|---|
45 | 1 import {Component} from '@angular/core'; |
0 | 2 |
7
6cd6c09032aa
object type query with results!
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
6
diff
changeset
|
3 import {QueryState} from './query-state'; |
8 | 4 import {QueryStep} from './query-step'; |
5 | |
20
34cd764e234b
make interfaces into classes. factor out NormalizationService.
casties
parents:
13
diff
changeset
|
6 import {QueryService} from './query.service'; |
34cd764e234b
make interfaces into classes. factor out NormalizationService.
casties
parents:
13
diff
changeset
|
7 import {NormalizationService} from './normalization.service'; |
34cd764e234b
make interfaces into classes. factor out NormalizationService.
casties
parents:
13
diff
changeset
|
8 |
0 | 9 @Component({ |
7
6cd6c09032aa
object type query with results!
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
6
diff
changeset
|
10 selector: 'query-app', |
0 | 11 template: ` |
25 | 12 <div class="container"> |
13
98b435bb6c0c
more query work.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
10
diff
changeset
|
13 <h1>ISMI-Lab Query Builder</h1> |
26 | 14 </div> |
15 <div class="container"> | |
8 | 16 <div>Select a query step:</div> |
45 | 17 <query-select *ngFor="let step of queryStepList; let i=index;" |
8 | 18 [queryStep]="step" [index]="i" |
19 (queryChanged)="onQueryChanged($event)"></query-select> | |
20 <div> | |
21 <button (click)="addQueryStep()">add step</button> | |
22 <button (click)="removeQueryStep()">remove step</button> | |
57
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
56
diff
changeset
|
23 <button (click)="resetQuery()">reset query</button> |
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
56
diff
changeset
|
24 <button (click)="showQueryUrl()">get query url</button> |
8 | 25 </div> |
26 | 26 </div> |
27 | 27 <div class="container"> |
33 | 28 <query-result *ngIf="queryState?.results" |
27 | 29 [resultInfo]="queryState.resultInfo" |
30 [queryState]="queryState"> | |
31 </query-result> | |
25 | 32 </div> |
0 | 33 `, |
34 }) | |
1
59b7c3afcc6b
first interface and http request.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
35 |
7
6cd6c09032aa
object type query with results!
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
6
diff
changeset
|
36 export class QueryAppComponent { |
6cd6c09032aa
object type query with results!
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
6
diff
changeset
|
37 public queryState: QueryState; |
20
34cd764e234b
make interfaces into classes. factor out NormalizationService.
casties
parents:
13
diff
changeset
|
38 public queryStepList: string[]; |
5
b06a5d61afed
new query state stuff.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
4
diff
changeset
|
39 |
7
6cd6c09032aa
object type query with results!
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
6
diff
changeset
|
40 constructor(private _queryService: QueryService) { |
55 | 41 console.debug("QueryAppComponent constructor!"); |
57
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
56
diff
changeset
|
42 let newState = this.getStateStringFromUrlFragment(); |
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
56
diff
changeset
|
43 // initialize query service using external state |
55 | 44 this._queryService.setup(newState); |
20
34cd764e234b
make interfaces into classes. factor out NormalizationService.
casties
parents:
13
diff
changeset
|
45 this.queryStepList = []; |
57
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
56
diff
changeset
|
46 // set state in queryStepList |
55 | 47 if (this._queryService.state.getNumSteps() > 0) { |
56
b22e52a128a8
query from url fragment works now somewhat (only for id_is).
casties
parents:
55
diff
changeset
|
48 // use state from URL |
55 | 49 this._queryService.state.steps |
50 .forEach((elem) => this.queryStepList.push('param')); | |
56
b22e52a128a8
query from url fragment works now somewhat (only for id_is).
casties
parents:
55
diff
changeset
|
51 } else { |
b22e52a128a8
query from url fragment works now somewhat (only for id_is).
casties
parents:
55
diff
changeset
|
52 // new empty state |
b22e52a128a8
query from url fragment works now somewhat (only for id_is).
casties
parents:
55
diff
changeset
|
53 this.addQueryStep(); |
55 | 54 } |
8 | 55 } |
56 | |
57
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
56
diff
changeset
|
57 getStateStringFromUrlFragment(): string { |
55 | 58 let hash: string = window.location.hash; |
59 if (hash) { | |
57
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
56
diff
changeset
|
60 let fragb: string = hash.substr(1); |
55 | 61 // base64 decode |
57
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
56
diff
changeset
|
62 let fragu = window.atob(fragb); |
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
56
diff
changeset
|
63 // url decode |
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
56
diff
changeset
|
64 let frag = decodeURIComponent(fragu); |
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
56
diff
changeset
|
65 // reset hash |
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
56
diff
changeset
|
66 window.location.hash = ''; |
55 | 67 return frag; |
68 } | |
69 return null; | |
70 } | |
71 | |
57
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
56
diff
changeset
|
72 getUrlFragmentFromState() { |
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
56
diff
changeset
|
73 let stateStr = this._queryService.state.getStateAsString(); |
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
56
diff
changeset
|
74 let frag = '#'; |
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
56
diff
changeset
|
75 if (stateStr.length > 0) { |
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
56
diff
changeset
|
76 let fragu = encodeURIComponent(stateStr); |
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
56
diff
changeset
|
77 let fragb = window.btoa(fragu); |
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
56
diff
changeset
|
78 frag += fragb; |
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
56
diff
changeset
|
79 } |
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
56
diff
changeset
|
80 return frag; |
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
56
diff
changeset
|
81 } |
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
56
diff
changeset
|
82 |
8 | 83 addQueryStep() { |
20
34cd764e234b
make interfaces into classes. factor out NormalizationService.
casties
parents:
13
diff
changeset
|
84 this.queryStepList.push('step'); |
8 | 85 } |
86 | |
87 removeQueryStep() { | |
20
34cd764e234b
make interfaces into classes. factor out NormalizationService.
casties
parents:
13
diff
changeset
|
88 this.queryStepList.pop(); |
8 | 89 this._queryService.state.steps.pop(); |
5
b06a5d61afed
new query state stuff.
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
4
diff
changeset
|
90 } |
4 | 91 |
57
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
56
diff
changeset
|
92 resetQuery() { |
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
56
diff
changeset
|
93 // reset everything by reloading |
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
56
diff
changeset
|
94 window.location.reload(); |
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
56
diff
changeset
|
95 } |
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
56
diff
changeset
|
96 |
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
56
diff
changeset
|
97 showQueryUrl() { |
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
56
diff
changeset
|
98 let url = window.location.href |
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
56
diff
changeset
|
99 url = url.replace(/#.*/, '') + this.getUrlFragmentFromState(); |
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
56
diff
changeset
|
100 window.prompt("URL to current query state", url); |
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
56
diff
changeset
|
101 } |
d7c947909ab8
renamed query-app.module to app.module. loading query from url fragment works now.
casties
parents:
56
diff
changeset
|
102 |
7
6cd6c09032aa
object type query with results!
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
6
diff
changeset
|
103 onQueryChanged(event: any) { |
6cd6c09032aa
object type query with results!
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
6
diff
changeset
|
104 console.debug("app.onquerychanged! event=", event); |
40 | 105 this._queryService.runQuery(); |
7
6cd6c09032aa
object type query with results!
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
6
diff
changeset
|
106 this.queryState = this._queryService.getState(); |
6cd6c09032aa
object type query with results!
Robert Casties <casties@mpiwg-berlin.mpg.de>
parents:
6
diff
changeset
|
107 } |
0 | 108 } |