LP#1942220: implement LI search action delete
authorGalen Charlton <gmc@equinoxOLI.org>
Wed, 15 Dec 2021 00:04:09 +0000 (19:04 -0500)
committerGalen Charlton <gmc@equinoxOLI.org>
Wed, 15 Dec 2021 00:04:09 +0000 (19:04 -0500)
Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
Open-ILS/src/eg2/src/app/staff/acq/search/lineitem-results.component.html
Open-ILS/src/eg2/src/app/staff/acq/search/lineitem-results.component.ts

index 6baf6ab..9afc20f 100644 (file)
@@ -5,11 +5,13 @@
 <eg-acq-export-attributes-dialog #exportAttributesDialog></eg-acq-export-attributes-dialog>
 <eg-acq-claim-policy-dialog #claimPolicyDialog></eg-acq-claim-policy-dialog>
 <eg-acq-cancel-dialog #cancelDialog></eg-acq-cancel-dialog>
+<eg-acq-delete-lineitems-dialog #deleteLineitemsDialog></eg-acq-delete-lineitems-dialog>
 
 <eg-string #claimPolicyAppliedString i18n-text text="Claim Policy Applied to Selected Line Item(s)"></eg-string>
 <eg-string #lineItemsReceivedString i18n-text text="Line Item(s) Received"></eg-string>
 <eg-string #lineItemsUnReceivedString i18n-text text="Line Item(s) Un-Received"></eg-string>
 <eg-string #lineItemsCancelledString i18n-text text="Line Item(s) Canceled"></eg-string>
+<eg-string #lineItemsDeletedString i18n-text text="Line Item(s) Deleted"></eg-string>
 
 <eg-alert-dialog #noActionableLIs i18n-dialogBody
   dialogBody="None of the selected line items are suitable for the action.">
index 35b43b4..0475c9b 100644 (file)
@@ -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;