Require classes for search; be very verbose for typescript
authorMike Rylander <mrylander@gmail.com>
Wed, 11 Mar 2020 18:37:32 +0000 (14:37 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Wed, 11 Mar 2020 18:39:54 +0000 (14:39 -0400)
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider-search-form.component.ts
Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider-search.service.ts

index afd33bf..26219c9 100644 (file)
@@ -68,13 +68,13 @@ export class AcqProviderSearchFormComponent implements OnInit, AfterViewInit {
 
         const searchTerms: AcqProviderSearchTerm[] = [];
         if (this.providerName) {
-            searchTerms.push({ fields: ['name'], op: 'ilike', value: this.providerName });
+            searchTerms.push({ classes: ['acqpro'], fields: ['name'], op: 'ilike', value: this.providerName });
         }
         if (this.providerCode) {
-            searchTerms.push({ fields: ['code'], op: 'ilike', value: this.providerCode });
+            searchTerms.push({ classes: ['acqpro'], fields: ['code'], op: 'ilike', value: this.providerCode });
         }
         if (this.providerOwners) {
-            searchTerms.push({ fields: ['owner'], op: 'in', value: this.providerOwners.orgIds });
+            searchTerms.push({ classes: ['acqpro'], fields: ['owner'], op: 'in', value: this.providerOwners.orgIds });
         }
         if (this.contactName) {
             searchTerms.push({ classes: ['acqpc'], fields: ['name'], op: 'ilike', value: this.contactName });
@@ -87,19 +87,19 @@ export class AcqProviderSearchFormComponent implements OnInit, AfterViewInit {
             searchTerms.push({ classes: ['acqpc','acqpro','acqpro'], fields: ['phone','phone','fax_phone'], op: 'ilike', value: this.providerPhone });
         }
         if (this.providerCurrencyType) {
-            searchTerms.push({ fields: ['currency_type'], op: 'ilike', value: this.providerCurrencyType });
+            searchTerms.push({ classes: ['acqpro'], fields: ['currency_type'], op: 'ilike', value: this.providerCurrencyType });
         }
         if (this.providerSAN) {
-            searchTerms.push({ fields: ['san'], op: 'ilike', value: this.providerSAN });
+            searchTerms.push({ classes: ['acqpro'], fields: ['san'], op: 'ilike', value: this.providerSAN });
         }
         if (this.providerEDIDefault) {
-            searchTerms.push({ fields: ['edi_default'], op: '=', value: this.providerEDIDefault });
+            searchTerms.push({ classes: ['acqpro'], fields: ['edi_default'], op: '=', value: this.providerEDIDefault });
         }
         if (this.providerURL) {
-            searchTerms.push({ fields: ['url'], op: 'ilike', value: this.providerURL });
+            searchTerms.push({ classes: ['acqpro'], fields: ['url'], op: 'ilike', value: this.providerURL });
         }
         if (this.providerIsActive) {
-            searchTerms.push({ fields: ['active'], op: '=', value: (this.providerIsActive ? 't' : 'f') });
+            searchTerms.push({ classes: ['acqpro'], fields: ['active'], op: '=', value: (this.providerIsActive ? 't' : 'f') });
         }
 
         // tossing setTimeout here to ensure that the
index 501ce59..9caa859 100644 (file)
@@ -8,7 +8,7 @@ import {Pager} from '@eg/share/util/pager';
 import {EventService} from '@eg/core/event.service';
 
 export interface AcqProviderSearchTerm {
-    classes?: string[];
+    classes: string[];
     fields: string[];
     op: string;
     value: any;
@@ -48,7 +48,7 @@ export class AcqProviderSearchService {
         class_list = class_list.filter((x, i, a) => x && x !== 'acqpro' && a.indexOf(x) == i);
 
         // build a join clause for use in the "opts" part of a pcrud query
-        class_list.forEach(cls => { joinPart[cls].type = 'left' })
+        class_list.forEach(cls => { joinPart[cls] = {type : 'left' } })
 
         if (Object.keys(joinPart).length == 0) return null;
         return joinPart;
@@ -67,7 +67,8 @@ export class AcqProviderSearchService {
             }
 
             // not const because we may want an array
-            let query_part = new Object();
+            let query_obj = new Object();
+            let query_arr = new Array();
 
             let op = term.op;
             if (!op) { op = '=' }; // just in case
@@ -88,37 +89,42 @@ export class AcqProviderSearchService {
                     isOR = true;
                     let tmp = new Object();
                     if (first_cls) {
-                        tmp['+'+first_cls] = query_part;
+                        tmp['+'+first_cls] = query_obj;
                     } else {
-                        tmp = query_part;
+                        tmp = query_obj;
                     }
 
-                    query_part = new Array();
-                    query_part.push(tmp);
+                    query_arr.push(tmp);
                 }
 
                 if (curr_cls) {
                     if (isOR) {
                         let tmp = new Object();
+                        tmp['+'+curr_cls] = new Object();
+                        tmp['+'+curr_cls][field] = new Object();
                         tmp['+'+curr_cls][field][op] = val;
-                        query_part.push(tmp);
+                        query_arr.push(tmp);
                     } else {
-                        query_part['+'+curr_cls][field][op] = val;
+                        query_obj['+'+curr_cls] = new Object();
+                        query_obj['+'+curr_cls][field] = new Object();
+                        query_obj['+'+curr_cls][field][op] = val;
                     }
                 } else {
                     if (isOR) {
                         let tmp = new Object();
+                        tmp[field] = new Object();
                         tmp[field][op] = val;
-                        query_part.push(tmp);
+                        query_arr.push(tmp);
                     } else {
-                        query_part[field][op] = val;
+                        query_obj[field] = new Object();
+                        query_obj[field][op] = val;
                     }
                 }
 
             });
 
-            if (isOR) { query_part = {'-or':query_part} }
-            query.push(query_part);
+            if (isOR) { query_obj = {'-or':query_arr} }
+            query.push(query_obj);
         });
 
         // handle grid filters