LP#1832897: Angular combobox: add idlIncludeLibraryInLabel option
authorGalen Charlton <gmc@equinoxinitiative.org>
Mon, 17 Jun 2019 00:30:10 +0000 (20:30 -0400)
committerJane Sandberg <sandbej@linnbenton.edu>
Wed, 4 Sep 2019 02:30:07 +0000 (19:30 -0700)
The new attribute, idlIncludeLibraryInLabel, specifies the
column containing a linked OU. That OU's shortname will
then be included in the label.  This attribute takes effect
only if idlClass is specified.

Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts
Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html

index 2664112..ce0dc3e 100644 (file)
@@ -72,6 +72,7 @@ export class ComboboxComponent implements ControlValueAccessor, OnInit {
 
     @Input() idlClass: string;
     @Input() idlField: string;
+    @Input() idlIncludeLibraryInLabel: string;
     @Input() asyncDataSource: (term: string) => Observable<ComboboxEntry>;
 
     // If true, an async data search is allowed to fetch all
@@ -152,9 +153,22 @@ export class ComboboxComponent implements ControlValueAccessor, OnInit {
                 const extra_args = { order_by : {} };
                 args[field] = {'ilike': `%${term}%`}; // could -or search on label
                 extra_args['order_by'][this.idlClass] = field;
-                return this.pcrud.search(this.idlClass, args, extra_args).pipe(map(data => {
-                    return {id: data[pkeyField](), label: data[field]()};
-                }));
+                if (this.idlIncludeLibraryInLabel) {
+                    extra_args['flesh'] = 1;
+                    const flesh_fields: Object = {};
+                    flesh_fields[this.idlClass] = [ this.idlIncludeLibraryInLabel ];
+                    extra_args['flesh_fields'] = flesh_fields;
+                    return this.pcrud.search(this.idlClass, args, extra_args).pipe(map(data => {
+                        return {
+                            id: data[pkeyField](),
+                            label: data[field]() + ' (' + data[this.idlIncludeLibraryInLabel]().shortname() + ')'
+                        };
+                    }));
+                } else {
+                    return this.pcrud.search(this.idlClass, args, extra_args).pipe(map(data => {
+                        return {id: data[pkeyField](), label: data[field]()};
+                    }));
+                }
             };
         }
     }
index 85585f9..3e29856 100644 (file)
     </eg-combobox>
   </div>
   <div class="col-lg-3">
+    <eg-combobox placeholder="Combobox with @idlClass = 'acpl'" [idlClass]="'acpl'" idlIncludeLibraryInLabel="owning_lib" [asyncSupportsEmptyTermClick]="true">
+    </eg-combobox>
   </div>
 </div>
 <!-- /Progress Dialog Experiments ----------------------------- -->