From 57d3c055ec6213a760354bfd02ec91f6c54321ae Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Fri, 17 Jan 2020 17:47:42 -0500 Subject: [PATCH] refactor the search form into a separate component This enables including the form *in* the tab and simplifies initializing the form during a tab change. Signed-off-by: Galen Charlton --- .../acq/search/acq-search-form.component.html | 53 ++++++++++++ .../staff/acq/search/acq-search-form.component.ts | 98 ++++++++++++++++++++++ .../app/staff/acq/search/acq-search.component.html | 55 ------------ .../app/staff/acq/search/acq-search.component.ts | 83 ------------------ .../src/app/staff/acq/search/acq-search.module.ts | 2 + .../acq/search/invoice-results.component.html | 2 + .../staff/acq/search/invoice-results.component.ts | 1 + .../acq/search/lineitem-results.component.html | 2 + .../staff/acq/search/lineitem-results.component.ts | 1 + .../acq/search/picklist-results.component.html | 2 + .../staff/acq/search/picklist-results.component.ts | 1 + .../search/purchase-order-results.component.html | 2 + .../acq/search/purchase-order-results.component.ts | 1 + 13 files changed, 165 insertions(+), 138 deletions(-) create mode 100644 Open-ILS/src/eg2/src/app/staff/acq/search/acq-search-form.component.html create mode 100644 Open-ILS/src/eg2/src/app/staff/acq/search/acq-search-form.component.ts diff --git a/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search-form.component.html b/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search-form.component.html new file mode 100644 index 0000000000..14f2e7ad5b --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search-form.component.html @@ -0,0 +1,53 @@ +
+
+ +
+
+ +
+
+ + + + + + + + + + + + + + + +
+
+
+
+ +
+
+ +
+
diff --git a/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search-form.component.ts b/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search-form.component.ts new file mode 100644 index 0000000000..36a50fb937 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search-form.component.ts @@ -0,0 +1,98 @@ +import {Component, OnInit, AfterViewInit, 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'; +import {IdlService, IdlObject} from '@eg/core/idl.service'; +import {PcrudService} from '@eg/core/pcrud.service'; +import {AcqSearchTerm} from './acq-search.service'; + +@Component({ + selector: 'eg-acq-search-form', + templateUrl: './acq-search-form.component.html' +}) + +export class AcqSearchFormComponent implements OnInit, AfterViewInit { + + @Output() searchSubmitted = new EventEmitter(); + + hints = ['jub', 'acqpl', 'acqpo', 'acqinv', 'acqlid']; + availableSearchFields = {}; + searchTermDatatypes = {}; + searchFieldLinkedClasses = {}; + validSearchTypes = ['lineitems', 'purchaseorders', 'invoices', 'selectionlists']; + defaultSearchType = 'lineitems'; + + searchTerms: AcqSearchTerm[] = []; + + constructor( + private router: Router, + private route: ActivatedRoute, + private pcrud: PcrudService, + private idl: IdlService, + ) {} + + ngOnInit() { + const self = this; + + this.hints.forEach( + function(hint) { + const 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; + if (field.datatype === 'link') { + self.searchFieldLinkedClasses[hint + ':' + field.name] = field.class; + } + } + } + ); + self.availableSearchFields[hint] = o; + } + ); + + this.hints.push('acqlia'); + this.availableSearchFields['acqlia'] = {'__label': this.idl.classes.acqlia.label, '__fields': []}; + this.pcrud.retrieveAll('acqliad', {'order_by': {'acqliad': 'id'}}) + .subscribe(liad => { + 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: '' }); + } + clearSearchTerm(term: AcqSearchTerm) { + term.value1 = ''; + term.value2 = ''; + term.is_date = false; + } + + setOrgUnitSearchValue(org: IdlObject, term: AcqSearchTerm) { + if (org == null) { + term.value1 = ''; + } else { + term.value1 = org.id(); + } + } + + submitSearch() { + this.searchSubmitted.emit(this.searchTerms); + } +} 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 fb1dc7c5e3..d1d43eeb9e 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,61 +4,6 @@ -
-
- -
-
- -
-
- - - - - - - - - - - - - - - -
-
-
-
- -
-
- -
-
-
-
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 2c40c5a0f8..8e3546d6b0 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 @@ -16,10 +16,6 @@ import {PicklistResultsComponent} from './picklist-results.component'; export class AcqSearchComponent implements OnInit, AfterViewInit { - hints = ['jub', 'acqpl', 'acqpo', 'acqinv', 'acqlid']; - availableSearchFields = {}; - searchTermDatatypes = {}; - searchFieldLinkedClasses = {}; searchType = ''; validSearchTypes = ['lineitems', 'purchaseorders', 'invoices', 'selectionlists']; defaultSearchType = 'lineitems'; @@ -57,90 +53,11 @@ export class AcqSearchComponent implements OnInit, AfterViewInit { this.onTabChange = ($event) => { if (this.validSearchTypes.includes($event.nextId)) { this.searchType = $event.nextId; - // clear search form upon tab change - this.searchTerms = []; - this.addSearchTerm(); this.router.navigate(['/staff', 'acq', 'search', $event.nextId]); } }; - - this.hints.forEach( - function(hint) { - const 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; - if (field.datatype === 'link') { - self.searchFieldLinkedClasses[hint + ':' + field.name] = field.class; - } - } - } - ); - self.availableSearchFields[hint] = o; - } - ); - - this.hints.push('acqlia'); - this.availableSearchFields['acqlia'] = {'__label': this.idl.classes.acqlia.label, '__fields': []}; - this.pcrud.retrieveAll('acqliad', {'order_by': {'acqliad': 'id'}}) - .subscribe(liad => { - 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: '' }); - } - clearSearchTerm(term: AcqSearchTerm) { - term.value1 = ''; - term.value2 = ''; - term.is_date = false; - } - - setOrgUnitSearchValue(org: IdlObject, term: AcqSearchTerm) { - if (org == null) { - term.value1 = ''; - } else { - term.value1 = org.id(); - } - } - - submitSearch() { - switch (this.searchType) { - case 'lineitems': { - this.liResults.forEach(results => results.doSearch(this.searchTerms)); - break; - } - case 'purchaseorders': { - this.poResults.forEach(results => results.doSearch(this.searchTerms)); - break; - } - case 'invoices': { - this.invResults.forEach(results => results.doSearch(this.searchTerms)); - break; - } - case 'selectionlists': { - this.plResults.forEach(results => results.doSearch(this.searchTerms)); - break; - } - } - } - } diff --git a/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search.module.ts b/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search.module.ts index 47124a42d0..4dc22517f1 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search.module.ts +++ b/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search.module.ts @@ -2,6 +2,7 @@ import {NgModule} from '@angular/core'; import {StaffCommonModule} from '@eg/staff/common.module'; import {AcqSearchRoutingModule} from './routing.module'; import {AcqSearchComponent} from './acq-search.component'; +import {AcqSearchFormComponent} from './acq-search-form.component'; import {LineitemResultsComponent} from './lineitem-results.component'; import {PurchaseOrderResultsComponent} from './purchase-order-results.component'; import {InvoiceResultsComponent} from './invoice-results.component'; @@ -14,6 +15,7 @@ import {PicklistMergeDialogComponent} from './picklist-merge-dialog.component'; @NgModule({ declarations: [ AcqSearchComponent, + AcqSearchFormComponent, LineitemResultsComponent, PurchaseOrderResultsComponent, InvoiceResultsComponent, diff --git a/Open-ILS/src/eg2/src/app/staff/acq/search/invoice-results.component.html b/Open-ILS/src/eg2/src/app/staff/acq/search/invoice-results.component.html index 2bd346bf22..cb15329a8b 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/search/invoice-results.component.html +++ b/Open-ILS/src/eg2/src/app/staff/acq/search/invoice-results.component.html @@ -1,3 +1,5 @@ + + diff --git a/Open-ILS/src/eg2/src/app/staff/acq/search/invoice-results.component.ts b/Open-ILS/src/eg2/src/app/staff/acq/search/invoice-results.component.ts index 195f89976c..e3396d6285 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/search/invoice-results.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/acq/search/invoice-results.component.ts @@ -12,6 +12,7 @@ import {AuthService} from '@eg/core/auth.service'; import {GridComponent} from '@eg/share/grid/grid.component'; import {GridDataSource} from '@eg/share/grid/grid'; import {AcqSearchService, AcqSearchTerm} from './acq-search.service'; +import {AcqSearchFormComponent} from './acq-search-form.component'; @Component({ selector: 'eg-invoice-results', diff --git a/Open-ILS/src/eg2/src/app/staff/acq/search/lineitem-results.component.html b/Open-ILS/src/eg2/src/app/staff/acq/search/lineitem-results.component.html index f3a64166f6..e1b222fc18 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/search/lineitem-results.component.html +++ b/Open-ILS/src/eg2/src/app/staff/acq/search/lineitem-results.component.html @@ -1,3 +1,5 @@ + + diff --git a/Open-ILS/src/eg2/src/app/staff/acq/search/lineitem-results.component.ts b/Open-ILS/src/eg2/src/app/staff/acq/search/lineitem-results.component.ts index 9f2e55d978..1a611968ae 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/search/lineitem-results.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/acq/search/lineitem-results.component.ts @@ -9,6 +9,7 @@ import {AuthService} from '@eg/core/auth.service'; import {GridComponent} from '@eg/share/grid/grid.component'; import {GridDataSource} from '@eg/share/grid/grid'; import {AcqSearchService, AcqSearchTerm} from './acq-search.service'; +import {AcqSearchFormComponent} from './acq-search-form.component'; @Component({ selector: 'eg-lineitem-results', diff --git a/Open-ILS/src/eg2/src/app/staff/acq/search/picklist-results.component.html b/Open-ILS/src/eg2/src/app/staff/acq/search/picklist-results.component.html index 97426537ff..4d9cdc9105 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/search/picklist-results.component.html +++ b/Open-ILS/src/eg2/src/app/staff/acq/search/picklist-results.component.html @@ -1,3 +1,5 @@ + + diff --git a/Open-ILS/src/eg2/src/app/staff/acq/search/picklist-results.component.ts b/Open-ILS/src/eg2/src/app/staff/acq/search/picklist-results.component.ts index c13d8381ef..77454864e7 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/search/picklist-results.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/acq/search/picklist-results.component.ts @@ -16,6 +16,7 @@ import {PicklistCreateDialogComponent} from './picklist-create-dialog.component' import {PicklistCloneDialogComponent} from './picklist-clone-dialog.component'; import {PicklistDeleteDialogComponent} from './picklist-delete-dialog.component'; import {PicklistMergeDialogComponent} from './picklist-merge-dialog.component'; +import {AcqSearchFormComponent} from './acq-search-form.component'; @Component({ selector: 'eg-picklist-results', diff --git a/Open-ILS/src/eg2/src/app/staff/acq/search/purchase-order-results.component.html b/Open-ILS/src/eg2/src/app/staff/acq/search/purchase-order-results.component.html index 5393ffa1aa..4ceda8a4ff 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/search/purchase-order-results.component.html +++ b/Open-ILS/src/eg2/src/app/staff/acq/search/purchase-order-results.component.html @@ -1,3 +1,5 @@ + + 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 9c9725f191..5861da6f2e 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 @@ -9,6 +9,7 @@ import {AuthService} from '@eg/core/auth.service'; import {GridComponent} from '@eg/share/grid/grid.component'; import {GridDataSource} from '@eg/share/grid/grid'; import {AcqSearchService, AcqSearchTerm} from './acq-search.service'; +import {AcqSearchFormComponent} from './acq-search-form.component'; @Component({ selector: 'eg-purchase-order-results', -- 2.11.0