LP#1929749: teach LI alert checking to handle more than one LI
authorGalen Charlton <gmc@equinoxOLI.org>
Sat, 5 Feb 2022 22:34:16 +0000 (17:34 -0500)
committerGalen Charlton <gmc@equinoxOLI.org>
Sat, 5 Feb 2022 22:34:16 +0000 (17:34 -0500)
Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
Open-ILS/src/eg2/src/app/staff/acq/lineitem/batch-copies.component.ts
Open-ILS/src/eg2/src/app/staff/acq/lineitem/lineitem-alert-dialog.component.html
Open-ILS/src/eg2/src/app/staff/acq/lineitem/lineitem-alert-dialog.component.ts
Open-ILS/src/eg2/src/app/staff/acq/lineitem/lineitem.service.ts

index 568c0bc..370ed34 100644 (file)
@@ -105,7 +105,7 @@ export class LineitemBatchCopiesComponent implements OnInit {
     }
 
     receiveCopy(copy: IdlObject) {
-        this.liService.checkLiAlerts(this.lineitem, this.confirmAlertsDialog).then(ok => {
+        this.liService.checkLiAlerts([this.lineitem], this.confirmAlertsDialog).then(ok => {
             this.net.request(
                 'open-ils.acq',
                 'open-ils.acq.lineitem_detail.receive',
index 8c5942e..05a02d8 100644 (file)
@@ -3,9 +3,15 @@
   dialogTitle="Confirm Alert" [dialogBodyTemplate]="confirmAlertsMsg">
 </eg-confirm-dialog>
 <ng-template #confirmAlertsMsg>
+  <div *ngIf="numAlerts > 0" class="alert alert-warning" i18n>
+    Alert {{alertIndex}} out of {{numAlerts}}
+  </div>
   <div i18n>An alert has been placed on line item {{liId}} ({{title}})</div>
   <div class="mt-2">{{alertText.code()}}</div>
   <div>{{alertText.description()}}</div>
   <div>{{alertComment}}</div>
-  <div class="mt-2" i18n>Choose "Confirm" to acknowledge this alert and continue with receiving. Otherwise, choose "Cancel".</div>
+  <div class="mt-2" i18n>Choose "Confirm" to acknowledge this alert and continue with receiving.
+    Otherwise, choose "Cancel" to not receive the line item(s). If there is more than one alert,
+    all of them must be confirmed in order to complete the receiving.
+  </div>
 </ng-template>
index 3faecae..37b480d 100644 (file)
@@ -13,6 +13,8 @@ export class LineitemAlertDialogComponent {
     @Input() title: string;
     @Input() alertText: IdlObject;
     @Input() alertComment: string;
+    @Input() numAlerts = 0;
+    @Input() alertIndex = 0;
 
     @ViewChild('confirmAlertsDialog') confirmAlertsDialog: ConfirmDialogComponent;
 
index 5bbe82c..5fc3d38 100644 (file)
@@ -56,6 +56,13 @@ export interface FleshCacheParams {
     toCache?: boolean;
 }
 
+interface LineitemAlertData {
+    liId: number;
+    title: string;
+    alertText: IdlObject;
+    alertComment: string;
+}
+
 @Injectable()
 export class LineitemService {
 
@@ -473,25 +480,38 @@ export class LineitemService {
         );
     }
 
-    checkLiAlerts(li: IdlObject, dialog: LineitemAlertDialogComponent): Promise<boolean> {
+    checkLiAlerts(lis: IdlObject[], dialog: LineitemAlertDialogComponent): Promise<boolean> {
 
         let promise = Promise.resolve(true);
 
-        const notes = li.lineitem_notes().filter(note =>
-            note.alert_text() && !this.alertAcks[note.id()]);
+        const alerts: LineitemAlertData[] = [];
+        lis.forEach(li => {
+            li.lineitem_notes().filter(
+                note => note.alert_text() && !this.alertAcks[note.id()]
+            ).forEach(alert =>
+                alerts.push({
+                    liId: li.id(),
+                    title: this.getFirstAttributeValue(li, 'title'),
+                    alertText: alert.alert_text(),
+                    alertComment: alert.value()
+                })
+            );
+        });
 
-        if (notes.length === 0) { return promise; }
+        if (alerts.length === 0) { return promise; }
 
-        dialog.liId = li.id();
-        dialog.title = this.getFirstAttributeValue(li, 'title');
+        dialog.numAlerts = alerts.length;
 
-        notes.forEach(n => {
+        alerts.forEach((alert, i) => {
             promise = promise.then(_ => {
-                dialog.alertText = n.alert_text();
-                dialog.alertComment = n.value();
+                dialog.liId = alert.liId;
+                dialog.title = alert.title;
+                dialog.alertText = alert.alertText;
+                dialog.alertComment = alert.alertComment;
+                dialog.alertIndex = i + 1;
                 return dialog.open().toPromise().then(ok => {
                     if (!ok) { return Promise.reject(); }
-                    this.alertAcks[n.id()] = true;
+                    this.alertAcks[alert.alertText.id()] = true;
                     return true;
                 });
             });