From 65ef28937dcc92726bd52a34b42887805039ff8f Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 17 Feb 2021 16:26:57 -0500 Subject: [PATCH] LP1904036 Barcode completion dialog Signed-off-by: Bill Erickson Signed-off-by: Jane Sandberg Signed-off-by: Galen Charlton --- .../app/staff/circ/patron/checkout.component.html | 1 + .../app/staff/circ/patron/checkout.component.ts | 15 +++- .../eg2/src/app/staff/circ/patron/patron.module.ts | 4 +- .../share/barcodes/barcode-select.component.html | 31 +++++++++ .../share/barcodes/barcode-select.component.ts | 81 ++++++++++++++++++++++ .../app/staff/share/barcodes/barcodes.module.ts | 19 +++++ .../src/app/staff/share/patron/patron.service.ts | 1 + 7 files changed, 149 insertions(+), 3 deletions(-) create mode 100644 Open-ILS/src/eg2/src/app/staff/share/barcodes/barcode-select.component.html create mode 100644 Open-ILS/src/eg2/src/app/staff/share/barcodes/barcode-select.component.ts create mode 100644 Open-ILS/src/eg2/src/app/staff/share/barcodes/barcodes.module.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 ca96c1d5cc..2e73da29ba 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,5 +1,6 @@ + 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 b4b1fdf8df..27baba530d 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 @@ -18,6 +18,7 @@ import {ServerStoreService} from '@eg/core/server-store.service'; import {PrecatCheckoutDialogComponent} from './precat-dialog.component'; import {AudioService} from '@eg/share/util/audio.service'; import {CopyAlertsDialogComponent} from '@eg/staff/share/holdings/copy-alerts-dialog.component'; +import {BarcodeSelectComponent} from '@eg/staff/share/barcodes/barcode-select.component'; const SESSION_DUE_DATE = 'eg.circ.checkout.is_until_logout'; @@ -45,6 +46,8 @@ export class CheckoutComponent implements OnInit { private precatDialog: PrecatCheckoutDialogComponent; @ViewChild('copyAlertsDialog') private copyAlertsDialog: CopyAlertsDialogComponent; + @ViewChild('barcodeSelect') + private barcodeSelect: BarcodeSelectComponent; constructor( private store: StoreService, @@ -101,9 +104,17 @@ export class CheckoutComponent implements OnInit { } else if (this.checkoutBarcode) { - params.copy_barcode = this.checkoutBarcode; if (this.dueDateOptions > 0) { params.due_date = this.dueDate; } - return Promise.resolve(params); + + return this.barcodeSelect.getBarcode('asset', this.checkoutBarcode) + .then(barcode => { + if (barcode) { + params.copy_barcode = barcode; + return params; + } else { + return null; + } + }); } return Promise.resolve(null); 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 ced4ffcc30..b4403f5188 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 @@ -16,6 +16,7 @@ import {EditComponent} from './edit.component'; import {EditToolbarComponent} from './edit-toolbar.component'; import {BcSearchComponent} from './bcsearch.component'; import {PrecatCheckoutDialogComponent} from './precat-dialog.component'; +import {BarcodesModule} from '@eg/staff/share/barcodes/barcodes.module'; @NgModule({ declarations: [ @@ -36,7 +37,8 @@ import {PrecatCheckoutDialogComponent} from './precat-dialog.component'; HoldingsModule, BookingModule, PatronModule, - PatronRoutingModule + PatronRoutingModule, + BarcodesModule ], providers: [ PatronManagerService diff --git a/Open-ILS/src/eg2/src/app/staff/share/barcodes/barcode-select.component.html b/Open-ILS/src/eg2/src/app/staff/share/barcodes/barcode-select.component.html new file mode 100644 index 0000000000..9081ce8871 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/share/barcodes/barcode-select.component.html @@ -0,0 +1,31 @@ + + + + + + + diff --git a/Open-ILS/src/eg2/src/app/staff/share/barcodes/barcode-select.component.ts b/Open-ILS/src/eg2/src/app/staff/share/barcodes/barcode-select.component.ts new file mode 100644 index 0000000000..53744100d4 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/share/barcodes/barcode-select.component.ts @@ -0,0 +1,81 @@ +import {Component, Input, Output, OnInit, ViewChild} 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 {AuthService} from '@eg/core/auth.service'; +import {PcrudService} from '@eg/core/pcrud.service'; +import {EventService, EgEvent} from '@eg/core/event.service'; +import {NgbModal, NgbModalOptions} from '@ng-bootstrap/ng-bootstrap'; +import {DialogComponent} from '@eg/share/dialog/dialog.component'; + +/* Suppor barcode completion for asset/actor/serial/booking data */ + +@Component({ + selector: 'eg-barcode-select', + templateUrl: './barcode-select.component.html', +}) + +export class BarcodeSelectComponent + extends DialogComponent implements OnInit { + + selectedBarcode: string; + barcodes: string[]; + inputs: {[barcode: string]: boolean}; + + constructor( + private modal: NgbModal, + private evt: EventService, + private org: OrgService, + private net: NetService, + private pcrud: PcrudService, + private auth: AuthService + ) { super(modal); } + + ngOnInit() { + } + + selectionChanged() { + this.selectedBarcode = Object.keys(this.inputs) + .filter(barcode => this.inputs[barcode] === true)[0]; + } + + // Returns promise of barcode + // When multiple barcodes match, the user is asked to select one. + // Returns promise of null if no match is found or the user cancels + // the selection process. + getBarcode(class_: 'asset' | 'actor', barcode: string): Promise { + this.barcodes = []; + this.inputs = {}; + + let promise = this.net.request( + 'open-ils.actor', + 'open-ils.actor.get_barcodes', + this.auth.token(), this.auth.user().ws_ou(), + class_, barcode.trim() + ).toPromise(); + + promise = promise.then(results => { + + if (!results) { return null; } + + results.forEach(result => { + if (!this.evt.parse(result)) { + this.barcodes.push(result.barcode); + } + }); + + if (this.barcodes.length === 0) { + return null; + } else if (this.barcodes.length === 1) { + return this.barcodes[0]; + } else { + return this.open().toPromise(); + } + }); + + return promise; + } +} + diff --git a/Open-ILS/src/eg2/src/app/staff/share/barcodes/barcodes.module.ts b/Open-ILS/src/eg2/src/app/staff/share/barcodes/barcodes.module.ts new file mode 100644 index 0000000000..fba4c836ff --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/share/barcodes/barcodes.module.ts @@ -0,0 +1,19 @@ +import {NgModule} from '@angular/core'; +import {StaffCommonModule} from '@eg/staff/common.module'; +import {BarcodeSelectComponent} from './barcode-select.component'; + +@NgModule({ + declarations: [ + BarcodeSelectComponent + ], + imports: [ + StaffCommonModule + ], + exports: [ + BarcodeSelectComponent + ], + providers: [ + ] +}) + +export class BarcodesModule {} diff --git a/Open-ILS/src/eg2/src/app/staff/share/patron/patron.service.ts b/Open-ILS/src/eg2/src/app/staff/share/patron/patron.service.ts index 5939cca086..9487c68ef1 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/patron/patron.service.ts +++ b/Open-ILS/src/eg2/src/app/staff/share/patron/patron.service.ts @@ -18,6 +18,7 @@ export class PatronService { private auth: AuthService ) {} + // TODO import barcodes.module instead bcSearch(barcode: string): Observable { return this.net.request( 'open-ils.actor', -- 2.11.0