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';
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));
})
);
}