LP1941764 Import from queue propagate form inputs
authorBill Erickson <berickxx@gmail.com>
Wed, 12 May 2021 15:46:01 +0000 (11:46 -0400)
committerGalen Charlton <gmc@equinoxOLI.org>
Thu, 23 Sep 2021 13:48:13 +0000 (09:48 -0400)
When importing records from an existing Vandelay queue, ensure the
selected queue, its match set, its match bucket, and its holdings import
profile are propagated into the import form.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Christine Morgan <cmorgan@noblenet.org>
Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>

Open-ILS/src/eg2/src/app/staff/cat/vandelay/import.component.html
Open-ILS/src/eg2/src/app/staff/cat/vandelay/import.component.ts

index 2882bc5..ec2fa75 100644 (file)
@@ -79,6 +79,7 @@
     </div>
     <div class="col-lg-3">
       <eg-combobox [entries]="formatEntries('activeQueues')"
+        #queueSelector
         id="queue-select"
         [startId]="startQueueId"
         [startIdFiresOnChange]="true"
@@ -93,6 +94,7 @@
     </div>
     <div class="col-lg-3">
       <eg-combobox [entries]="formatEntries('bibBuckets')" 
+        #bucketSelector
         id="bucket-select"
         [startId]="selectedBucket"
         [disabled]="(selectedQueue && !selectedQueue.freetext) || importSelection()"
index 08f795d..ca4ed7e 100644 (file)
@@ -133,6 +133,8 @@ export class ImportComponent implements OnInit, AfterViewInit, OnDestroy {
         private mergeProfileSelector: ComboboxComponent;
     @ViewChild('fallThruMergeProfileSelector', { static: true })
         private fallThruMergeProfileSelector: ComboboxComponent;
+    @ViewChild('queueSelector') private queueSelector: ComboboxComponent;
+    @ViewChild('bucketSelector') private bucketSelector: ComboboxComponent;
 
     @ViewChild('dupeQueueAlert', { static: true })
         private dupeQueueAlert: AlertDialogComponent;
@@ -147,7 +149,6 @@ export class ImportComponent implements OnInit, AfterViewInit, OnDestroy {
         private store: ServerStoreService,
         private vandelay: VandelayService
     ) {
-        this.applyDefaults();
     }
 
     applyDefaults() {
@@ -158,20 +159,19 @@ export class ImportComponent implements OnInit, AfterViewInit, OnDestroy {
         this.formTemplates = {};
 
         if (this.vandelay.importSelection) {
+            // Apply start-id values to our comboboxes based on our
+            // import selection values.
+            const queue = this.vandelay.importSelection.queue;
 
-            if (!this.vandelay.importSelection.queue) {
+            if (!queue) {
                 // Incomplete import selection, clear it.
                 this.vandelay.importSelection = null;
                 return;
             }
 
-            const queue = this.vandelay.importSelection.queue;
             this.recordType = queue.queue_type();
-            this.selectedMatchSet = queue.match_set();
-
-            // This will be propagated to selectedQueue as a combobox
-            // entry via the combobox
             this.startQueueId = queue.id();
+            this.selectedMatchSet = queue.match_set();
 
             if (this.recordType === 'bib') {
                 this.selectedBucket = queue.match_bucket();
@@ -180,9 +180,49 @@ export class ImportComponent implements OnInit, AfterViewInit, OnDestroy {
         }
     }
 
-    ngOnInit() {}
+    applyImportSelection() {
+
+        // Depending on when the comboboxes are rendered, the start-id values
+        // applied in applyDefaults() may not have any affect.  Ensure we
+        // get the initial values we want by manually setting selectedIds
+        // to the rendered combobox as well.
+
+        const queue = this.vandelay.importSelection.queue;
+        if (!queue) {
+            // Incomplete import selection, clear it.
+            this.vandelay.importSelection = null;
+            return;
+        }
+
+        if (this.queueSelector) {
+            this.queueSelector.selectedId = this.startQueueId;
+            this.selectedQueue = {id: queue.id(), label: queue.name()};
+        }
+
+        if (this.matchSetSelector) {
+            this.matchSetSelector.selectedId = this.selectedMatchSet;
+        }
+
+        if (this.recordType === 'bib') {
+            if (this.holdingsProfileSelector) {
+                this.holdingsProfileSelector.selectedId = this.selectedHoldingsProfile;
+            }
+            if (this.bucketSelector) {
+                this.bucketSelector.selectedId = this.selectedBucket;
+            }
+        }
+    }
+
+    ngOnInit() {
+        this.applyDefaults();
+    }
 
     ngAfterViewInit() {
+        if (this.vandelay.importSelection) {
+            // setTimeout() is not required here, but it helps to
+            // avoid expression-changed-after-checking console messages.
+            setTimeout(() => this.applyImportSelection());
+        }
         this.loadStartupData();
     }