From 51fc80d07ee69c461d544e797a2e5377324936ad Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Fri, 6 Mar 2020 11:44:24 -0500 Subject: [PATCH] more work on hooking up search service and search form TODO: - contact name searching - get the org-family-selector to show the starting value of the WS OU - refactor how form parameters are managed? Signed-off-by: Galen Charlton --- .../acq-provider-search-form.component.html | 18 +++---- .../provider/acq-provider-search-form.component.ts | 55 ++++++++++++++++++---- .../acq/provider/acq-provider-search.service.ts | 13 ++++- .../staff/acq/provider/acq-provider.component.html | 2 +- .../app/staff/acq/provider/acq-provider.module.ts | 4 ++ .../acq/provider/provider-results.component.html | 2 + .../acq/provider/provider-results.component.ts | 49 +++++++++++++++++++ 7 files changed, 122 insertions(+), 21 deletions(-) create mode 100644 Open-ILS/src/eg2/src/app/staff/acq/provider/provider-results.component.ts diff --git a/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider-search-form.component.html b/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider-search-form.component.html index 3ef2995448..1acef426f4 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider-search-form.component.html +++ b/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider-search-form.component.html @@ -2,13 +2,13 @@
- +
- +
- +
@@ -20,13 +20,13 @@
- +
- +
- +
@@ -35,17 +35,17 @@
- +
- +
- +
diff --git a/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider-search-form.component.ts b/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider-search-form.component.ts index 66648f74ab..79f9822481 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider-search-form.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider-search-form.component.ts @@ -1,5 +1,4 @@ -import {Component, OnInit, AfterViewInit, Input, Output, EventEmitter, ViewChild, - OnChanges, SimpleChanges} from '@angular/core'; +import {Component, OnInit, AfterViewInit, Input, Output, EventEmitter, 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'; @@ -7,8 +6,10 @@ import {IdlService, IdlObject} from '@eg/core/idl.service'; import {PcrudService} from '@eg/core/pcrud.service'; import {StringComponent} from '@eg/share/string/string.component'; import {ToastService} from '@eg/share/toast/toast.service'; -import {AcqProviderSearchTerm, AcqProviderSearch} from './acq-provider.service'; +import {AuthService} from '@eg/core/auth.service'; +import {AcqProviderSearchTerm, AcqProviderSearch} from './acq-provider-search.service'; import {ServerStoreService} from '@eg/core/server-store.service'; +import {OrgFamily} from '@eg/share/org-family-select/org-family-select.component'; @Component({ selector: 'eg-acq-provider-search-form', @@ -16,13 +17,13 @@ import {ServerStoreService} from '@eg/core/server-store.service'; templateUrl: './acq-provider-search-form.component.html' }) -export class AcqProviderSearchFormComponent implements OnInit, AfterViewInit, OnChanges { +export class AcqProviderSearchFormComponent implements OnInit, AfterViewInit { @Output() searchSubmitted = new EventEmitter(); providerName = ''; providerCode = ''; - providerOwners = []; + providerOwners: OrgFamily; contactName = ''; providerEmail = ''; providerPhone = ''; @@ -39,11 +40,12 @@ export class AcqProviderSearchFormComponent implements OnInit, AfterViewInit, On private store: ServerStoreService, private idl: IdlService, private toast: ToastService, + private auth: AuthService, ) {} ngOnInit() { const self = this; - + this.providerOwners = {primaryOrgId: this.auth.user().ws_ou(), includeDescendants: true}; } ngAfterViewInit() {} @@ -51,7 +53,7 @@ export class AcqProviderSearchFormComponent implements OnInit, AfterViewInit, On clearSearch() { this.providerName = ''; this.providerCode = ''; - this.providerOwners = []; + this.providerOwners = {primaryOrgId: this.auth.user().ws_ou(), includeDescendants: true}; this.contactName = ''; this.providerEmail = ''; this.providerPhone = ''; @@ -63,12 +65,47 @@ export class AcqProviderSearchFormComponent implements OnInit, AfterViewInit, On } submitSearch() { + + const searchTerms: AcqProviderSearchTerm[] = []; + if (this.providerName) { + searchTerms.push({ field: 'name', op: 'ilike', value: this.providerName }); + } + if (this.providerCode) { + searchTerms.push({ field: 'code', op: 'ilike', value: this.providerCode }); + } + if (this.providerOwners) { + searchTerms.push({ field: 'owner', op: 'in', value: this.providerOwners.orgIds }); + } + if (this.contactName) { + // TODO + } + if (this.providerEmail) { + searchTerms.push({ field: 'email', op: 'ilike', value: this.providerEmail }); + } + if (this.providerPhone) { + searchTerms.push({ field: 'phone', op: 'ilike', value: this.providerPhone }); + } + if (this.providerCurrencyType) { + searchTerms.push({ field: 'currency_type', op: 'ilike', value: this.providerCurrencyType }); + } + if (this.providerSAN) { + searchTerms.push({ field: 'san', op: 'ilike', value: this.providerSAN }); + } + if (this.providerEDIDefault) { + searchTerms.push({ field: 'edi_default', op: '=', value: this.providerEDIDefault }); + } + if (this.providerURL) { + searchTerms.push({ field: 'url', op: 'ilike', value: this.providerURL }); + } + if (this.providerIsActive) { + searchTerms.push({ field: 'active', op: '=', value: (this.providerIsActive ? 't' : 'f') }); + } + // tossing setTimeout here to ensure that the // grid data source is fully initialized setTimeout(() => { this.searchSubmitted.emit({ - terms: this.searchTerms, - conjunction: this.searchConjunction + terms: searchTerms, }); }); } diff --git a/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider-search.service.ts b/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider-search.service.ts index 21559839c5..295f2c1051 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider-search.service.ts +++ b/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider-search.service.ts @@ -9,7 +9,8 @@ import {EventService} from '@eg/core/event.service'; export interface AcqProviderSearchTerm { field: string; - value: string; + op: string; + value: any; } export interface AcqProviderSearch { @@ -48,7 +49,15 @@ export class AcqProviderSearchService { } const query_part = new Object(); - query_part[term.field] = { '=' : term.value }; + + query_part[term.field] = {}; + let op = term.op; + if (!op) { op = '=' }; // just in case + let val = term.value; + if (op === 'ilike') { + val = '%' + val + '%'; + } + query_part[term.field][op] = val; query.push(query_part); }); diff --git a/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider.component.html b/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider.component.html index f826482fa1..84a2c3fb2f 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider.component.html +++ b/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider.component.html @@ -10,7 +10,7 @@ PROVIDER DETAILS TAB
- PROVIDER SEARCH FORM +
diff --git a/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider.module.ts b/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider.module.ts index e20d667c2b..e4641f4fe8 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider.module.ts +++ b/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider.module.ts @@ -3,14 +3,18 @@ import {StaffCommonModule} from '@eg/staff/common.module'; import {AcqProviderRoutingModule} from './routing.module'; import {AcqProviderComponent} from './acq-provider.component'; import {AcqProviderSearchFormComponent} from './acq-provider-search-form.component'; +import {ProviderResultsComponent} from './provider-results.component'; +import {OrgFamilySelectModule} from '@eg/share/org-family-select/org-family-select.module'; @NgModule({ declarations: [ AcqProviderComponent, AcqProviderSearchFormComponent, + ProviderResultsComponent ], imports: [ StaffCommonModule, + OrgFamilySelectModule, AcqProviderRoutingModule ] }) diff --git a/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-results.component.html b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-results.component.html index 127b7a56ce..f89149ac9f 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-results.component.html +++ b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-results.component.html @@ -1,3 +1,5 @@ + +
  • {{c.name()}}
  • diff --git a/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-results.component.ts b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-results.component.ts new file mode 100644 index 0000000000..206d4898f6 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-results.component.ts @@ -0,0 +1,49 @@ +import {Component, OnInit, Input, ViewChild} from '@angular/core'; +import {Observable} from 'rxjs'; +import {map} from 'rxjs/operators'; +import {Router, ActivatedRoute, ParamMap} from '@angular/router'; +import {Pager} from '@eg/share/util/pager'; +import {IdlObject} from '@eg/core/idl.service'; +import {NetService} from '@eg/core/net.service'; +import {AuthService} from '@eg/core/auth.service'; +import {GridComponent} from '@eg/share/grid/grid.component'; +import {GridDataSource, GridCellTextGenerator} from '@eg/share/grid/grid'; +import {AcqProviderSearchService, AcqProviderSearchTerm, AcqProviderSearch} from './acq-provider-search.service'; +import {AcqProviderSearchFormComponent} from './acq-provider-search-form.component'; + +@Component({ + selector: 'eg-provider-results', + templateUrl: 'provider-results.component.html', + providers: [AcqProviderSearchService] +}) +export class ProviderResultsComponent implements OnInit { + + gridSource: GridDataSource; + @ViewChild('acqSearchProviderGrid', { static: true }) providerResultsGrid: GridComponent; + + cellTextGenerator: GridCellTextGenerator; + + constructor( + private router: Router, + private route: ActivatedRoute, + private net: NetService, + private auth: AuthService, + private providerSearch: AcqProviderSearchService) { + } + + ngOnInit() { + this.gridSource = this.providerSearch.getDataSource(); + + this.cellTextGenerator = { + provider: row => row.provider().code(), + name: row => row.name(), + }; + } + + doSearch(search: AcqProviderSearch) { + setTimeout(() => { + this.providerSearch.setSearch(search); + this.providerResultsGrid.reload(); + }); + } +} -- 2.11.0