From 6a219f06768f9fb43a185411ba9ff946c625ba41 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 20 Jul 2021 17:57:44 -0400 Subject: [PATCH] LP1936233 Item status actions menu Signed-off-by: Bill Erickson --- .../holdings/mark-items-dialog.component.html | 65 +++++++++ .../share/holdings/mark-items-dialog.component.ts | 161 +++++++++++++++++++++ 2 files changed, 226 insertions(+) create mode 100644 Open-ILS/src/eg2/src/app/staff/share/holdings/mark-items-dialog.component.html create mode 100644 Open-ILS/src/eg2/src/app/staff/share/holdings/mark-items-dialog.component.ts diff --git a/Open-ILS/src/eg2/src/app/staff/share/holdings/mark-items-dialog.component.html b/Open-ILS/src/eg2/src/app/staff/share/holdings/mark-items-dialog.component.html new file mode 100644 index 0000000000..9b70023c60 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/share/holdings/mark-items-dialog.component.html @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Open-ILS/src/eg2/src/app/staff/share/holdings/mark-items-dialog.component.ts b/Open-ILS/src/eg2/src/app/staff/share/holdings/mark-items-dialog.component.ts new file mode 100644 index 0000000000..42a666d51b --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/share/holdings/mark-items-dialog.component.ts @@ -0,0 +1,161 @@ +import {Component, OnInit, Input, ViewChild} from '@angular/core'; +import {of, empty, from, Observable, throwError} from 'rxjs'; +import {concatMap, map} from 'rxjs/operators'; +import {NetService} from '@eg/core/net.service'; +import {IdlObject, IdlService} from '@eg/core/idl.service'; +import {EventService} from '@eg/core/event.service'; +import {ToastService} from '@eg/share/toast/toast.service'; +import {AuthService} from '@eg/core/auth.service'; +import {DialogComponent} from '@eg/share/dialog/dialog.component'; +import {ConfirmDialogComponent} from '@eg/share/dialog/confirm.component'; +import {NgbModal, NgbModalOptions} from '@ng-bootstrap/ng-bootstrap'; +import {StringComponent} from '@eg/share/string/string.component'; +import {HoldingsService} from './holdings.service'; + + +/** + * Dialog for marking items various statuses + */ + + +interface MarkItemArgs { + handle_checkin?: boolean; + handle_transit?: boolean; + handle_last_hold_copy?: boolean; + handle_copy_delete_warning?: boolean; +} + + +@Component({ + selector: 'eg-mark-items-dialog', + templateUrl: 'mark-items-dialog.component.html' +}) + +export class MarkItemsDialogComponent + extends DialogComponent implements OnInit { + + @Input() markAs: 'missing' | 'discard'; + @Input() copies: IdlObject[]; + + copyCount = 0; + method: string; + statusName: string; + copyStatuses: {[statId: number]: IdlObject} = {}; + numSucceeded: number; + numFailed: number; + currentBarcode: string; + + @ViewChild('successMsg') private successMsg: StringComponent; + @ViewChild('errorMsg') private errorMsg: StringComponent; + + @ViewChild('confirmDelete') private confirmDelete: ConfirmDialogComponent; + @ViewChild('confirmLastHold') private confirmLastHold: ConfirmDialogComponent; + @ViewChild('confirmCheckedOut') private confirmCheckedOut: ConfirmDialogComponent; + @ViewChild('confirmInTransit') private confirmInTransit: ConfirmDialogComponent; + + constructor( + private modal: NgbModal, // required for passing to parent + private toast: ToastService, + private net: NetService, + private evt: EventService, + private holdings: HoldingsService, + private auth: AuthService) { + super(modal); // required for subclassing + } + + ngOnInit() {} + + open(args?: NgbModalOptions): Observable { + this.numSucceeded = 0; + this.numFailed = 0; + this.currentBarcode = ''; + let copyStatus: number; + + switch (this.markAs) { + case 'missing': + this.method = 'open-ils.circ.mark_item_missing'; + copyStatus = 4; + break; + case 'discard': + this.method = 'open-ils.circ.mark_item_discard'; + copyStatus = 13; + break; + } + + return of( + this.holdings.getCopyStatuses() + .then(stats => { + this.copyStatuses = stats; + this.statusName = this.copyStatuses[copyStatus].name(); + }) + ).pipe(concatMap(_ => super.open(args))); + } + + markOneItem(copy: IdlObject, args?: MarkItemArgs): Observable { + if (!args) { args = {}; } + this.currentBarcode = copy.barcode(); + + return this.net.request( + 'open-ils.circ', this.method, this.auth.token(), copy.id(), args) + .pipe(concatMap(resp => { + return this.handleMarkResponse(copy, args, resp); + })); + } + + handleMarkResponse(copy: IdlObject, args: MarkItemArgs, resp: any): Observable { + const evt = this.evt.parse(resp); + + if (!evt) { return of(true); } // success + + let dialog: ConfirmDialogComponent; + + switch (evt.textcode) { + case 'ITEM_TO_MARK_CHECKED_OUT': + dialog = this.confirmCheckedOut; + args.handle_checkin = true; + break; + case 'ITEM_TO_MARK_IN_TRANSIT': + args.handle_transit = true; + dialog = this.confirmInTransit; + break; + case 'ITEM_TO_MARK_LAST_HOLD_COPY': + args.handle_last_hold_copy = true; + dialog = this.confirmLastHold; + break; + case 'COPY_DELETE_WARNING': + args.handle_copy_delete_warning = true; + dialog = this.confirmDelete; + break; + default: + console.error('Marking failed ' + evt); + return of(false); + } + + return dialog.open().pipe(concatMap(confirmed => { + if (confirmed) { + return this.markOneItem(copy, args); + } else { + return of(false); + } + })); + } + + // Returns a stream of copy IDs. Any non-null ID is a copy that + // was successfully modified. + markItems() { + if (!this.copies || this.copies.length === 0) { + this.close(); + return; + } + + this.copyCount = this.copies.length; + + from(this.copies).pipe(concatMap(copy => { + return this.markOneItem(copy) + .pipe(map(modified => this.respond(modified ? copy.id() : null))); + })).toPromise().then(_ => this.close()); + } +} + + + -- 2.11.0