LP#1929749: add mark selector/order ready actions to LI list
authorGalen Charlton <gmc@equinoxOLI.org>
Wed, 19 Jan 2022 22:54:40 +0000 (17:54 -0500)
committerGalen Charlton <gmc@equinoxOLI.org>
Wed, 19 Jan 2022 22:54:40 +0000 (17:54 -0500)
Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
Open-ILS/src/eg2/src/app/staff/acq/lineitem/lineitem-list.component.html
Open-ILS/src/eg2/src/app/staff/acq/lineitem/lineitem-list.component.ts

index e53806e..7c9c1c7 100644 (file)
@@ -7,6 +7,22 @@
 <eg-acq-claim-policy-dialog #claimPolicyDialog></eg-acq-claim-policy-dialog>
 <eg-acq-export-attributes-dialog #exportAttributesDialog></eg-acq-export-attributes-dialog>
 
+<eg-string #lineItemsUpdatedString i18n-text text="Line Item(s) Updated"></eg-string>
+
+<eg-alert-dialog #noActionableLIs i18n-dialogBody
+  dialogBody="None of the selected line items are suitable for the action.">
+</eg-alert-dialog>
+<eg-confirm-dialog #selectorReadyConfirmDialog
+  i18n-dialogTitle i18n-dialogBody
+  dialogTitle="Confirm Line Item Change"
+  dialogBody="Mark selected line item(s) as ready for selector?">
+</eg-confirm-dialog>
+<eg-confirm-dialog #orderReadyConfirmDialog
+  i18n-dialogTitle i18n-dialogBody
+  dialogTitle="Confirm Line Item Change"
+  dialogBody="Mark selected line item(s) as ready for order?">
+</eg-confirm-dialog>
+
 <div class="col-lg-6 offset-lg-3" *ngIf="saving">
   <eg-progress-inline [max]="progressMax" [value]="progressValue">
   </eg-progress-inline>
           [disabled]="!selectedIds().length" i18n>Export Single Attribute List for Selected Line Items</button>
         <div class="dropdown-divider"></div>
         <h6 class="dropdown-header" i18n>Selection List Actions</h6>
+        <button ngbDropdownItem (click)="markSelectorReady()" 
+          [disabled]="!picklistId" i18n>Mark Selected Line Items as Ready for Selector</button>
+        <button ngbDropdownItem (click)="markOrderReady()" 
+          [disabled]="!picklistId" i18n>Mark Selected Line Items as Ready for Order</button>
         <button ngbDropdownItem (click)="createPo()" 
           [disabled]="!picklistId" i18n>Create Purchase Order from Selected Line Items</button>
         <button ngbDropdownItem (click)="createPo(true)"
index 6e6d81c..72bd173 100644 (file)
@@ -7,11 +7,15 @@ import {EgEvent, EventService} from '@eg/core/event.service';
 import {IdlService, IdlObject} from '@eg/core/idl.service';
 import {NetService} from '@eg/core/net.service';
 import {AuthService} from '@eg/core/auth.service';
+import {ToastService} from '@eg/share/toast/toast.service';
 import {ServerStoreService} from '@eg/core/server-store.service';
 import {LineitemService, LINEITEM_DISPOSITION} from './lineitem.service';
 import {PoService} from '../po/po.service';
 import {ComboboxEntry} from '@eg/share/combobox/combobox.component';
 import {HoldingsService} from '@eg/staff/share/holdings/holdings.service';
+import {StringComponent} from '@eg/share/string/string.component';
+import {AlertDialogComponent} from '@eg/share/dialog/alert.component';
+import {ConfirmDialogComponent} from '@eg/share/dialog/confirm.component';
 import {CancelDialogComponent} from './cancel-dialog.component';
 import {DeleteLineitemsDialogComponent} from './delete-lineitems-dialog.component';
 import {AddCopiesDialogComponent} from './add-copies-dialog.component';
