LP#775466 Org selector shows all on click
authorBill Erickson <berickxx@gmail.com>
Fri, 29 Jun 2018 18:48:22 +0000 (14:48 -0400)
committerBill Erickson <berickxx@gmail.com>
Fri, 29 Jun 2018 18:48:46 +0000 (14:48 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/share/org-select/org-select.component.ts

index ec906b9..8055616 100644 (file)
@@ -1,6 +1,7 @@
 import {Component, OnInit, Input, Output, ViewChild, EventEmitter} from '@angular/core';
 import {Observable} from 'rxjs/Observable';
 import {map} from 'rxjs/operators/map';
+import {mapTo} from 'rxjs/operators/mapTo';
 import {debounceTime} from 'rxjs/operators/debounceTime';
 import {distinctUntilChanged} from 'rxjs/operators/distinctUntilChanged';
 import {merge} from 'rxjs/operators/merge';
@@ -141,19 +142,30 @@ export class OrgSelectComponent implements OnInit {
         return text$.pipe(
             debounceTime(200),
             distinctUntilChanged(),
-            merge(this.click$.pipe(filter(() => !this.instance.isPopupOpen()))),
+            merge(
+                // Inject a specifier indicating the source of the 
+                // action is a user click
+                this.click$.pipe(filter(() => !this.instance.isPopupOpen()))
+                .pipe(mapTo('_CLICK_'))
+            ),
             map(term => {
-
-                return this.org.list().filter(org => {
-
-                    // Find orgs matching the search term
-                    return org[this.displayField]()
-                      .toLowerCase().indexOf(term.toLowerCase()) > -1;
-
-                }).filter(org => { // Exclude hidden orgs
-                    return this.hidden.filter(id => org.id() === id).length === 0;
-
-                }).map(org => this.formatForDisplay(org));
+                
+                let orgs = this.org.list().filter(org =>
+                    this.hidden.filter(id => org.id() === id).length === 0
+                );
+
+                if (term !== '_CLICK_') {
+                    // For search-driven events, limit to the matching
+                    // org units.
+                    orgs = orgs.filter(org => {
+                        return term === '' || // show all
+                            org[this.displayField]()
+                                .toLowerCase().indexOf(term.toLowerCase()) > -1;
+
+                    });
+                }
+                
+                return orgs.map(org => this.formatForDisplay(org));
             })
         );
     }