From bfa94bee383156a3d99720900a09a02d14a6b0d5 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Tue, 14 Dec 2021 19:04:09 -0500 Subject: [PATCH] LP#1942220: implement LI search action delete Signed-off-by: Galen Charlton --- .../acq/search/lineitem-results.component.html | 2 + .../staff/acq/search/lineitem-results.component.ts | 43 +++++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/staff/acq/search/lineitem-results.component.html b/Open-ILS/src/eg2/src/app/staff/acq/search/lineitem-results.component.html index 6baf6ab032..9afc20f4e7 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/search/lineitem-results.component.html +++ b/Open-ILS/src/eg2/src/app/staff/acq/search/lineitem-results.component.html @@ -5,11 +5,13 @@ + + diff --git a/Open-ILS/src/eg2/src/app/staff/acq/search/lineitem-results.component.ts b/Open-ILS/src/eg2/src/app/staff/acq/search/lineitem-results.component.ts index 35b43b4252..0475c9b4ba 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/search/lineitem-results.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/acq/search/lineitem-results.component.ts @@ -1,6 +1,6 @@ import {Component, OnInit, Input, ViewChild} from '@angular/core'; -import {Observable} from 'rxjs'; -import {map} from 'rxjs/operators'; +import {Observable, from, of} from 'rxjs'; +import {map, concatMap} from 'rxjs/operators'; import {Router, ActivatedRoute, ParamMap} from '@angular/router'; import {Pager} from '@eg/share/util/pager'; import {IdlObject} from '@eg/core/idl.service'; @@ -17,6 +17,7 @@ import {StringComponent} from '@eg/share/string/string.component'; import {AlertDialogComponent} from '@eg/share/dialog/alert.component'; import {ClaimPolicyDialogComponent} from '../lineitem/claim-policy-dialog.component'; import {CancelDialogComponent} from '../lineitem/cancel-dialog.component'; +import {DeleteLineitemsDialogComponent} from '../lineitem/delete-lineitems-dialog.component'; @Component({ selector: 'eg-lineitem-results', @@ -32,10 +33,12 @@ export class LineitemResultsComponent implements OnInit { @ViewChild('exportAttributesDialog') exportAttributesDialog: ExportAttributesDialogComponent; @ViewChild('claimPolicyDialog') claimPolicyDialog: ClaimPolicyDialogComponent; @ViewChild('cancelDialog') cancelDialog: CancelDialogComponent; + @ViewChild('deleteLineitemsDialog') deleteLineitemsDialog: DeleteLineitemsDialogComponent; @ViewChild('claimPolicyAppliedString', { static: false }) claimPolicyAppliedString: StringComponent; @ViewChild('lineItemsReceivedString', { static: false }) lineItemsReceivedString: StringComponent; @ViewChild('lineItemsUnReceivedString', { static: false }) lineItemsUnReceivedString: StringComponent; @ViewChild('lineItemsCancelledString', { static: false }) lineItemsCancelledString: StringComponent; + @ViewChild('lineItemsDeletedString', { static: false }) lineItemsDeletedString: StringComponent; @ViewChild('noActionableLIs', { static: true }) private noActionableLIs: AlertDialogComponent; noSelectedRows: (rows: IdlObject[]) => boolean; @@ -167,6 +170,42 @@ export class LineitemResultsComponent implements OnInit { }); } + deleteLineitems(rows: IdlObject[]) { + const lis = rows.filter(l => + l.picklist() || ( + l.purchase_order() && + ['new', 'selector-ready', 'order-ready', 'approved', 'pending-order'].includes(l.state()) + ) + ); + // TODO - if the LI somehow has a claim attached to it, lineitem.delete + // current crashes + if (lis.length === 0) { + this.noActionableLIs.open(); + return; + } + const ids = lis.map(x => Number(x.id())); + this.deleteLineitemsDialog.ids = ids; + this.deleteLineitemsDialog.open().subscribe(doIt => { + if (!doIt) { return; } + + from(lis) + .pipe(concatMap(li => { + const method = li.purchase_order() ? + 'open-ils.acq.purchase_order.lineitem.delete' : + 'open-ils.acq.picklist.lineitem.delete'; + + return this.net.request('open-ils.acq', method, this.auth.token(), li.id()); + // TODO: cap parallelism + })) + .pipe(concatMap(_ => of(true) )) + .subscribe(r => {}, err => {}, () => { + this.lineItemsDeletedString.current() + .then(str => this.toast.success(str)); + this.lineitemResultsGrid.reload(); + }); + }); + } + exportSingleAttributeList(rows: IdlObject[]) { const ids = rows.map(x => Number(x.id())); this.exportAttributesDialog.ids = ids; -- 2.11.0