From 5c2aeab40d35b1ea7c11ab5cb33ca0edc7d6ab3e Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 9 Jan 2020 18:13:12 -0500 Subject: [PATCH] LPXXX Angular patron search component Signed-off-by: Bill Erickson --- .../app/staff/share/patron/search.component.html | 49 ++++++++-- .../src/app/staff/share/patron/search.component.ts | 102 ++++++++++++++------- 2 files changed, 111 insertions(+), 40 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/staff/share/patron/search.component.html b/Open-ILS/src/eg2/src/app/staff/share/patron/search.component.html index 919ecb020d..18d64c957b 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/patron/search.component.html +++ b/Open-ILS/src/eg2/src/app/staff/share/patron/search.component.html @@ -5,16 +5,31 @@
+ [(ngModel)]="search.family_name"/>
-
-
-
- + +
+
+ +
+
+ +
+
+
@@ -56,9 +71,10 @@ - - - + + + + @@ -73,5 +89,20 @@ [sortable]="true" [multiSortable]="true"> + + + + + + + + + + + + + + + diff --git a/Open-ILS/src/eg2/src/app/staff/share/patron/search.component.ts b/Open-ILS/src/eg2/src/app/staff/share/patron/search.component.ts index b884dc2516..dba36c3274 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/patron/search.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/share/patron/search.component.ts @@ -1,7 +1,8 @@ import {Component, Input, Output, OnInit, AfterViewInit, EventEmitter, ViewChild, Renderer2} from '@angular/core'; import {Observable, of} from 'rxjs'; -import {IdlService} from '@eg/core/idl.service'; +import {map} from 'rxjs/operators'; +import {IdlService, IdlObject} from '@eg/core/idl.service'; import {EventService} from '@eg/core/event.service'; import {NetService} from '@eg/core/net.service'; import {AuthService} from '@eg/core/auth.service'; @@ -14,6 +15,19 @@ import {GridComponent} from '@eg/share/grid/grid.component'; import {GridDataSource} from '@eg/share/grid/grid'; import {Pager} from '@eg/share/util/pager'; +const DEFAULT_SORT = [ + "family_name ASC", + "first_given_name ASC", + "second_given_name ASC", + "dob DESC" +]; + +const DEFAULT_FLESH = [ + "card", "settings", "standing_penalties", "addresses", "billing_address", + "mailing_address", "stat_cat_entries", "waiver_entries", "usr_activity", + "notes", "profile" +]; + @Component({ selector: 'eg-patron-search', templateUrl: './search.component.html' @@ -24,25 +38,7 @@ export class PatronSearchComponent implements OnInit, AfterViewInit { @ViewChild('searchGrid', {static: false}) searchGrid: GridComponent; @Output() patronsSelected: EventEmitter; - search = { - au: {}, - aua: {}, - include_inactive: false - }; - - searchSort = [ - "family_name ASC", - "first_given_name ASC", - "second_given_name ASC", - "dob DESC" - ]; - - searchFlesh = [ - "card", "settings", "standing_penalties", "addresses", - "billing_address", "mailing_address", "stat_cat_entries", - "waiver_entries", "usr_activity", "notes", "profile" - ]; - + search: any = {}; dataSource: GridDataSource; constructor( @@ -69,27 +65,39 @@ export class PatronSearchComponent implements OnInit, AfterViewInit { this.patronsSelected.emit(rows); } + go() { + this.searchGrid.reload(); + } + getRows(pager: Pager, sort: any[]): Observable { const search = this.compileSearch(); if (!search) { return of(); } + const sorter = this.compileSort(sort); + return this.net.request( 'open-ils.actor', 'open-ils.actor.patron.search.advanced.fleshed', this.auth.token(), this.compileSearch(), pager.limit, - this.searchSort, - null, // todo? + sorter, + null, // ? this.auth.user().ws_ou(), - this.searchFlesh, + DEFAULT_FLESH, pager.offset - ); + ).pipe(map(user => this.localFleshUser(user))); } - isValue(val: any): boolean { - return (val !== null && val !== undefined && val !== ''); + localFleshUser(user: IdlObject): IdlObject { + user.home_ou(this.org.get(user.home_ou())); + return user; + } + + compileSort(sort: any[]): string[] { + if (!sort || sort.length === 0) { return DEFAULT_SORT; } + return sort.map(def => `${def.name} ${def.dir}`); } compileSearch(): any { @@ -97,19 +105,51 @@ export class PatronSearchComponent implements OnInit, AfterViewInit { let hasSearch = false; const search: Object = {}; - Object.keys(this.search.au).forEach(field => { - const val = this.search.au[field]; + Object.keys(this.search).forEach(field => { + const val = this.search[field]; + if (this.isValue(val)) { hasSearch = true; - search[field] = {value: val, group: 0} + search[field] = this.mapSearchField(field, val); } + }); return hasSearch ? search : null; } - performSearch() { - this.searchGrid.reload(); + isValue(val: any): boolean { + return (val !== null && val !== undefined && val !== ''); + } + + mapSearchField(field: string, value: any): any { + + const chunk = {value: value, group: 0}; + + switch (field) { + case 'name': + delete chunk.group; + break; + + case 'phone': // thunk + case 'ident': + chunk.group = 2; + break; + + case 'street1': + case 'street2': + case 'city': + case 'state': + case 'post_code': + chunk.group = 1; + break; + + case 'card': + chunk.group = 3; + break; + } + + return chunk; } } -- 2.11.0