start work on search form
authorMike Rylander <mrylander@gmail.com>
Thu, 16 Jan 2020 21:57:04 +0000 (16:57 -0500)
committerGalen Charlton <gmc@equinoxinitiative.org>
Thu, 16 Jan 2020 21:57:04 +0000 (16:57 -0500)
- IDL-based field selector
- conditional selection of search inputs

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/eg2/src/app/staff/acq/search/acq-search.component.html
Open-ILS/src/eg2/src/app/staff/acq/search/acq-search.component.ts

index d1d43ee..33d6487 100644 (file)
@@ -5,6 +5,38 @@
   <div class="ml-auto mr-3"><a i18n href="/eg/staff/acq/legacy/search/unified">Legacy Search Interface</a></div>
 </div>
 <div class="row">
+  <div class="col-lg-3">
+    <select class="form-control" id="selected-search-term" [ngModelOptions]="{standalone: true}" [(ngModel)]="selectedSearchTerm">
+      <option disabled="disabled" i18n>Select Search Field</option>
+      <optgroup *ngFor="let g of hints" label="{{availableSearchTerms[g]['__label']}}">
+        <option *ngFor="let o of availableSearchTerms[g]['__fields']" value="{{g}}:{{o}}">
+          {{availableSearchTerms[g][o].label}}
+        </option>
+      </optgroup>
+    </select>
+  </div>
+  <div class="col-lg-3">
+    <select class="form-control" id="selected-search-op" [ngModelOptions]="{standalone: true}" [(ngModel)]="selectedSearchOp">
+      <option i18n value="">is</option>
+      <option i18n value="__not">is NOT</option>
+      <option i18n value="__fuzzy" [disabled]="searchTermDatatypes[selectedSearchTerm] != 'text'">contains</option>
+      <option i18n value="__not,__fuzzy" [disabled]="searchTermDatatypes[selectedSearchTerm] != 'text'">does NOT contain</option>
+      <option i18n value="__lte" [disabled]="searchTermDatatypes[selectedSearchTerm] != 'timestamp'">is on or BEFORE</option>
+      <option i18n value="__gte" [disabled]="searchTermDatatypes[selectedSearchTerm] != 'timestamp'">is on or AFTER</option>
+      <option i18n value="__in">matches a term from a file</option>
+    </select>
+  </div>
+  <div class="col-lg-3">
+  </div>
+</div>
+<div class="row">
+  <div class="col-lg-2">
+    <button class="form-control" i18n>Add Search Term</button>
+  </div>
+</div>
+<div class="row">
+</div>
+<div class="row">
   <div class="col-lg-12">
     <ngb-tabset #acqSearchTabs [activeId]="searchType" (tabChange)="onTabChange($event)" type="pills">
       <ngb-tab title="Line Items Search" i18n-title id="lineitems">
index 9e92d5b..fc71497 100644 (file)
@@ -2,6 +2,8 @@ import {Component, OnInit, AfterViewInit, ViewChild} from '@angular/core';
 import {NgbTabset, NgbTabChangeEvent} from '@ng-bootstrap/ng-bootstrap';
 import {Router, ActivatedRoute} from '@angular/router';
 import {StaffCommonModule} from '@eg/staff/common.module';
+import {IdlService, IdlObject} from '@eg/core/idl.service';
+import {PcrudService} from '@eg/core/pcrud.service';
 import {LineitemResultsComponent} from './lineitem-results.component';
 import {PurchaseOrderResultsComponent} from './purchase-order-results.component';
 import {InvoiceResultsComponent} from './invoice-results.component';
@@ -13,6 +15,12 @@ import {PicklistResultsComponent} from './picklist-results.component';
 
 export class AcqSearchComponent implements OnInit, AfterViewInit {
 
+    selectedSearchTerm: String;
+    selectedSearchOp: String;
+
+    hints = ["jub", "acqpl", "acqpo", "acqinv", "acqlid"];
+    availableSearchTerms = {};
+    searchTermDatatypes = {};
     searchType = '';
     validSearchTypes = ['lineitems', 'purchaseorders', 'invoices', 'selectionlists'];
     defaultSearchType = 'lineitems';
@@ -23,9 +31,15 @@ export class AcqSearchComponent implements OnInit, AfterViewInit {
     constructor(
         private router: Router,
         private route: ActivatedRoute,
+        private pcrud: PcrudService,
+        private idl: IdlService,
     ) {}
 
     ngOnInit() {
+        var self = this;
+        this.selectedSearchTerm = '';
+        this.selectedSearchOp = '';
+
         const searchTypeParam = this.route.snapshot.paramMap.get('searchtype');
 
         if (searchTypeParam) {
@@ -42,6 +56,39 @@ export class AcqSearchComponent implements OnInit, AfterViewInit {
                 this.router.navigate(['/staff', 'acq', 'search', $event.nextId]);
             }
         };
+
+        this.hints.forEach(
+            function(hint) {
+                var o = {};
+                o['__label'] = self.idl.classes[hint].label;
+                o['__fields'] = [];
+                self.idl.classes[hint].fields.forEach(
+                    function(field) {
+                        if (!field.virtual) {
+                            o['__fields'].push(field.name);
+                            o[field.name] = {
+                                "label": field.label, "datatype": field.datatype
+                            };
+                            self.searchTermDatatypes[hint+':'+field.name] = field.datatype;
+                        }
+                    }
+                );
+                self.availableSearchTerms[hint] = o;
+            }
+        );
+
+        this.hints.push('acqlia');
+        this.availableSearchTerms['acqlia'] = {"__label": this.idl.classes.acqlia.label, "__fields": []};
+        this.pcrud.retrieveAll("acqliad", {"order_by": {"acqliad": "id"}})
+        .subscribe(liad => {
+            this.availableSearchTerms['acqlia']['__fields'].push(''+liad.id());
+            this.availableSearchTerms['acqlia'][liad.id()] = {
+                "label": liad.description(),
+                "datatype": "text"
+            };
+            this.searchTermDatatypes['acqlia:'+liad.id()] = 'text';
+        });
+
     }
 
     ngAfterViewInit() {}