58
|
1 "use strict";
|
|
2 var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6 return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7 };
|
|
8 var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10 };
|
|
11 var core_1 = require('@angular/core');
|
|
12 var query_service_1 = require('./query.service');
|
|
13 var QueryAppComponent = (function () {
|
|
14 function QueryAppComponent(_queryService) {
|
|
15 var _this = this;
|
|
16 this._queryService = _queryService;
|
|
17 console.debug("QueryAppComponent constructor!");
|
|
18 var newState = this.getStateStringFromUrlFragment();
|
|
19 // initialize query service using external state
|
|
20 this._queryService.setup(newState);
|
|
21 this.queryStepList = [];
|
|
22 // set state in queryStepList
|
|
23 if (this._queryService.state.getNumSteps() > 0) {
|
|
24 // use state from URL
|
|
25 this._queryService.state.steps
|
|
26 .forEach(function (elem) { return _this.queryStepList.push('param'); });
|
|
27 }
|
|
28 else {
|
|
29 // new empty state
|
|
30 this.addQueryStep();
|
|
31 }
|
|
32 }
|
|
33 QueryAppComponent.prototype.getStateStringFromUrlFragment = function () {
|
|
34 var hash = window.location.hash;
|
|
35 if (hash) {
|
|
36 var fragb = hash.substr(1);
|
|
37 // base64 decode
|
|
38 var fragu = window.atob(fragb);
|
|
39 // url decode
|
|
40 var frag = decodeURIComponent(fragu);
|
|
41 // reset hash
|
|
42 window.location.hash = '';
|
|
43 return frag;
|
|
44 }
|
|
45 return null;
|
|
46 };
|
|
47 QueryAppComponent.prototype.getUrlFragmentFromState = function () {
|
|
48 var stateStr = this._queryService.state.getStateAsString();
|
|
49 var frag = '#';
|
|
50 if (stateStr.length > 0) {
|
|
51 var fragu = encodeURIComponent(stateStr);
|
|
52 var fragb = window.btoa(fragu);
|
|
53 frag += fragb;
|
|
54 }
|
|
55 return frag;
|
|
56 };
|
|
57 QueryAppComponent.prototype.addQueryStep = function () {
|
|
58 this.queryStepList.push('step');
|
|
59 };
|
|
60 QueryAppComponent.prototype.removeQueryStep = function () {
|
|
61 this.queryStepList.pop();
|
|
62 this._queryService.state.steps.pop();
|
|
63 };
|
|
64 QueryAppComponent.prototype.resetQuery = function () {
|
|
65 // reset everything by reloading
|
|
66 window.location.reload();
|
|
67 };
|
|
68 QueryAppComponent.prototype.showQueryUrl = function () {
|
|
69 var url = window.location.href;
|
|
70 url = url.replace(/#.*/, '') + this.getUrlFragmentFromState();
|
|
71 window.prompt("URL to current query state", url);
|
|
72 };
|
|
73 QueryAppComponent.prototype.onQueryChanged = function (event) {
|
|
74 console.debug("app.onquerychanged! event=", event);
|
|
75 this._queryService.runQuery();
|
|
76 this.queryState = this._queryService.getState();
|
|
77 };
|
|
78 QueryAppComponent = __decorate([
|
|
79 core_1.Component({
|
|
80 selector: 'query-app',
|
|
81 template: "\n <div class=\"container\"> \n <h1>ISMI-Lab Query Builder</h1>\n </div>\n <div class=\"container\"> \n <div>Select a query step:</div>\n <query-select *ngFor=\"let step of queryStepList; let i=index;\"\n [queryStep]=\"step\" [index]=\"i\" \n (queryChanged)=\"onQueryChanged($event)\"></query-select>\n <div>\n <button (click)=\"addQueryStep()\">add step</button>\n <button (click)=\"removeQueryStep()\">remove step</button>\n <button (click)=\"resetQuery()\">reset query</button>\n <button (click)=\"showQueryUrl()\">get query url</button>\n </div>\n </div>\n <div class=\"container\">\n <query-result *ngIf=\"queryState?.results\"\n [resultInfo]=\"queryState.resultInfo\"\n [queryState]=\"queryState\">\n </query-result>\n </div>\n ",
|
|
82 }),
|
|
83 __metadata('design:paramtypes', [query_service_1.QueryService])
|
|
84 ], QueryAppComponent);
|
|
85 return QueryAppComponent;
|
|
86 }());
|
|
87 exports.QueryAppComponent = QueryAppComponent;
|
|
88 //# sourceMappingURL=query-app.component.js.map |