<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.">
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';
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',
@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;
});
}
+ 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;