From 9e60c40466aedce44b12e1686fad13eda2fb7fe1 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 5 Feb 2021 14:58:55 -0500 Subject: [PATCH] LP1904036 Patron ui checkout tab; noncats Signed-off-by: Bill Erickson Signed-off-by: Jane Sandberg Signed-off-by: Galen Charlton --- .../app/staff/circ/patron/checkout.component.html | 43 ++++++++++- .../app/staff/circ/patron/checkout.component.ts | 75 ++++++++++++++++++- .../eg2/src/app/staff/circ/patron/patron.module.ts | 2 + Open-ILS/src/eg2/src/app/staff/nav.component.html | 4 ++ .../eg2/src/app/staff/share/circ/circ.module.ts | 20 ++++++ .../eg2/src/app/staff/share/circ/circ.service.ts | 84 ++++++++++++++++++++++ Open-ILS/src/templates/staff/navbar.tt2 | 6 ++ 7 files changed, 232 insertions(+), 2 deletions(-) create mode 100644 Open-ILS/src/eg2/src/app/staff/share/circ/circ.module.ts create mode 100644 Open-ILS/src/eg2/src/app/staff/share/circ/circ.service.ts diff --git a/Open-ILS/src/eg2/src/app/staff/circ/patron/checkout.component.html b/Open-ILS/src/eg2/src/app/staff/circ/patron/checkout.component.html index d6add2b645..dea9023a5c 100644 --- a/Open-ILS/src/eg2/src/app/staff/circ/patron/checkout.component.html +++ b/Open-ILS/src/eg2/src/app/staff/circ/patron/checkout.component.html @@ -1,2 +1,43 @@ -CHECKOUT + + + +
+
+
+
+
+
+ +
+ + + + + +
+
+
+ +
+ +
+
+
+
+ here +
+
+
diff --git a/Open-ILS/src/eg2/src/app/staff/circ/patron/checkout.component.ts b/Open-ILS/src/eg2/src/app/staff/circ/patron/checkout.component.ts index e300bbe94e..a372f144f8 100644 --- a/Open-ILS/src/eg2/src/app/staff/circ/patron/checkout.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/circ/patron/checkout.component.ts @@ -1,10 +1,15 @@ -import {Component, OnInit, Input} from '@angular/core'; +import {Component, OnInit, AfterViewInit, Input, ViewChild} from '@angular/core'; import {Router, ActivatedRoute, ParamMap} from '@angular/router'; +import {Observable, empty, of} from 'rxjs'; +import {tap, switchMap} from 'rxjs/operators'; import {NgbNav, NgbNavChangeEvent} from '@ng-bootstrap/ng-bootstrap'; +import {IdlObject} from '@eg/core/idl.service'; import {OrgService} from '@eg/core/org.service'; import {NetService} from '@eg/core/net.service'; import {PatronService} from '@eg/staff/share/patron/patron.service'; import {PatronManagerService} from './patron.service'; +import {CheckoutParams, CheckoutResult, CircService} from '@eg/staff/share/circ/circ.service'; +import {PromptDialogComponent} from '@eg/share/dialog/prompt.component'; @Component({ templateUrl: 'checkout.component.html', @@ -12,14 +17,82 @@ import {PatronManagerService} from './patron.service'; }) export class CheckoutComponent implements OnInit { + maxNoncats = 99; // Matches AngJS version + checkoutNoncat: IdlObject = null; + + @ViewChild('nonCatCount') nonCatCount: PromptDialogComponent; + constructor( private org: OrgService, private net: NetService, + public circ: CircService, public patronService: PatronService, public context: PatronManagerService ) {} ngOnInit() { + this.circ.getNonCatTypes(); + } + + ngAfterViewInit() { + const input = document.getElementById('barcode-input'); + if (input) { input.focus(); } + } + + collectParams(): Promise { + + const params: CheckoutParams = { + patron_id: this.context.patron.id() + }; + + if (this.checkoutNoncat) { + + return this.noncatPrompt().toPromise().then(count => { + if (!count) { return null; } + params.noncat = true; + params.noncat_count = count; + params.noncat_type = this.checkoutNoncat.id(); + return params; + }); + } + + return null; + } + + checkout() { + this.collectParams() + + .then((params: CheckoutParams) => { + if (!params) { return null; } + return this.circ.checkout(params); + }) + + .then((result: CheckoutResult) => { + if (!result) { return null; } + + // Reset the form + this.checkoutNoncat = null; + }); + } + + noncatPrompt(): Observable { + return this.nonCatCount.open() + .pipe(switchMap(count => { + + if (count === null || count === undefined) { + return empty(); // dialog canceled + } + + // Even though the prompt has a type and min/max values, + // users can still manually enter bogus values. + count = Number(count); + if (count > 0 && count < this.maxNoncats) { + return of(count); + } else { + // Bogus value. Try again + return this.noncatPrompt(); + } + })); } } diff --git a/Open-ILS/src/eg2/src/app/staff/circ/patron/patron.module.ts b/Open-ILS/src/eg2/src/app/staff/circ/patron/patron.module.ts index a46313dbd1..36e042935b 100644 --- a/Open-ILS/src/eg2/src/app/staff/circ/patron/patron.module.ts +++ b/Open-ILS/src/eg2/src/app/staff/circ/patron/patron.module.ts @@ -3,6 +3,7 @@ import {PatronRoutingModule} from './routing.module'; import {FmRecordEditorModule} from '@eg/share/fm-editor/fm-editor.module'; import {StaffCommonModule} from '@eg/staff/common.module'; import {HoldsModule} from '@eg/staff/share/holds/holds.module'; +import {CircModule} from '@eg/staff/share/circ/circ.module'; import {HoldingsModule} from '@eg/staff/share/holdings/holdings.module'; import {BookingModule} from '@eg/staff/share/booking/booking.module'; import {PatronModule} from '@eg/staff/share/patron/patron.module'; @@ -28,6 +29,7 @@ import {BcSearchComponent} from './bcsearch.component'; imports: [ StaffCommonModule, FmRecordEditorModule, + CircModule, HoldsModule, HoldingsModule, BookingModule, diff --git a/Open-ILS/src/eg2/src/app/staff/nav.component.html b/Open-ILS/src/eg2/src/app/staff/nav.component.html index d707d3f0d2..24b027f5c0 100644 --- a/Open-ILS/src/eg2/src/app/staff/nav.component.html +++ b/Open-ILS/src/eg2/src/app/staff/nav.component.html @@ -23,6 +23,10 @@ Search for Patrons + + + Search for Patrons (Experimental) + Search for Items by Barcode diff --git a/Open-ILS/src/eg2/src/app/staff/share/circ/circ.module.ts b/Open-ILS/src/eg2/src/app/staff/share/circ/circ.module.ts new file mode 100644 index 0000000000..907a85d42a --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/share/circ/circ.module.ts @@ -0,0 +1,20 @@ +import {NgModule} from '@angular/core'; +import {StaffCommonModule} from '@eg/staff/common.module'; +import {HoldingsModule} from '@eg/staff/share/holdings/holdings.module'; +import {CircService} from './circ.service'; + +@NgModule({ + declarations: [ + ], + imports: [ + StaffCommonModule, + HoldingsModule + ], + exports: [ + ], + providers: [ + CircService + ] +}) + +export class CircModule {} diff --git a/Open-ILS/src/eg2/src/app/staff/share/circ/circ.service.ts b/Open-ILS/src/eg2/src/app/staff/share/circ/circ.service.ts new file mode 100644 index 0000000000..f3ab34a4fb --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/share/circ/circ.service.ts @@ -0,0 +1,84 @@ +import {Injectable} from '@angular/core'; +import {Observable} from 'rxjs'; +import {map, mergeMap} from 'rxjs/operators'; +import {IdlObject} from '@eg/core/idl.service'; +import {NetService} from '@eg/core/net.service'; +import {OrgService} from '@eg/core/org.service'; +import {PcrudService} from '@eg/core/pcrud.service'; +import {EventService, EgEvent} from '@eg/core/event.service'; +import {AuthService} from '@eg/core/auth.service'; +import {BibRecordService, BibRecordSummary} from '@eg/share/catalog/bib-record.service'; +import {AudioService} from '@eg/share/util/audio.service'; + + +export interface CheckoutParams { + patron_id: number; + noncat?: boolean; + noncat_type?: number; + noncat_count?: number; +} + +export interface CheckoutResult { + circ?: IdlObject; +} + +@Injectable() +export class CircService { + + nonCatTypes: IdlObject[] = null; + + constructor( + private audio: AudioService, + private evt: EventService, + private org: OrgService, + private net: NetService, + private pcrud: PcrudService, + private auth: AuthService, + private bib: BibRecordService, + ) {} + + getNonCatTypes(): Promise { + + if (this.nonCatTypes) { + return Promise.resolve(this.nonCatTypes); + } + + return this.pcrud.search('cnct', + {owning_lib: this.org.fullPath(this.auth.user().ws_ou(), true)}, + {order_by: {cnct: 'name'}}, + {atomic: true} + ).toPromise().then(types => this.nonCatTypes = types); + } + + checkout(params: CheckoutParams): Promise { + + console.log('checking out with', params); + + return this.net.request( + 'open-ils.circ', + 'open-ils.circ.checkout.full', + this.auth.token(), params + ).toPromise().then(result => this.processCheckoutResult(result)) + } + + processCheckoutResult(response: any): Promise { + console.debug('checkout resturned', response); + + if (Array.isArray(response)) { response = response[0]; } + + const evt = this.evt.parse(response); + const payload = evt.payload; + + if (!payload) { + this.audio.play('error.unknown.no_payload'); + return Promise.reject(); + } + + const result: CheckoutResult = { + circ: payload.circ + }; + + return Promise.resolve(result); + } +} + diff --git a/Open-ILS/src/templates/staff/navbar.tt2 b/Open-ILS/src/templates/staff/navbar.tt2 index b988653e52..5c59dbd934 100644 --- a/Open-ILS/src/templates/staff/navbar.tt2 +++ b/Open-ILS/src/templates/staff/navbar.tt2 @@ -43,6 +43,12 @@
  • + + + [% l('Search for Patrons (Experimental)') %] + +
  • +
  • -- 2.11.0