LP1888723 Angular holdings broadcast changes
authorBill Erickson <berickxx@gmail.com>
Tue, 18 Aug 2020 20:44:34 +0000 (16:44 -0400)
committerGalen Charlton <gmc@equinoxOLI.org>
Sun, 15 Aug 2021 23:55:03 +0000 (19:55 -0400)
Broadcast to other tabs information about which holdings have changed
during editing in the Angular volcopy UI.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Ruth Frasur <rfrasur@library.in.gov>
Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.component.ts

index f782eff..08eabd6 100644 (file)
@@ -13,6 +13,7 @@ import {ProgressInlineComponent} from '@eg/share/dialog/progress-inline.componen
 import {AnonCacheService} from '@eg/share/util/anon-cache.service';
 import {VolCopyService} from './volcopy.service';
 import {NgbNav, NgbNavChangeEvent} from '@ng-bootstrap/ng-bootstrap';
+import {BroadcastService} from '@eg/share/util/broadcast.service';
 
 const COPY_FLESH = {
     flesh: 1,
@@ -72,6 +73,7 @@ export class VolCopyComponent implements OnInit {
         private auth: AuthService,
         private pcrud: PcrudService,
         private cache: AnonCacheService,
+        private broadcaster: BroadcastService,
         private holdings: HoldingsService,
         private volcopy: VolCopyService
     ) { }
@@ -412,6 +414,26 @@ export class VolCopyComponent implements OnInit {
         }).then(_ => this.loading = false);
     }
 
+    broadcastChanges(volumes: IdlObject[]) {
+
+        const volIds = volumes.map(v => v.id());
+        const copyIds = [];
+        const recIds = [];
+
+        volumes.forEach(vol => {
+            if (!recIds.includes(vol.record())) {
+                recIds.push(vol.record());
+            }
+            vol.copies().forEach(copy => copyIds.push(copy.id()));
+        });
+
+        this.broadcaster.broadcast('eg.holdings.update', {
+            copies : copyIds,
+            volumes: volIds,
+            records: recIds
+        });
+    }
+
     saveApi(volumes: IdlObject[], override?:
         boolean, close?: boolean): Promise<number[]> {
 
@@ -438,6 +460,8 @@ export class VolCopyComponent implements OnInit {
                 return Promise.reject();
             }
 
+            this.broadcastChanges(volumes);
+
             return copyIds;
         });
     }