implement passing search form parameters via URL
authorGalen Charlton <gmc@equinoxinitiative.org>
Sun, 19 Jan 2020 21:58:07 +0000 (16:58 -0500)
committerGalen Charlton <gmc@equinoxinitiative.org>
Sun, 19 Jan 2020 21:58:07 +0000 (16:58 -0500)
TODO: avoid double-search on page startup
TODO: consider having the LI search results flesh invoice_entries
      so that the invoice link can be displayed only when it
      would display results

Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/eg2/src/app/staff/acq/search/acq-search-form.component.ts
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
Open-ILS/src/eg2/src/app/staff/acq/search/invoice-results.component.html
Open-ILS/src/eg2/src/app/staff/acq/search/invoice-results.component.ts
Open-ILS/src/eg2/src/app/staff/acq/search/lineitem-results.component.html
Open-ILS/src/eg2/src/app/staff/acq/search/lineitem-results.component.ts
Open-ILS/src/eg2/src/app/staff/acq/search/picklist-results.component.html
Open-ILS/src/eg2/src/app/staff/acq/search/picklist-results.component.ts
Open-ILS/src/eg2/src/app/staff/acq/search/purchase-order-results.component.html
Open-ILS/src/eg2/src/app/staff/acq/search/purchase-order-results.component.ts

index 9b92117..c745c01 100644 (file)
@@ -1,4 +1,4 @@
-import {Component, OnInit, AfterViewInit, Output, EventEmitter} from '@angular/core';
+import {Component, OnInit, AfterViewInit, Input, Output, EventEmitter} from '@angular/core';
 import {NgbTabset, NgbTabChangeEvent} from '@ng-bootstrap/ng-bootstrap';
 import {Router, ActivatedRoute} from '@angular/router';
 import {StaffCommonModule} from '@eg/staff/common.module';
@@ -14,6 +14,8 @@ import {AcqSearchTerm} from './acq-search.service';
 
 export class AcqSearchFormComponent implements OnInit, AfterViewInit {
 
+    @Input() initialSearchTerms: AcqSearchTerm[] = [];
+
     @Output() searchSubmitted = new EventEmitter<AcqSearchTerm[]>();
 
     hints = ['jub', 'acqpl', 'acqpo', 'acqinv', 'acqlid'];
@@ -71,7 +73,12 @@ export class AcqSearchFormComponent implements OnInit, AfterViewInit {
             this.searchTermDatatypes['acqlia:' + liad.id()] = 'text';
         });
 
-        this.addSearchTerm();
+        if (this.initialSearchTerms.length > 0) {
+            this.searchTerms = JSON.parse(JSON.stringify(this.initialSearchTerms)); // deep copy
+            this.submitSearch();
+        } else {
+            this.addSearchTerm();
+        }
     }
 
     ngAfterViewInit() {}
index cc2e952..d5d5a4d 100644 (file)
@@ -8,16 +8,16 @@
   <div class="col-lg-12">
     <ngb-tabset #acqSearchTabs [activeId]="searchType" (tabChange)="onTabChange($event)">
       <ngb-tab title="Line Items Search" i18n-title id="lineitems">
-        <ng-template ngbTabContent><eg-lineitem-results></eg-lineitem-results></ng-template>
+        <ng-template ngbTabContent><eg-lineitem-results [initialSearchTerms]="urlSearchTerms"></eg-lineitem-results></ng-template>
       </ngb-tab>
       <ngb-tab title="Purchase Orders Search" i18n-title id="purchaseorders">
-        <ng-template ngbTabContent><eg-purchase-order-results></eg-purchase-order-results></ng-template>
+        <ng-template ngbTabContent><eg-purchase-order-results [initialSearchTerms]="urlSearchTerms"></eg-purchase-order-results></ng-template>
       </ngb-tab>
       <ngb-tab title="Invoices Search" i18n-title id="invoices">
-        <ng-template ngbTabContent><eg-invoice-results></eg-invoice-results></ng-template>
+        <ng-template ngbTabContent><eg-invoice-results [initialSearchTerms]="urlSearchTerms"></eg-invoice-results></ng-template>
       </ngb-tab>
       <ngb-tab title="Selection Lists Search" i18n-title id="selectionlists">
-        <ng-template ngbTabContent><eg-picklist-results></eg-picklist-results></ng-template>
+        <ng-template ngbTabContent><eg-picklist-results [initialSearchTerms]="urlSearchTerms"></eg-picklist-results></ng-template>
       </ngb-tab>
     </ngb-tabset>
   </div>