@@ -120,6 +124,10 @@ export class LineitemListComponent implements OnInit {
     @ViewChild('linkInvoiceDialog') linkInvoiceDialog: LinkInvoiceDialogComponent;
     @ViewChild('exportAttributesDialog') exportAttributesDialog: ExportAttributesDialogComponent;
     @ViewChild('claimPolicyDialog') claimPolicyDialog: ClaimPolicyDialogComponent;
+    @ViewChild('lineItemsUpdatedString', { static: false }) lineItemsUpdatedString: StringComponent;
+    @ViewChild('noActionableLIs', { static: true }) private noActionableLIs: AlertDialogComponent;
+    @ViewChild('selectorReadyConfirmDialog', { static: true }) selectorReadyConfirmDialog: ConfirmDialogComponent;
+    @ViewChild('orderReadyConfirmDialog', { static: true }) orderReadyConfirmDialog: ConfirmDialogComponent;
 
     constructor(
         private router: Router,
@@ -129,6 +137,7 @@ export class LineitemListComponent implements OnInit {
         private auth: AuthService,
         private store: ServerStoreService,
         private idl: IdlService,
+        private toast: ToastService,
         private holdings: HoldingsService,
         private liService: LineitemService,
         private poService: PoService
@@ -787,6 +796,74 @@ export class LineitemListComponent implements OnInit {
         });
     }
 
+    markSelectorReady(rows: IdlObject[]) {
+        const ids = this.selectedIds().map(i => Number(i));
+        if (ids.length === 0) { return; }
+
+        const lis: IdlObject[] = [];
+        this.liService.getFleshedLineitems(ids, { fromCache: true }).subscribe(
+            liStruct => {
+                if (liStruct.lineitem.state() === 'new') {
+                    lis.push(liStruct.lineitem);
+                }
+            },
+            err => {},
+            () => {
+                if (lis.length === 0) {
+                    this.noActionableLIs.open();
+                    return;
+                }
+                this.selectorReadyConfirmDialog.open().subscribe(doIt => {
+                    if (!doIt) { return; }
+                    lis.forEach(li => li.state('selector-ready'));
+                    this.net.request(
+                        'open-ils.acq',
+                        'open-ils.acq.lineitem.update',
+                        this.auth.token(), lis
+                    ).toPromise().then(resp => {
+                        this.lineItemsUpdatedString.current()
+                        .then(str => this.toast.success(str));
+                        this.postBatchAction(resp, ids);
+                    });
+                });
+            }
+        );
+    }
+
+    markOrderReady(rows: IdlObject[]) {
+        const ids = this.selectedIds().map(i => Number(i));
+        if (ids.length === 0) { return; }
+
+        const lis: IdlObject[] = [];
+        this.liService.getFleshedLineitems(ids, { fromCache: true }).subscribe(
+            liStruct => {
+                if (liStruct.lineitem.state() === 'new' || liStruct.lineitem.state() === 'selector-ready') {
+                    lis.push(liStruct.lineitem);
+                }
+            },
+            err => {},
+            () => {
+                if (lis.length === 0) {
+                    this.noActionableLIs.open();
+                    return;
+                }
+                this.orderReadyConfirmDialog.open().subscribe(doIt => {
+                    if (!doIt) { return; }
+                    lis.forEach(li => li.state('order-ready'));
+                    this.net.request(
+                        'open-ils.acq',
+                        'open-ils.acq.lineitem.update',
+                        this.auth.token(), lis
+                    ).toPromise().then(resp => {
+                        this.lineItemsUpdatedString.current()
+                        .then(str => this.toast.success(str));
+                        this.postBatchAction(resp, ids);
+                    });
+                });
+            }
+        );
+    }
+
     liHasRealCopies(li: IdlObject): boolean {
         for (let idx = 0; idx < li.lineitem_details().length; idx++) {
             if (li.lineitem_details()[idx].eg_copy_id()) {