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_step_1 = require('./query-step');
|
|
13 var query_service_1 = require('./query.service');
|
|
14 var normalization_service_1 = require('./normalization.service');
|
|
15 var ismi_relation_types_1 = require('./ismi-relation-types');
|
|
16 var QuerySelectComponent = (function () {
|
|
17 function QuerySelectComponent(_queryService, _normService) {
|
|
18 this._queryService = _queryService;
|
|
19 this._normService = _normService;
|
|
20 // output queryChanged
|
|
21 this.queryChanged = new core_1.EventEmitter();
|
|
22 }
|
|
23 QuerySelectComponent.prototype.ngOnInit = function () {
|
|
24 this.setup();
|
|
25 };
|
|
26 QuerySelectComponent.prototype.setup = function () {
|
|
27 console.log("query-select setup step=", this.queryStep);
|
|
28 var step = this._queryService.state.steps[this.index]; // i-1?
|
|
29 if (step != null) {
|
|
30 this.setQueryStep(step);
|
|
31 }
|
|
32 };
|
|
33 QuerySelectComponent.prototype.getQueryModes = function () {
|
|
34 this.queryModes = this._queryService.getQueryModes(this.index);
|
|
35 return this.queryModes;
|
|
36 };
|
|
37 QuerySelectComponent.prototype.onSelectMode = function (event) {
|
|
38 var selected = event.target.value;
|
|
39 this.selectedMode = this.queryModes.find(function (mode) { return mode.id === selected; });
|
|
40 this.queryOptions = this._queryService.getQueryOptions(this.selectedMode);
|
|
41 };
|
|
42 QuerySelectComponent.prototype.onSelectOption = function (event) {
|
|
43 var selected = event.target.value;
|
|
44 console.debug("selected option:", selected);
|
|
45 this.selectedOption = selected;
|
|
46 this.onSubmit();
|
|
47 };
|
|
48 QuerySelectComponent.prototype.onSubmit = function () {
|
|
49 console.debug("Submit! selectedMode=", this.selectedMode, " selectedOption=", this.selectedOption, " queryInput=", this.queryInput);
|
|
50 var step = this.getQueryStep();
|
|
51 /*
|
|
52 * set step and submit change event
|
|
53 */
|
|
54 if (step != null) {
|
|
55 this._queryService.setQueryStep(this.index, step);
|
|
56 this.queryChanged.emit(this._queryService.getState());
|
|
57 }
|
|
58 return false;
|
|
59 };
|
|
60 /**
|
|
61 * Returns QueryStep from current form state.
|
|
62 */
|
|
63 QuerySelectComponent.prototype.getQueryStep = function () {
|
|
64 var _this = this;
|
|
65 var step = null;
|
|
66 if (this.selectedMode.id === 'type_is') {
|
|
67 /*
|
|
68 * type_is
|
|
69 */
|
|
70 var opt = this.selectedOption;
|
|
71 if (opt) {
|
|
72 step = new query_step_1.QueryStep(this.selectedMode, { 'objectType': opt });
|
|
73 }
|
|
74 }
|
|
75 else if (this.selectedMode.id === 'relation_is') {
|
|
76 /*
|
|
77 * relation_is
|
|
78 */
|
|
79 var opt = this.selectedOption;
|
|
80 if (opt) {
|
|
81 var rel = ismi_relation_types_1.getRelationByName(opt);
|
|
82 step = new query_step_1.QueryStep(this.selectedMode, { 'relationType': rel });
|
|
83 }
|
|
84 }
|
|
85 else if (this.selectedMode.id === 'id_is') {
|
|
86 /*
|
|
87 * id is
|
|
88 */
|
|
89 var val = this.queryInput;
|
|
90 if (val) {
|
|
91 step = new query_step_1.QueryStep(this.selectedMode, { 'value': val });
|
|
92 }
|
|
93 }
|
|
94 else if (this.selectedMode.id === 'att_contains') {
|
|
95 /*
|
|
96 * att_contains
|
|
97 */
|
|
98 var att = this.selectedOption;
|
|
99 var val = this.queryInput;
|
|
100 if (att && val) {
|
|
101 step = new query_step_1.QueryStep(this.selectedMode, { 'attribute': att, 'value': val });
|
|
102 }
|
|
103 }
|
|
104 else if (this.selectedMode.id === 'att_num_range') {
|
|
105 /*
|
|
106 * att_num_range
|
|
107 */
|
|
108 var att = this.selectedOption;
|
|
109 var nlo = this.queryInput;
|
|
110 var nhi = this.queryInput2;
|
|
111 if (att && nlo && nhi) {
|
|
112 step = new query_step_1.QueryStep(this.selectedMode, { 'attribute': att, 'numLo': nlo, 'numHi': nhi });
|
|
113 }
|
|
114 }
|
|
115 else if (this.selectedMode.id === 'att_contains_norm') {
|
|
116 /*
|
|
117 * att_contains_norm
|
|
118 *
|
|
119 * calls normalization service and submits event in callback
|
|
120 */
|
|
121 var att_1 = this.selectedOption;
|
|
122 var val_1 = this.queryInput;
|
|
123 if (att_1 && val_1) {
|
|
124 // run search term through normalizer
|
|
125 this._normService.fetchArabicTranslitNormalizedString(val_1)
|
|
126 .subscribe(function (data) {
|
|
127 console.debug("openmind norm data=", data);
|
|
128 step = new query_step_1.QueryStep(_this.selectedMode, { 'attribute': att_1, 'value': val_1, 'normValue': data.normalized_text });
|
|
129 _this._queryService.setQueryStep(_this.index, step);
|
|
130 // query has changed now
|
|
131 _this.queryChanged.emit(_this._queryService.getState());
|
|
132 }, function (err) { return console.error("openmind norm error=", err); }, function () { return console.debug("openmind norm query Complete"); });
|
|
133 // query has not been set yet (gets set in callback)
|
|
134 return null;
|
|
135 }
|
|
136 }
|
|
137 return step;
|
|
138 };
|
|
139 /**
|
|
140 * Sets form state from given QueryStep.
|
|
141 */
|
|
142 QuerySelectComponent.prototype.setQueryStep = function (step) {
|
|
143 var mode = step.mode;
|
|
144 this.selectedMode = mode;
|
|
145 if (mode.id === 'id_is') {
|
|
146 /*
|
|
147 * id_is
|
|
148 */
|
|
149 this.queryInput = step.params.value;
|
|
150 }
|
|
151 else if (mode.id === 'type_is') {
|
|
152 /*
|
|
153 * type_is
|
|
154 */
|
|
155 var name_1 = step.params.objectType;
|
|
156 this.queryOptions = [name_1];
|
|
157 this.selectedOption = name_1;
|
|
158 }
|
|
159 else if (this.selectedMode.id === 'relation_is') {
|
|
160 /*
|
|
161 * relation_is
|
|
162 */
|
|
163 var name_2 = step.params.relationType.name;
|
|
164 var rel = ismi_relation_types_1.getRelationByName(name_2);
|
|
165 this.queryOptions = [rel];
|
|
166 this.selectedOption = name_2;
|
|
167 }
|
|
168 else if (this.selectedMode.id === 'att_contains') {
|
|
169 /*
|
|
170 * att_contains
|
|
171 */
|
|
172 var name_3 = step.params.attribute;
|
|
173 this.queryOptions = [name_3];
|
|
174 this.selectedOption = name_3;
|
|
175 this.queryInput = step.params.value;
|
|
176 }
|
|
177 else if (this.selectedMode.id === 'att_num_range') {
|
|
178 /*
|
|
179 * att_num_range
|
|
180 */
|
|
181 var name_4 = step.params.attribute;
|
|
182 this.queryOptions = [name_4];
|
|
183 this.selectedOption = name_4;
|
|
184 this.queryInput = step.params.numLo;
|
|
185 this.queryInput2 = step.params.numHi;
|
|
186 }
|
|
187 else if (this.selectedMode.id === 'att_contains_norm') {
|
|
188 /*
|
|
189 * att_contains_norm
|
|
190 */
|
|
191 var name_5 = step.params.attribute;
|
|
192 this.queryOptions = [name_5];
|
|
193 this.selectedOption = name_5;
|
|
194 this.queryInput = step.params.value;
|
|
195 }
|
|
196 // TODO: implement other modes
|
|
197 this.resultInfo = step.resultInfo;
|
|
198 };
|
|
199 QuerySelectComponent = __decorate([
|
|
200 core_1.Component({
|
|
201 selector: 'query-select',
|
|
202 template: "\n<p *ngIf=\"resultInfo\"> result: {{resultInfo}}</p>\n<div>\n <form (ngSubmit)=\"onSubmit()\">\n <select name=\"mode\" (change)=\"onSelectMode($event)\">\n <option></option>\n <option *ngFor=\"let mode of getQueryModes()\" \n [selected]=\"mode.id==selectedMode?.id\" [value]=\"mode.id\">\n {{mode.label}}\n </option>\n </select>\n\n <span *ngIf=\"selectedMode?.id=='type_is'\">\n <select name=\"option\" *ngIf=\"queryOptions\" [ngModel]=\"selectedOption\" (change)=\"onSelectOption($event)\">\n <option></option>\n <option *ngFor=\"let option of queryOptions\" [value]=\"option\">\n {{option}}\n </option>\n </select>\n </span>\n\n <span *ngIf=\"selectedMode?.id=='relation_is'\">\n <select name=\"option\" *ngIf=\"queryOptions\" [ngModel]=\"selectedOption\" (change)=\"onSelectOption($event)\">\n <option></option>\n <option *ngFor=\"let option of queryOptions\" [value]=\"option.getName()\">\n {{option.getLabel()}}\n </option>\n </select>\n </span>\n\n <span *ngIf=\"selectedMode?.id=='att_contains' || selectedMode?.id=='att_contains_norm'\">\n <select name=\"option\" [ngModel]=\"selectedOption\" (change)=\"selectedOption=$event.target.value\">\n <option></option>\n <option *ngFor=\"let option of queryOptions\" [value]=\"option\">\n {{option}}\n </option>\n </select>\n <span>contains</span>\n <input type=\"text\" name=\"value\" [(ngModel)]=\"queryInput\"/>\n </span>\n\n <span *ngIf=\"selectedMode?.id=='att_num_range'\">\n <select name=\"option\" [ngModel]=\"selectedOption\" (change)=\"selectedOption=$event.target.value\">\n <option></option>\n <option *ngFor=\"let option of queryOptions\" [value]=\"option\">\n {{option}}\n </option>\n </select>\n <span>is between</span>\n <input type=\"text\" name=\"value1\" [(ngModel)]=\"queryInput\"/>\n <span>and</span>\n <input type=\"text\" name=\"value2\" [(ngModel)]=\"queryInput2\"/>\n </span>\n\n <span *ngIf=\"selectedMode?.id=='id_is'\">\n <input type=\"text\" name=\"value\" [(ngModel)]=\"queryInput\"/>\n </span>\n\n <button type=\"submit\">Submit</button>\n </form>\n</div>\n ",
|
|
203 inputs: ['queryStep', 'index'],
|
|
204 outputs: ['queryChanged']
|
|
205 }),
|
|
206 __metadata('design:paramtypes', [query_service_1.QueryService, normalization_service_1.NormalizationService])
|
|
207 ], QuerySelectComponent);
|
|
208 return QuerySelectComponent;
|
|
209 }());
|
|
210 exports.QuerySelectComponent = QuerySelectComponent;
|
|
211 //# sourceMappingURL=query-select.component.js.map |