From 9d5472e68657aec4051f472dd47ac05d8073c19f Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Thu, 16 Jan 2020 18:50:02 -0500 Subject: [PATCH] start fleshing out more of the search form - start adding appropriate input widgets based on field type - set up proof of concept of integrating search terms from form with grid filters - do some renaming and defining interfaces Signed-off-by: Galen Charlton --- .../app/staff/acq/search/acq-search.component.html | 32 ++++++++++------- .../app/staff/acq/search/acq-search.component.ts | 40 ++++++++++++++++------ .../src/app/staff/acq/search/acq-search.service.ts | 24 +++++++++++++ .../acq/search/purchase-order-results.component.ts | 6 +++- 4 files changed, 78 insertions(+), 24 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search.component.html b/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search.component.html index 33d6487ef4..75d10d927c 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search.component.html +++ b/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search.component.html @@ -4,34 +4,42 @@ -
+
- - - +
-
- - - - - + + + +
+ + + +
- + +
+
+
diff --git a/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search.component.ts b/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search.component.ts index fd4bfa599e..6a23ce50c5 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search.component.ts @@ -1,9 +1,10 @@ -import {Component, OnInit, AfterViewInit, ViewChild} from '@angular/core'; +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 {StaffCommonModule} from '@eg/staff/common.module'; import {IdlService, IdlObject} from '@eg/core/idl.service'; import {PcrudService} from '@eg/core/pcrud.service'; +import {AcqSearchTerm} from './acq-search.service'; import {LineitemResultsComponent} from './lineitem-results.component'; import {PurchaseOrderResultsComponent} from './purchase-order-results.component'; import {InvoiceResultsComponent} from './invoice-results.component'; @@ -15,18 +16,18 @@ import {PicklistResultsComponent} from './picklist-results.component'; export class AcqSearchComponent implements OnInit, AfterViewInit { - selectedSearchTerm: String; - selectedSearchOp: String; - hints = ['jub', 'acqpl', 'acqpo', 'acqinv', 'acqlid']; - availableSearchTerms = {}; + availableSearchFields = {}; searchTermDatatypes = {}; searchType = ''; validSearchTypes = ['lineitems', 'purchaseorders', 'invoices', 'selectionlists']; defaultSearchType = 'lineitems'; + searchTerms: AcqSearchTerm[] = []; + onTabChange: ($event: NgbTabChangeEvent) => void; @ViewChild('acqSearchTabs', { static: true }) tabs: NgbTabset; + @ViewChildren(PurchaseOrderResultsComponent) poResults: QueryList; constructor( private router: Router, @@ -37,8 +38,6 @@ export class AcqSearchComponent implements OnInit, AfterViewInit { ngOnInit() { const self = this; - this.selectedSearchTerm = ''; - this.selectedSearchOp = ''; const searchTypeParam = this.route.snapshot.paramMap.get('searchtype'); @@ -74,24 +73,43 @@ export class AcqSearchComponent implements OnInit, AfterViewInit { } } ); - self.availableSearchTerms[hint] = o; + self.availableSearchFields[hint] = o; } ); this.hints.push('acqlia'); - this.availableSearchTerms['acqlia'] = {'__label': this.idl.classes.acqlia.label, '__fields': []}; + this.availableSearchFields['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()] = { + this.availableSearchFields['acqlia']['__fields'].push('' + liad.id()); + this.availableSearchFields['acqlia'][liad.id()] = { label: liad.description(), datatype: 'text' }; this.searchTermDatatypes['acqlia:' + liad.id()] = 'text'; }); + this.addSearchTerm(); } ngAfterViewInit() {} + addSearchTerm() { + this.searchTerms.push({ field: '', op: '', value1: '', value2: '' }); + } + + setOrgUnitSearchValue(org: IdlObject, term: AcqSearchTerm) { + if (org == null) { + term.value1 = ''; + } else { + term.value1 = org.id(); + } + } + + submitSearch() { + if (this.searchType === 'purchaseorders') { + this.poResults.forEach(poResult => poResult.doSearch(this.searchTerms)); + } + } + } diff --git a/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search.service.ts b/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search.service.ts index 97ead98903..778a8c4387 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search.service.ts +++ b/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search.service.ts @@ -72,19 +72,43 @@ const operatorMap = { 'like': '__fuzzy', }; +export interface AcqSearchTerm { + field: string; + op: string; + value1: string; + value2: string; +} + @Injectable() export class AcqSearchService { + _terms: AcqSearchTerm[] = []; + constructor( private net: NetService, private auth: AuthService ) { } + setSearchTerms(terms: AcqSearchTerm[]) { + this._terms = terms; + } + generateAcqSearch(searchType, filters): any { const baseSearch = JSON.parse(JSON.stringify(defaultSearch[searchType])); // deep copy const coreRecType = Object.keys(defaultSearch[searchType])[0]; + // handle supplied search terms + this._terms.forEach(term => { + const searchTerm: Object = {}; + const searchField = term.field.split(':')[1]; + searchTerm[searchField] = term.value1; + if (term.op !== '') { + searchTerm[term.op] = true; + } + baseSearch[coreRecType].push(searchTerm); + }); + // handle grid filters // note that date filters coming from the grid do not need // to worry about __castdate because the grid filter supplies diff --git a/Open-ILS/src/eg2/src/app/staff/acq/search/purchase-order-results.component.ts b/Open-ILS/src/eg2/src/app/staff/acq/search/purchase-order-results.component.ts index 3d688c68ca..9c9725f191 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/search/purchase-order-results.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/acq/search/purchase-order-results.component.ts @@ -8,7 +8,7 @@ import {NetService} from '@eg/core/net.service'; import {AuthService} from '@eg/core/auth.service'; import {GridComponent} from '@eg/share/grid/grid.component'; import {GridDataSource} from '@eg/share/grid/grid'; -import {AcqSearchService} from './acq-search.service'; +import {AcqSearchService, AcqSearchTerm} from './acq-search.service'; @Component({ selector: 'eg-purchase-order-results', @@ -32,4 +32,8 @@ export class PurchaseOrderResultsComponent implements OnInit { this.gridSource = this.acqSearch.getAcqSearchDataSource('purchase_order'); } + doSearch(terms: AcqSearchTerm[]) { + this.acqSearch.setSearchTerms(terms); + this.purchaseOrderResultsGrid.reload(); + } } -- 2.11.0