index 8e3546d..e083c25 100644 (file)
@@ -1,6 +1,6 @@
 import {Component, OnInit, AfterViewInit, ViewChild, ViewChildren, QueryList} from '@angular/core';
 import {NgbTabset, NgbTabChangeEvent} from '@ng-bootstrap/ng-bootstrap';
-import {Router, ActivatedRoute} from '@angular/router';
+import {Router, ActivatedRoute, ParamMap} 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';
@@ -20,7 +20,7 @@ export class AcqSearchComponent implements OnInit, AfterViewInit {
     validSearchTypes = ['lineitems', 'purchaseorders', 'invoices', 'selectionlists'];
     defaultSearchType = 'lineitems';
 
-    searchTerms: AcqSearchTerm[] = [];
+    urlSearchTerms: AcqSearchTerm[] = [];
 
     onTabChange: ($event: NgbTabChangeEvent) => void;
     @ViewChild('acqSearchTabs', { static: true }) tabs: NgbTabset;
@@ -34,7 +34,32 @@ export class AcqSearchComponent implements OnInit, AfterViewInit {
         private route: ActivatedRoute,
         private pcrud: PcrudService,
         private idl: IdlService,
-    ) {}
+    ) {
+        this.route.queryParamMap.subscribe((params: ParamMap) => {
+            const fields = params.getAll('f');
+            const ops = params.getAll('op');
+            const values1 = params.getAll('val1');
+            const values2 = params.getAll('val2');
+            fields.forEach((f, idx) => {
+                const term: AcqSearchTerm = {
+                    field:  f,
+                    op:     '',
+                    value1: '',
+                    value2: ''
+                };
+                if (idx < ops.length) {
+                    term.op = ops[idx];
+                }
+                if (idx < values1.length) {
+                    term.value1 = values1[idx];
+                }
+                if (idx < values2.length) {
+                    term.value2 = values2[idx];
+                }
+                this.urlSearchTerms.push(term);
+            });
+        });
+    }
 
     ngOnInit() {
         const self = this;
@@ -53,6 +78,7 @@ export class AcqSearchComponent implements OnInit, AfterViewInit {
         this.onTabChange = ($event) => {
             if (this.validSearchTypes.includes($event.nextId)) {
                 this.searchType = $event.nextId;
+                this.urlSearchTerms = [];
                 this.router.navigate(['/staff', 'acq', 'search', $event.nextId]);
             }
         };
index cb15329..0f778bc 100644 (file)
@@ -1,4 +1,4 @@
-<eg-acq-search-form (searchSubmitted)="doSearch($event)"></eg-acq-search-form>
+<eg-acq-search-form (searchSubmitted)="doSearch($event)" [initialSearchTerms]="initialSearchTerms"></eg-acq-search-form>
 
 <ng-template #inv_identTmpl let-invoice="row">
   <a href="/eg/staff/acq/legacy/invoice/view/{{invoice.id()}}"
index e3396d6..30359a8 100644 (file)
@@ -1,4 +1,4 @@
-import {Component, OnInit, ViewChild} from '@angular/core';
+import {Component, OnInit, Input, ViewChild} from '@angular/core';
 import {Observable} from 'rxjs';
 import {map} from 'rxjs/operators';
 import {Router, ActivatedRoute, ParamMap} from '@angular/router';
@@ -21,6 +21,8 @@ import {AcqSearchFormComponent} from './acq-search-form.component';
 })
 export class InvoiceResultsComponent implements OnInit {
 
+    @Input() initialSearchTerms: AcqSearchTerm[] = [];
+
     gridSource: GridDataSource;
     @ViewChild('acqSearchInvoicesGrid', { static: true }) invoiceResultsGrid: GridComponent;
     @ViewChild('printfail', { static: true }) private printfail: AlertDialogComponent;
index e1b222f..59dd86f 100644 (file)
@@ -1,4 +1,4 @@
-<eg-acq-search-form (searchSubmitted)="doSearch($event)"></eg-acq-search-form>
+<eg-acq-search-form (searchSubmitted)="doSearch($event)" [initialSearchTerms]="initialSearchTerms"></eg-acq-search-form>
 
 <ng-template #idTmpl let-lineitem="row">
   <a *ngIf="lineitem.purchase_order()" href="/eg/staff/acq/legacy/po/view/{{lineitem.purchase_order()}}?focus_li={{lineitem.id()}}"
@@ -38,7 +38,9 @@
           target="_blank" i18n>Purchase Order</a></li>
     <li><a href="/eg/staff/acq/requests/lineitem/{{lineitem.id()}}"
            target="_blank" i18n>Requests</a></li>
-    <li>Invoices TODO; awaits Angular invoice search</li>
+    <li>
+      <a routerLink="/staff/acq/search/invoices" [queryParams]="{f: 'jub:id', val1: lineitem.id()}"
+        target="_blank" i18n>Invoices</a></li>
     <li *ngIf="lineitem.queued_record()">
       <a routerLink="/staff/cat/vandelay/queue/bib/{{lineitem.queued_record().queue()}}"
         target="_blank" i18n>Queue</a></li>
index 1a61196..1518f9b 100644 (file)
@@ -1,4 +1,4 @@
-import {Component, OnInit, ViewChild} from '@angular/core';
+import {Component, OnInit, Input, ViewChild} from '@angular/core';
 import {Observable} from 'rxjs';
 import {map} from 'rxjs/operators';
 import {Router, ActivatedRoute, ParamMap} from '@angular/router';
@@ -18,6 +18,8 @@ import {AcqSearchFormComponent} from './acq-search-form.component';
 })
 export class LineitemResultsComponent implements OnInit {
 
+    @Input() initialSearchTerms: AcqSearchTerm[] = [];
+
     gridSource: GridDataSource;
     @ViewChild('acqSearchLineitemsGrid', { static: true }) lineitemResultsGrid: GridComponent;
 
index 4d9cdc9..c66fbfd 100644 (file)
@@ -1,4 +1,4 @@
-<eg-acq-search-form (searchSubmitted)="doSearch($event)"></eg-acq-search-form>
+<eg-acq-search-form (searchSubmitted)="doSearch($event)" [initialSearchTerms]="initialSearchTerms"></eg-acq-search-form>
 
 <eg-string #createSelectionListString i18n-text text="Selection List Created">
 </eg-string>
index 7745486..606eff8 100644 (file)
@@ -1,4 +1,4 @@
-import {Component, OnInit, ViewChild} from '@angular/core';
+import {Component, OnInit, Input, ViewChild} from '@angular/core';
 import {Observable} from 'rxjs';
 import {map} from 'rxjs/operators';
 import {Router, ActivatedRoute, ParamMap} from '@angular/router';
@@ -25,6 +25,8 @@ import {AcqSearchFormComponent} from './acq-search-form.component';
 })
 export class PicklistResultsComponent implements OnInit {
 
+    @Input() initialSearchTerms: AcqSearchTerm[] = [];
+
     gridSource: GridDataSource;
     @ViewChild('acqSearchPicklistsGrid', { static: true }) picklistResultsGrid: GridComponent;
     @ViewChild('picklistCreateDialog', { static: true }) picklistCreateDialog: PicklistCreateDialogComponent;
index 4ceda8a..b9e83a5 100644 (file)
@@ -1,4 +1,4 @@
-<eg-acq-search-form (searchSubmitted)="doSearch($event)"></eg-acq-search-form>
+<eg-acq-search-form (searchSubmitted)="doSearch($event)" [initialSearchTerms]="initialSearchTerms"></eg-acq-search-form>
 
 <ng-template #nameTmpl let-purchaseorder="row">
   <a href="/eg/staff/acq/legacy/po/view/{{purchaseorder.id()}}"
index 5861da6..bb605e6 100644 (file)
@@ -1,4 +1,4 @@
-import {Component, OnInit, ViewChild} from '@angular/core';
+import {Component, OnInit, Input, ViewChild} from '@angular/core';
 import {Observable} from 'rxjs';
 import {map} from 'rxjs/operators';
 import {Router, ActivatedRoute, ParamMap} from '@angular/router';
@@ -18,6 +18,8 @@ import {AcqSearchFormComponent} from './acq-search-form.component';
 })
 export class PurchaseOrderResultsComponent implements OnInit {
 
+    @Input() initialSearchTerms: AcqSearchTerm[] = [];
+
     gridSource: GridDataSource;
     @ViewChild('acqSearchPurchaseOrdersGrid', { static: true }) purchaseOrderResultsGrid: GridComponent;