From eeed3763a6c91e2ff14d1a133096ae3c7eeda58d Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 29 Jun 2018 14:48:22 -0400 Subject: [PATCH] LP#775466 Org selector shows all on click Signed-off-by: Bill Erickson --- .../app/share/org-select/org-select.component.ts | 36 ++++++++++++++-------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/share/org-select/org-select.component.ts b/Open-ILS/src/eg2/src/app/share/org-select/org-select.component.ts index ec906b97bf..8055616e29 100644 --- a/Open-ILS/src/eg2/src/app/share/org-select/org-select.component.ts +++ b/Open-ILS/src/eg2/src/app/share/org-select/org-select.component.ts @@ -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)); }) ); } -- 2.11.0