From 7ca8b6aa11c67ebb9df46e346441a66490cc7e41 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 5 Feb 2021 16:26:03 -0500 Subject: [PATCH] LP1904036 Patron ui checkout tab Signed-off-by: Bill Erickson Signed-off-by: Jane Sandberg Signed-off-by: Galen Charlton --- .../app/staff/circ/patron/checkout.component.html | 29 ++++++++- .../app/staff/circ/patron/checkout.component.ts | 70 +++++++++++++++++++--- .../eg2/src/app/staff/share/circ/circ.service.ts | 18 +++++- 3 files changed, 106 insertions(+), 11 deletions(-) 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 dea9023a5c..c856da3d2b 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,4 +1,6 @@ + +
@@ -41,3 +43,28 @@
+ + + + {{r.title}} + + {{r.title}} + + +
+
+ + + + + +
+
+ + + + 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 a372f144f8..9a278a2487 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,6 +1,6 @@ import {Component, OnInit, AfterViewInit, Input, ViewChild} from '@angular/core'; import {Router, ActivatedRoute, ParamMap} from '@angular/router'; -import {Observable, empty, of} from 'rxjs'; +import {Observable, empty, of, from} from 'rxjs'; import {tap, switchMap} from 'rxjs/operators'; import {NgbNav, NgbNavChangeEvent} from '@ng-bootstrap/ng-bootstrap'; import {IdlObject} from '@eg/core/idl.service'; @@ -10,6 +10,15 @@ 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'; +import {GridDataSource, GridColumn, GridCellTextGenerator} from '@eg/share/grid/grid'; +import {GridComponent} from '@eg/share/grid/grid.component'; +import {Pager} from '@eg/share/util/pager'; + +interface CircGridEntry { + title?: string; + circ?: IdlObject; + copyAlertCount: number; +} @Component({ templateUrl: 'checkout.component.html', @@ -19,8 +28,13 @@ export class CheckoutComponent implements OnInit { maxNoncats = 99; // Matches AngJS version checkoutNoncat: IdlObject = null; + checkoutBarcode = ''; + checkouts: CircGridEntry[] = []; + gridDataSource: GridDataSource = new GridDataSource(); + cellTextGenerator: GridCellTextGenerator; @ViewChild('nonCatCount') nonCatCount: PromptDialogComponent; + @ViewChild('checkoutsGrid') checkoutsGrid: GridComponent; constructor( private org: OrgService, @@ -32,9 +46,21 @@ export class CheckoutComponent implements OnInit { ngOnInit() { this.circ.getNonCatTypes(); + + this.gridDataSource.getRows = (pager: Pager, sort: any[]) => { + return from(this.checkouts); + }; + + this.cellTextGenerator = { + title: row => row.title + }; } ngAfterViewInit() { + this.focusInput(); + } + + focusInput() { const input = document.getElementById('barcode-input'); if (input) { input.focus(); } } @@ -54,27 +80,55 @@ export class CheckoutComponent implements OnInit { params.noncat_type = this.checkoutNoncat.id(); return params; }); + } else if (this.checkoutBarcode) { + params.copy_barcode = this.checkoutBarcode; + return Promise.resolve(params); } - return null; + return Promise.resolve(null); } checkout() { this.collectParams() .then((params: CheckoutParams) => { - if (!params) { return null; } - return this.circ.checkout(params); + if (params) { + return this.circ.checkout(params); + } }) .then((result: CheckoutResult) => { - if (!result) { return null; } - - // Reset the form - this.checkoutNoncat = null; + if (result) { + if (result.success) { + this.gridifyResult(result); + this.resetForm(); + } + } }); } + resetForm() { + this.checkoutBarcode = ''; + this.checkoutNoncat = null; + this.focusInput(); + } + + gridifyResult(result: CheckoutResult) { + const entry: CircGridEntry = { + circ: result.circ, + copyAlertCount: 0 // TODO + }; + + if (this.checkoutNoncat) { + entry.title = this.checkoutNoncat.name(); + } else if (result.record) { + entry.title = result.record.title(); + } + + this.checkouts.unshift(entry); + this.checkoutsGrid.reload(); + } + noncatPrompt(): Observable { return this.nonCatCount.open() .pipe(switchMap(count => { 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 index f3ab34a4fb..554b77d93b 100644 --- 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 @@ -11,19 +11,28 @@ import {BibRecordService, BibRecordSummary} from '@eg/share/catalog/bib-record.s import {AudioService} from '@eg/share/util/audio.service'; +// API parameter options export interface CheckoutParams { patron_id: number; + copy_id?: number; + copy_barcode?: string; noncat?: boolean; noncat_type?: number; noncat_count?: number; + noop?: boolean; } export interface CheckoutResult { + index: number; + params: CheckoutParams, + success: boolean; circ?: IdlObject; + record?: IdlObject; } @Injectable() export class CircService { + static resultIndex = 0; nonCatTypes: IdlObject[] = null; @@ -58,10 +67,12 @@ export class CircService { 'open-ils.circ', 'open-ils.circ.checkout.full', this.auth.token(), params - ).toPromise().then(result => this.processCheckoutResult(result)) + ).toPromise().then(result => this.processCheckoutResult(params, result)) } - processCheckoutResult(response: any): Promise { + processCheckoutResult( + params: CheckoutParams, response: any): Promise { + console.debug('checkout resturned', response); if (Array.isArray(response)) { response = response[0]; } @@ -75,6 +86,9 @@ export class CircService { } const result: CheckoutResult = { + index: CircService.resultIndex++, + params: params, + success: true, circ: payload.circ }; -- 2.11.0