From: Bill Erickson Date: Fri, 24 Jun 2022 14:19:49 +0000 (-0400) Subject: LP1840773 SCKO Angular X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=a27ae72c7edbd638f5440846bad9776268071cd7;p=working%2FEvergreen.git LP1840773 SCKO Angular Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/eg2/src/app/scko/banner.component.ts b/Open-ILS/src/eg2/src/app/scko/banner.component.ts index a5e3062114..9a6a39cda3 100644 --- a/Open-ILS/src/eg2/src/app/scko/banner.component.ts +++ b/Open-ILS/src/eg2/src/app/scko/banner.component.ts @@ -118,6 +118,7 @@ export class SckoBannerComponent implements OnInit { submitItemBarcode() { this.scko.resetPatronTimeout(); + this.scko.checkout(this.itemBarcode); } } diff --git a/Open-ILS/src/eg2/src/app/scko/fines.component.ts b/Open-ILS/src/eg2/src/app/scko/fines.component.ts index 373f41596b..f13bda7615 100644 --- a/Open-ILS/src/eg2/src/app/scko/fines.component.ts +++ b/Open-ILS/src/eg2/src/app/scko/fines.component.ts @@ -55,7 +55,7 @@ export class SckoFinesComponent implements OnInit { }, select: {bre : ['id']} } - ).pipe(tap(xact => this.xacts.push(xact))) + ).pipe(tap(xact => this.xacts.push(xact))); })).toPromise(); } @@ -78,7 +78,7 @@ export class SckoFinesComponent implements OnInit { } getDetails(xact: IdlObject): string { - if (xact.summary().xact_type() == 'circulation') { + if (xact.summary().xact_type() === 'circulation') { return this.getTitle(xact); } else { return xact.summary().last_billing_type(); diff --git a/Open-ILS/src/eg2/src/app/scko/scko.component.ts b/Open-ILS/src/eg2/src/app/scko/scko.component.ts index 4e21ebb5aa..7da2bcf835 100644 --- a/Open-ILS/src/eg2/src/app/scko/scko.component.ts +++ b/Open-ILS/src/eg2/src/app/scko/scko.component.ts @@ -26,10 +26,8 @@ export class SckoComponent implements OnInit, AfterViewInit { ngOnInit() { this.net.authExpired$.subscribe(how => { - console.debug("SCKO auth expired with info", how); - this.scko.resetPatron(); - this.auth.logout(); - this.router.navigate(['/scko']); + console.debug('SCKO auth expired with info', how); + this.scko.logoutStaff(); }); this.scko.load(); diff --git a/Open-ILS/src/eg2/src/app/scko/scko.service.ts b/Open-ILS/src/eg2/src/app/scko/scko.service.ts index 2268edfdc3..c3c8e28f7c 100644 --- a/Open-ILS/src/eg2/src/app/scko/scko.service.ts +++ b/Open-ILS/src/eg2/src/app/scko/scko.service.ts @@ -10,6 +10,12 @@ import {PatronService, PatronSummary, PatronStats} from '@eg/staff/share/patron/ import {ConfirmDialogComponent} from '@eg/share/dialog/confirm.component'; import {PrintService} from '@eg/share/print/print.service'; +interface CheckoutStat { + override?: boolean; + redo?: boolean; + renew?: boolean; +} + @Injectable({providedIn: 'root'}) export class SckoService { @@ -38,6 +44,12 @@ export class SckoService { private patrons: PatronService, ) {} + logoutStaff() { + this.resetPatron(); + this.auth.logout(); + this.router.navigate(['/scko']); + } + resetPatron() { this.patronSummary = null; this.sessionCheckouts = []; @@ -195,15 +207,94 @@ export class SckoService { } - /* - logout(receiptType: - this.printer.print({ - templateName: 'bills_current', - contextData: {xacts: rows}, - printContext: 'default' - }); - */ + checkout(barcode: string, override?: boolean): Promise { + this.resetPatronTimeout(); + + let method = 'open-ils.circ.checkout.full'; + if (override) { method += '.override'; } + + return this.net.request( + 'open-ils.circ', method, this.auth.token(), { + patron_id: this.patronSummary.id, + copy_barcode: barcode + }).toPromise() + + .then(result => { + + console.debug('CO returned', result); + + return this.handleCheckoutResult(result, barcode, 'checkout'); + + }).then(stat => { + console.debug('handleCheckoutResult returned', stat); + + if (stat.override) { + return this.checkout(barcode, true); + } else if (stat.redo) { + return this.checkout(barcode); + } else if (stat.renew) { + return this.renew(barcode); + } + }); + + // return this.router.navigate(['/scko']); + } + + renew(barcode: string, override?: boolean): Promise { + + let method = 'open-ils.circ.renew'; + if (override) { method += '.override'; } + + return this.net.request( + 'open-ils.circ', method, this.auth.token(), { + patron_id: this.patronSummary.id, + copy_barcode: barcode + }).toPromise() + + .then(result => { + console.debug('Renew returned', result); + return this.handleCheckoutResult(result, barcode, 'renew'); + + }).then(stat => { + console.debug('handleCheckoutResult returned', stat); + + if (stat.override) { + return this.renew(barcode, true); + } + }); + } + + + handleCheckoutResult(result: any, + barcode: string, action: string): Promise { + + if (Array.isArray(result)) { + result = result[0]; + } + + const evt: any = this.evt.parse(result) || {}; + const payload = evt.payload || {}; + + if (evt.textcode === 'NO_SESSION') { + this.logoutStaff(); + return; + } + + if (evt.textcode === 'SUCCESS') { + + if (action === 'checkout') { + + return Promise.resolve({}); + + } else if (action === 'renew') { + + return Promise.resolve({}); + } + } + + return Promise.resolve({}); // TODO + } } diff --git a/Open-ILS/src/eg2/src/app/share/print/print.service.ts b/Open-ILS/src/eg2/src/app/share/print/print.service.ts index e2d7a9767b..de6682f0b4 100644 --- a/Open-ILS/src/eg2/src/app/share/print/print.service.ts +++ b/Open-ILS/src/eg2/src/app/share/print/print.service.ts @@ -101,7 +101,7 @@ export class PrintService { reject({notFound: true}); } else { console.error( - "Print template generator returned status: " + this.status); + 'Print template generator returned status: ' + this.status); } reject({}); }