LP#1850547: eg-combobox: handle startId if idlClass is set
authorGalen Charlton <gmc@equinoxinitiative.org>
Mon, 20 Jan 2020 17:12:53 +0000 (12:12 -0500)
committerBill Erickson <berickxx@gmail.com>
Thu, 3 Sep 2020 15:50:59 +0000 (11:50 -0400)
This patch teaches the Angular eg-combobox component to retrieve
the record indicated by the startId attribute when an IDL class
is specified.

Sponsored-by: Evergreen Community Development Initiative
Sponsored-by: Georgia Public Library Service
Sponsored-by: Indiana State Library
Sponsored-by: C/W MARS

Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Signed-off-by: Tiffany Little <tlittle@georgialibraries.org>
Signed-off-by: Bill Erickson <berickxx@gmail.com>

Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts

index 2afbe41..56da747 100644 (file)
@@ -71,6 +71,7 @@ export class ComboboxComponent implements ControlValueAccessor, OnInit {
     // onChange() is NOT fired when applying the default value,
     // unless startIdFiresOnChange is set to true.
     @Input() startId: any = null;
+    @Input() idlClass: string;
     @Input() startIdFiresOnChange: boolean;
 
     // Allow the selected entry ID to be passed via the template
@@ -89,6 +90,16 @@ export class ComboboxComponent implements ControlValueAccessor, OnInit {
             // It's possible the selected ID lives in a set of entries
             // that are yet to be provided.
             this.startId = id;
+            if (this.idlClass) {
+                this.pcrud.retrieve(this.idlClass, id)
+                .subscribe(rec => {
+                    this.entrylist = [{
+                        id: id,
+                        label: rec[this.idlField]()
+                    }];
+                    this.selected = this.entrylist.filter(e => e.id === id)[0];
+                });
+            }
         }
     }
 
@@ -96,7 +107,6 @@ export class ComboboxComponent implements ControlValueAccessor, OnInit {
         return this.selected ? this.selected.id : null;
     }
 
-    @Input() idlClass: string;
     @Input() idlField: string;
     @Input() idlIncludeLibraryInLabel: string;
     @Input() asyncDataSource: (term: string) => Observable<ComboboxEntry>;