From 64c68ff9129b067041f2117dc634733ac4be1e37 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 25 Feb 2021 12:10:56 -0500 Subject: [PATCH] LP1904036 Mark items lost Signed-off-by: Bill Erickson Signed-off-by: Jane Sandberg Signed-off-by: Galen Charlton --- .../eg2/src/app/staff/share/circ/circ.service.ts | 29 +++------- .../src/app/staff/share/circ/grid.component.html | 8 ++- .../eg2/src/app/staff/share/circ/grid.component.ts | 65 +++++++++++++++++++--- 3 files changed, 70 insertions(+), 32 deletions(-) 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 3c513d0736..027bfd6d33 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 @@ -1,6 +1,6 @@ import {Injectable} from '@angular/core'; -import {Observable, empty} from 'rxjs'; -import {map, mergeMap} from 'rxjs/operators'; +import {Observable, empty, from} from 'rxjs'; +import {map, concatMap, 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'; @@ -178,29 +178,14 @@ export class CircService { if (copyIds.length === 0) { return empty(); } if (!params) { params = {}; } - const ids = [].concat(copyIds); // clone - let observer; - const observable = new Observable(o => observer = o); - - const checkinOne = (ids: number[]): Promise => { - if (ids.length === 0) { - observer.complete(); - return Promise.resolve(null); - } + const source = from(copyIds); + return source.pipe(concatMap(id => { const cparams = Object.assign(params, {}); // clone - cparams.copy_id = ids.pop(); - - return this.checkin(cparams).then(result => { - observer.next(result); - return checkinOne(ids); - }); - } - - checkinOne(ids); - - return observable; + cparams.copy_id = id; + return from(this.checkin(cparams)); + })); } } diff --git a/Open-ILS/src/eg2/src/app/staff/share/circ/grid.component.html b/Open-ILS/src/eg2/src/app/staff/share/circ/grid.component.html index 53177274fa..18b0ec6a3a 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/circ/grid.component.html +++ b/Open-ILS/src/eg2/src/app/staff/share/circ/grid.component.html @@ -54,7 +54,13 @@ group="Mark" i18n-group i18n-label label="Mark Item Missing" (onClick)="showMarkMissingDialog($event)"> - + + + + Number(row.id())); + } + getCircs(rows: any): IdlObject[] { return rows.filter(r => r.circ).map(r => r.circ); } @@ -342,7 +357,7 @@ export class CircGridComponent implements OnInit { this.itemsOutConfirm.open().subscribe(confirmed => { if (!confirmed) { return; } - this.checkin(rows, {noop: true}, true).then(_ => { + this.checkin(rows, {noop: true}, true).toPromise().then(_ => { this.markMissingDialog.copyIds = copyIds; this.markMissingDialog.open({}).subscribe( @@ -356,16 +371,48 @@ export class CircGridComponent implements OnInit { }); } - // TODO: progress dialog + openProgressDialog(rows: CircGridEntry[]): ProgressDialogComponent { + this.progressDialog.update({value: 0, max: rows.length}); + this.progressDialog.open(); + return this.progressDialog; + } + // Same params will be used for each copy - checkin(rows: CircGridEntry[], params?: CheckinParams, noReload?: boolean): Promise { - return this.circ.checkinBatch(this.getCopyIds(rows), params).toPromise() - .then(_ => { if (!noReload) { this.emitReloadRequest(); } }); + checkin(rows: CircGridEntry[], params?: + CheckinParams, noReload?: boolean): Observable { + + const dialog = this.openProgressDialog(rows); + + return this.circ.checkinBatch(this.getCopyIds(rows), params) + .pipe(tap( + result => dialog.increment(), + err => null, + () => { + dialog.close(); + if (!noReload) { this.emitReloadRequest(); } + } + )); } - emitReloadRequest() { - this.entries = null; - this.reloadRequested.emit(); + //markLost(rows: CircGridEntry[]): Observable { + markLost(rows: CircGridEntry[]) { + const dialog = this.openProgressDialog(rows); + const barcodes = this.getCopies(rows).map(c => c.barcode()); + + from(barcodes).pipe(concatMap(barcode => { + return this.net.request( + 'open-ils.circ', + 'open-ils.circ.circulation.set_lost', + this.auth.token(), {barcode: barcode} + ); + })).subscribe( + result => dialog.increment(), + err => console.error(err), + () => { + dialog.close(); + this.emitReloadRequest(); + } + ); } } -- 2.11.0