diff src/app/query-app.component.ts @ 55:308c96f734c8 ng2-table

first steps to importing state from URL.
author casties
date Mon, 27 Mar 2017 14:17:55 +0200
parents f8d6f8479e77
children b22e52a128a8
line wrap: on
line diff
--- a/src/app/query-app.component.ts	Thu Mar 23 18:57:01 2017 +0100
+++ b/src/app/query-app.component.ts	Mon Mar 27 14:17:55 2017 +0200
@@ -1,5 +1,4 @@
 import {Component} from '@angular/core';
-//import {HTTP_PROVIDERS} from '@angular/http';
 
 import {QueryState} from './query-state';
 import {QueryStep} from './query-step';
@@ -7,10 +6,6 @@
 import {QueryService} from './query.service';
 import {NormalizationService} from './normalization.service';
 
-import {QuerySelectComponent} from './query-select.component';
-import {QueryResultComponent} from './query-result.component';
-//import {QueryResultTableComponent} from './query-result-table.component';
-
 @Component({
     selector: 'query-app',
     template: `
@@ -34,8 +29,6 @@
         </query-result>
     </div>
         `,
-    //directives: [QuerySelectComponent, QueryResultTableComponent],
-    //providers: [QueryService, NormalizationService, HTTP_PROVIDERS]
 })
     
 export class QueryAppComponent { 
@@ -43,11 +36,27 @@
     public queryStepList: string[];
         
     constructor(private _queryService: QueryService) {
-        this._queryService.setup();
+        console.debug("QueryAppComponent constructor!");
+        let newState = this.getStateStringFromFragment();
+        this._queryService.setup(newState);
         this.queryStepList = [];
+        if (this._queryService.state.getNumSteps() > 0) {
+            this._queryService.state.steps
+                .forEach((elem) => this.queryStepList.push('param'));
+        }
         this.addQueryStep();
     }
     
+    getStateStringFromFragment(): string {
+        let hash: string = window.location.hash;
+        if (hash) {
+            let frag: string = hash.substr(1);
+            // base64 decode
+            return frag;
+        }
+        return null;
+    }
+    
     addQueryStep() {
         this.queryStepList.push('step');
     }