diff app/query-select.component.ts @ 20:34cd764e234b

make interfaces into classes. factor out NormalizationService.
author casties
date Fri, 22 Jan 2016 17:32:33 +0100
parents f84ff6781e57
children 4c046f3244ec
line wrap: on
line diff
--- a/app/query-select.component.ts	Thu Jan 21 20:22:02 2016 +0100
+++ b/app/query-select.component.ts	Fri Jan 22 17:32:33 2016 +0100
@@ -1,10 +1,12 @@
 import {Component, Output, EventEmitter, OnInit} from 'angular2/core';
 
-import {QueryService} from './query.service';
 import {QueryMode} from './query-mode';
 import {QueryStep} from './query-step';
 import {QueryState} from './query-state';
 
+import {QueryService} from './query.service';
+import {NormalizationService} from './normalization.service';
+
 
 @Component({
     selector: 'query-select',
@@ -19,7 +21,7 @@
             </option>
         </select>
 
-        <span *ngIf="selectedMode && selectedMode.id=='type_is' || selectedMode.id=='relation_is'">
+        <span *ngIf="selectedMode && (selectedMode.id=='type_is' || selectedMode.id=='relation_is')">
             <select *ngIf="queryOptions" [(ngModel)]="selectedOption" (change)="onSelectOption($event)">
                 <option></option>
                 <option *ngFor="#option of queryOptions" [value]="option">
@@ -28,7 +30,7 @@
             </select>
         </span>
 
-        <span *ngIf="selectedMode && selectedMode.id=='att_contains' || selectedMode.id=='att_contains_norm'">
+        <span *ngIf="selectedMode && (selectedMode.id=='att_contains' || selectedMode.id=='att_contains_norm')">
             <select [(ngModel)]="selectedOption">
                 <option></option>
                 <option *ngFor="#option of queryOptions" [value]="option">
@@ -61,7 +63,7 @@
 })
    
 export class QuerySelectComponent implements OnInit { 
-    public queryStep: QueryStep;
+    public queryStep: string;
     public index: number;
     public resultInfo: string;
     public queryModes: QueryMode[];
@@ -73,7 +75,7 @@
     
     @Output('queryChanged') queryChanged = new EventEmitter<QueryState>();
     
-    constructor(private _queryService: QueryService) {}
+    constructor(private _queryService: QueryService, private _normService: NormalizationService) {}
     
     ngOnInit() {
         this.setup();
@@ -86,9 +88,6 @@
         if (step != null) {
             this.resultInfo = step.resultInfo;
         }
-        // select first mode (too early?)
-        this.selectedMode = this.queryModes[0];
-        this.query2Options = this._queryService.getQueryOptions(this.selectedMode);
     }
     
     onSelectMode(event: any) {
@@ -110,36 +109,36 @@
         if (this.selectedMode.id == 'type_is') {
             var opt = this.selectedOption;
             if (opt) {
-                step = {'mode': this.selectedMode, 'objectType': opt};
+                step = new QueryStep(this.selectedMode, {'objectType': opt});
            }
         } else if (this.selectedMode.id == 'relation_is') {
             var opt = this.selectedOption;
             if (opt) {
-                step = {'mode': this.selectedMode, 'relationType': opt};
+                step = new QueryStep(this.selectedMode, {'relationType': opt});
            }
         } else if (this.selectedMode.id == 'att_contains') {
             var att = this.selectedOption;
             var val = this.queryInput;
             if (att && val) {
-                step = {'mode': this.selectedMode, 'attribute': att, 'value': val};
+                step = new QueryStep(this.selectedMode, {'attribute': att, 'value': val});
            }
         } else if (this.selectedMode.id == 'att_num_range') {
             var att = this.selectedOption;
             var nlo = this.queryInput;
             var nhi = this.queryInput2;
             if (att && nlo && nhi) {
-                step = {'mode': this.selectedMode, 'attribute': att, 'numLo': nlo, 'numHi': nhi};
+                step = new QueryStep(this.selectedMode, {'attribute': att, 'numLo': nlo, 'numHi': nhi});
            }
         } else if (this.selectedMode.id == 'att_contains_norm') {
             var att = this.selectedOption;
             var val = this.queryInput;
             if (att && val) {
                 // run search term through normalizer 
-                this._queryService.fetchNormalizedString(val)
+                this._normService.fetchArabicTranslitNormalizedString(val)
                 .subscribe(
                     data => {
                         console.debug("openmind norm data=", data);
-                        step = {'mode': this.selectedMode, 'attribute': att, 'value': val, 'normValue': data.normalized_text};
+                        step = new QueryStep(this.selectedMode, {'attribute': att, 'value': val, 'normValue': data.normalized_text});
                         this._queryService.setQueryStep(this.index, step);
                         // query has changed now
                         this.queryChanged.emit(this._queryService.getState());