immediately run search only of search form starts off being visble (LH#14)
authorGalen Charlton <gmc@equinoxinitiative.org>
Thu, 9 Jul 2020 21:52:49 +0000 (17:52 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Thu, 9 Jul 2020 21:52:49 +0000 (17:52 -0400)
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/eg2/src/app/staff/acq/provider/provider-results.component.ts

index b981b7f..1c670b0 100644 (file)
@@ -1,4 +1,4 @@
-import {Component, OnInit, AfterViewInit, Input, Output, EventEmitter, ViewChild} from '@angular/core';
+import {Component, OnInit, AfterViewInit, Input, Output, EventEmitter, ViewChild, ElementRef} from '@angular/core';
 import {Observable} from 'rxjs';
 import {map} from 'rxjs/operators';
 import {Router, ActivatedRoute, ParamMap} from '@angular/router';
@@ -27,6 +27,7 @@ export class ProviderResultsComponent implements OnInit {
     @Output('desireSummarize') summarize: EventEmitter<number> = new EventEmitter<number>();
 
     constructor(
+        private elementRef: ElementRef,
         private router: Router,
         private route: ActivatedRoute,
         private net: NetService,
@@ -48,7 +49,15 @@ export class ProviderResultsComponent implements OnInit {
     }
 
     ngAfterViewInit() {
-        setTimeout(x => this.providerSearchForm.submitSearch());
+        // check if we're visible; if we are, we've
+        // likely come in directly from the main Provider Search
+        // menu item and should go ahead and submit the
+        // form with default values
+        // see: https://stackoverflow.com/questions/37843907/angular2-is-there-a-way-to-know-when-a-component-is-hidden
+        const elm = this.elementRef.nativeElement;
+        if (elm.offsetParent !== null) {
+            setTimeout(x => this.providerSearchForm.submitSearch());
+        }
     }
 
     doSearch(search: AcqProviderSearch) {