[open-ils-commits] [GIT] Evergreen ILS branch master updated. 853e7b2408872bd3b95d88191b0908baf75e115c

Evergreen Git git at git.evergreen-ils.org
Tue Jul 30 10:59:22 EDT 2019


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Evergreen ILS".

The branch, master has been updated
       via  853e7b2408872bd3b95d88191b0908baf75e115c (commit)
       via  cb6efeb8261a50f101a40fa9d96268a937636e39 (commit)
       via  5d9ce17d7d1dd8c610a6d3f0c62c4680a0ab51f8 (commit)
      from  f6c0ba381ad29334c708aa001ed7e72bcc73e32a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 853e7b2408872bd3b95d88191b0908baf75e115c
Author: Bill Erickson <berickxx at gmail.com>
Date:   Mon Jul 29 11:36:38 2019 -0400

    LP1831785 Combobox pcrud selector and pkey support
    
    Teach the PCRUD-driven combobox to use the IDL class' selector field
    as the sort and display field when no idlField value is provided.
    
    Teach the async source to use the pkey field of the IDL class instead of
    assuming the 'id' field.
    
    Tweak the sandbox example to fetch data for a class which uses a
    selector not called "name" and a pkey not called "id".
    
    Signed-off-by: Bill Erickson <berickxx at gmail.com>
    Signed-off-by: Jane Sandberg <sandbej at linnbenton.edu>

diff --git a/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts b/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts
index 1fe37b141b..99206321cd 100644
--- a/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts
+++ b/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts
@@ -8,6 +8,7 @@ import {Observable, of, Subject} from 'rxjs';
 import {map, tap, reduce, mergeMap, mapTo, debounceTime, distinctUntilChanged, merge, filter} from 'rxjs/operators';
 import {NgbTypeahead, NgbTypeaheadSelectItemEvent} from '@ng-bootstrap/ng-bootstrap';
 import {StoreService} from '@eg/core/store.service';
