diff app/query-select.component.ts @ 39:7578b21cdf2e

make relation types configurable. relations can have custom labels for incoming or outgoing direction.
author casties
date Sun, 14 Feb 2016 19:40:07 +0100
parents 8e03b8fafb87
children 896ae7eefb33
line wrap: on
line diff
--- a/app/query-select.component.ts	Sun Feb 14 19:38:36 2016 +0100
+++ b/app/query-select.component.ts	Sun Feb 14 19:40:07 2016 +0100
@@ -6,6 +6,7 @@
 
 import {QueryService} from './query.service';
 import {NormalizationService} from './normalization.service';
+import {getRelationType} from './ismi-relation-types';
 
 
 @Component({
@@ -21,7 +22,7 @@
             </option>
         </select>
 
-        <span *ngIf="selectedMode?.id=='type_is' || selectedMode?.id=='relation_is'">
+        <span *ngIf="selectedMode?.id=='type_is'">
             <select *ngIf="queryOptions" [ngModel]="selectedOption" (change)="onSelectOption($event)">
                 <option></option>
                 <option *ngFor="#option of queryOptions" [value]="option">
@@ -30,6 +31,15 @@
             </select>
         </span>
 
+        <span *ngIf="selectedMode?.id=='relation_is'">
+            <select *ngIf="queryOptions" [ngModel]="selectedOption" (change)="onSelectOption($event)">
+                <option></option>
+                <option *ngFor="#option of queryOptions" [value]="option.getName()">
+                    {{option.getLabel()}}
+                </option>
+            </select>
+        </span>
+
         <span *ngIf="selectedMode?.id=='att_contains' || selectedMode?.id=='att_contains_norm'">
             <select [ngModel]="selectedOption" (change)="selectedOption=$event.target.value">
                 <option></option>
@@ -116,36 +126,57 @@
         console.debug("Submit! selectedMode=", this.selectedMode, " selectedOption=", this.selectedOption, " queryInput=", this.queryInput);
         var step: QueryStep;
         if (this.selectedMode.id == 'type_is') {
-            var opt = this.selectedOption;
+            /*
+             * type_is
+             */
+            let opt = this.selectedOption;
             if (opt) {
                 step = new QueryStep(this.selectedMode, {'objectType': opt});
             }
         } else if (this.selectedMode.id == 'relation_is') {
-            var opt = this.selectedOption;
+            /*
+             * relation_is
+             */
+            let opt = this.selectedOption;
             if (opt) {
-                step = new QueryStep(this.selectedMode, {'relationType': opt});
+                let rel = getRelationType(opt);
+                step = new QueryStep(this.selectedMode, {'relationType': rel});
+            }
+        } else if (this.selectedMode.id == 'id_is') {
+            /*
+             * id is
+             */
+            let val = this.queryInput;
+            if (val) {
+                step = new QueryStep(this.selectedMode, {'value': val});
             }
         } else if (this.selectedMode.id == 'att_contains') {
-            var att = this.selectedOption;
-            var val = this.queryInput;
+            /*
+             * att_contains
+             */
+            let att = this.selectedOption;
+            let val = this.queryInput;
             if (att && val) {
                 step = new QueryStep(this.selectedMode, {'attribute': att, 'value': val});
             }
-        } else if (this.selectedMode.id == 'id_is') {
-            var val = this.queryInput;
-            if (val) {
-                step = new QueryStep(this.selectedMode, {'value': val});
-            }
         } else if (this.selectedMode.id == 'att_num_range') {
-            var att = this.selectedOption;
-            var nlo = this.queryInput;
-            var nhi = this.queryInput2;
+            /*
+             * att_num_range
+             */
+            let att = this.selectedOption;
+            let nlo = this.queryInput;
+            let nhi = this.queryInput2;
             if (att && nlo && 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;
+            /*
+             * att_contains_norm
+             * 
+             * calls normalization service and submits event in callback
+             */
+            let att = this.selectedOption;
+            let val = this.queryInput;
             if (att && val) {
                 // run search term through normalizer 
                 this._normService.fetchArabicTranslitNormalizedString(val)
@@ -165,6 +196,9 @@
            }
         }
 
+        /*
+         * set step and submit change event
+         */
         if (step != null) {
             this._queryService.setQueryStep(this.index, step);
             this.queryChanged.emit(this._queryService.getState());