+import {IdlService} from '@eg/core/idl.service';
 import {PcrudService} from '@eg/core/pcrud.service';
 
 export interface ComboboxEntry {
@@ -103,6 +104,7 @@ export class ComboboxComponent implements OnInit {
     constructor(
       private elm: ElementRef,
       private store: StoreService,
+      private idl: IdlService,
       private pcrud: PcrudService,
     ) {
         this.entrylist = [];
@@ -119,14 +121,25 @@ export class ComboboxComponent implements OnInit {
 
     ngOnInit() {
         if (this.idlClass) {
+            const classDef = this.idl.classes[this.idlClass];
+            const pkeyField = classDef.pkey;
+
+            if (!pkeyField) {
+                throw new Error(`IDL class ${this.idlClass} has no pkey field`);
+            }
+
+            if (!this.idlField) {
+                this.idlField = classDef.field_map[classDef.pkey].selector || 'name';
+            }
+
             this.asyncDataSource = term => {
-                const field = this.idlField || 'name';
+                const field = this.idlField;
                 const args = {};
                 const extra_args = { order_by : {} };
-                args[field] = { 'ilike': `%${term}%`}; // could -or search on label
-                extra_args['order_by'][this.idlClass] = this.idlField || 'name';
+                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.id(), label: data[field]()};
+                    return {id: data[pkeyField](), label: data[field]()};
                 }));
             };
         }
diff --git a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html
index 1b36ec8f60..4d3f795c1b 100644
--- a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html
+++ b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html
@@ -94,6 +94,10 @@
     </eg-combobox>
   </div>
   <div class="col-lg-3">
+    <eg-combobox placeholder="Combobox with @idlClass = 'cvrfm'" idlClass="cvrfm" [asyncSupportsEmptyTermClick]="true">
+    </eg-combobox>
+  </div>
+  <div class="col-lg-3">
     <eg-combobox placeholder="Combobox with @idlClass = 'csp'" idlClass="csp" [asyncSupportsEmptyTermClick]="true">
     </eg-combobox>
   </div>

commit cb6efeb8261a50f101a40fa9d96268a937636e39
Author: Jane Sandberg <sandbej at linnbenton.edu>
Date:   Sat Jul 27 10:50:40 2019 -0700

    LP1831785 (follow-up): simplifying static string binding, removing empty else statement
    
    Signed-off-by: Jane Sandberg <sandbej at linnbenton.edu>
    Signed-off-by: Bill Erickson <berickxx at gmail.com>

diff --git a/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts b/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts
index 4a98fe39f6..1fe37b141b 100644
--- a/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts
+++ b/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts
@@ -223,7 +223,6 @@ export class ComboboxComponent implements OnInit {
         searchTerm = term;
         if (searchTerm === '_CLICK_' && this.asyncSupportsEmptyTermClick) {
             searchTerm = '';
-        } else {
         }
 
         return new Observable(observer => {
diff --git a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html
index d7cff9f0d9..1b36ec8f60 100644
--- a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html
+++ b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html
@@ -90,11 +90,11 @@
   <div class="col-lg-4">
   </div>
   <div class="col-lg-3">
-    <eg-combobox placeholder="Combobox with @idlClass = 'aou' @idlField='shortname'" [idlClass]="'aou'" [idlField]="'shortname'" [asyncSupportsEmptyTermClick]="true">
+    <eg-combobox placeholder="Combobox with @idlClass = 'aou' @idlField='shortname'" idlClass="aou" idlField="shortname" [asyncSupportsEmptyTermClick]="true">
     </eg-combobox>
   </div>
   <div class="col-lg-3">
-    <eg-combobox placeholder="Combobox with @idlClass = 'csp'" [idlClass]="'csp'" [asyncSupportsEmptyTermClick]="true">
+    <eg-combobox placeholder="Combobox with @idlClass = 'csp'" idlClass="csp" [asyncSupportsEmptyTermClick]="true">
     </eg-combobox>
   </div>
 </div>
@@ -102,7 +102,7 @@
   <div class="col-lg-4">
   </div>
   <div class="col-lg-3">
-    <eg-combobox placeholder="Combobox with @idlClass = 'aou'" [idlClass]="'aou'" [asyncSupportsEmptyTermClick]="true">
+    <eg-combobox placeholder="Combobox with @idlClass = 'aou'" idlClass="aou" [asyncSupportsEmptyTermClick]="true">
     </eg-combobox>
   </div>
   <div class="col-lg-3">

commit 5d9ce17d7d1dd8c610a6d3f0c62c4680a0ab51f8
Author: Jason Etheridge <jason at EquinoxInitiative.org>
Date:   Wed Jun 5 11:42:29 2019 -0400

    LP#1831785: eg-combobox support automatic pcrud-based IDL data sources
    
    This patch adds new idlClass and idlField attributes to eg-combobox to
    enable it to automatically construct a pcrud-base data source. The
    idlClass property specifies which table/class to use as the base
    data source, while idlField specifies the label to display. If idlField
    is not supplied, the label field defaults to "name".
    
    It also adds an asyncSupportsEmptyTermClick option to specify that an
    async data source (whether or not it is automatically built) is
    expected to never return more than a couple hundred entries or so;
    when supplied, it will allow fetching the entire contents of the
    data source when the user clicks on the drop-down.
    
    To test
    -------
    [1] Apply the patch and exercise the comboboxes on the
         Angular sandbox page (/eg2/en-US/staff/sandbox)
    
    Sponsored-by: MassLNC
    Sponsored-by: Georgia Public Library Service
    Sponsored-by: Indiana State Library
    Sponsored-by: CW MARS
    Sponsored-by: King County Library System
    
    Signed-off-by: Jason Etheridge <jason at EquinoxInitiative.org>
    Signed-off-by: Galen Charlton <gmc at equinoxinitiative.org>
    Signed-off-by: Bill Erickson <berickxx at gmail.com>
    Signed-off-by: Jane Sandberg <sandbej at linnbenton.edu>

diff --git a/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts b/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts
index 63f964ef81..4a98fe39f6 100644
--- a/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts
+++ b/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts
@@ -8,6 +8,7 @@ import {Observable, of, Subject} from 'rxjs';
 import {map, tap, reduce, mergeMap, mapTo, debounceTime, distinctUntilChanged, merge, filter} from 'rxjs/operators';
 import {NgbTypeahead, NgbTypeaheadSelectItemEvent} from '@ng-bootstrap/ng-bootstrap';
 import {StoreService} from '@eg/core/store.service';
+import {PcrudService} from '@eg/core/pcrud.service';
 
 export interface ComboboxEntry {
   id: any;
@@ -61,8 +62,16 @@ export class ComboboxComponent implements OnInit {
     @Input() startId: any;
     @Input() startIdFiresOnChange: boolean;
 
+    @Input() idlClass: string;
+    @Input() idlField: string;
     @Input() asyncDataSource: (term: string) => Observable<ComboboxEntry>;
 
+    // If true, an async data search is allowed to fetch all
+    // values when given an empty term. This should be used only
+    // if the maximum number of entries returned by the data source
+    // is known to be no more than a couple hundred.
+    @Input() asyncSupportsEmptyTermClick: boolean;
+
     // Useful for efficiently preventing duplicate async entries
     asyncIds: {[idx: string]: boolean};
 
@@ -94,6 +103,7 @@ export class ComboboxComponent implements OnInit {
     constructor(
       private elm: ElementRef,
       private store: StoreService,
+      private pcrud: PcrudService,
     ) {
         this.entrylist = [];
         this.asyncIds = {};
@@ -108,6 +118,18 @@ export class ComboboxComponent implements OnInit {
     }
 
     ngOnInit() {
+        if (this.idlClass) {
+            this.asyncDataSource = term => {
+                const field = this.idlField || 'name';
+                const args = {};
+                const extra_args = { order_by : {} };
+                args[field] = { 'ilike': `%${term}%`}; // could -or search on label
+                extra_args['order_by'][this.idlClass] = this.idlField || 'name';
+                return this.pcrud.search(this.idlClass, args, extra_args).pipe(map(data => {
+                    return {id: data.id(), label: data[field]()};
+                }));
+            };
+        }
     }
 
     openMe($event) {
@@ -197,12 +219,19 @@ export class ComboboxComponent implements OnInit {
             return of(term);
         }
 
+        let searchTerm: string;
+        searchTerm = term;
+        if (searchTerm === '_CLICK_' && this.asyncSupportsEmptyTermClick) {
+            searchTerm = '';
+        } else {
+        }
+
         return new Observable(observer => {
-            this.asyncDataSource(term).subscribe(
+            this.asyncDataSource(searchTerm).subscribe(
                 (entry: ComboboxEntry) => this.addAsyncEntry(entry),
                 err => {},
                 ()  => {
-                    observer.next(term);
+                    observer.next(searchTerm);
                     observer.complete();
                 }
             );
@@ -220,7 +249,7 @@ export class ComboboxComponent implements OnInit {
                 // action is a user click instead of a text entry.
                 // This tells the filter to show all values in sync mode.
                 this.click$.pipe(filter(() =>
-                    !this.instance.isPopupOpen() && !this.asyncDataSource
+                    !this.instance.isPopupOpen()
                 )).pipe(mapTo('_CLICK_'))
             ),
 
@@ -229,12 +258,7 @@ export class ComboboxComponent implements OnInit {
             map((term: string) => {
 
                 if (term === '' || term === '_CLICK_') {
-                    // Avoid displaying the existing entries on-click
-                    // for async sources, becuase that implies we have
-                    // the full data set. (setting?)
-                    if (this.asyncDataSource) {
-                        return [];
-                    } else {
+                    if (!this.asyncDataSource) {
                         // In sync mode, a post-focus empty search or
                         // click event displays the whole list.
                         return this.entrylist;
diff --git a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html
index 38908aeed6..d7cff9f0d9 100644
--- a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html
+++ b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html
@@ -69,7 +69,7 @@
   <div class="col-lg-3">
     <eg-help-popover helpText="You have to type to see any options in this dropdown."></eg-help-popover>
     <eg-combobox
-      placeholder="Combobox with dynamic data"
+      placeholder="Combobox with dynamic data that does not enable click if no search term is supplied"
       [asyncDataSource]="cbAsyncSource"></eg-combobox>
   </div>
 </div>
@@ -86,6 +86,28 @@
     </eg-org-select>
   </div>
 </div>
+<div class="row mb-3">
+  <div class="col-lg-4">
+  </div>
+  <div class="col-lg-3">
+    <eg-combobox placeholder="Combobox with @idlClass = 'aou' @idlField='shortname'" [idlClass]="'aou'" [idlField]="'shortname'" [asyncSupportsEmptyTermClick]="true">
+    </eg-combobox>
+  </div>
+  <div class="col-lg-3">
+    <eg-combobox placeholder="Combobox with @idlClass = 'csp'" [idlClass]="'csp'" [asyncSupportsEmptyTermClick]="true">
+    </eg-combobox>
+  </div>
+</div>
+<div class="row mb-3">
+  <div class="col-lg-4">
+  </div>
+  <div class="col-lg-3">
+    <eg-combobox placeholder="Combobox with @idlClass = 'aou'" [idlClass]="'aou'" [asyncSupportsEmptyTermClick]="true">
+    </eg-combobox>
+  </div>
+  <div class="col-lg-3">
+  </div>
+</div>
 <!-- /Progress Dialog Experiments ----------------------------- -->
 
 <!-- eg strings -->

-----------------------------------------------------------------------

Summary of changes:
 .../src/app/share/combobox/combobox.component.ts   | 54 ++++++++++++++++++----
 .../src/app/staff/sandbox/sandbox.component.html   | 28 ++++++++++-
 2 files changed, 72 insertions(+), 10 deletions(-)


hooks/post-receive
-- 
Evergreen ILS


More information about the open-ils-commits mailing list