clear search form and redo default search if same-URL-navigated
authorGalen Charlton <gmc@equinoxinitiative.org>
Mon, 17 Aug 2020 21:25:08 +0000 (17:25 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Mon, 17 Aug 2020 21:25:08 +0000 (17:25 -0400)
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider.component.html
Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider.component.ts
Open-ILS/src/eg2/src/app/staff/acq/provider/provider-results.component.ts

index bf25eae..a1167b4 100644 (file)
@@ -24,7 +24,7 @@
 </div>
 <div class="row mb-5" [hidden]="!showSearchForm">
   <div class="col-lg-12">
-    <eg-provider-results (desireSummarize)="onDesireSummarize($event)"></eg-provider-results>
+    <eg-provider-results #acqProviderResults (desireSummarize)="onDesireSummarize($event)"></eg-provider-results>
   </div>
 </div>
 
index 3130ccb..a3aa44f 100644 (file)
@@ -1,4 +1,6 @@
-import {Component, OnInit, AfterViewInit, ViewChild, ChangeDetectorRef} from '@angular/core';
+import {Component, OnInit, AfterViewInit, ViewChild, ChangeDetectorRef, OnDestroy} from '@angular/core';
+import {filter, takeUntil} from 'rxjs/operators';
+import {Subject} from 'rxjs';
 import {NgbTabset, NgbTabChangeEvent} from '@ng-bootstrap/ng-bootstrap';
 import {Router, ActivatedRoute, ParamMap, RouterEvent, NavigationEnd} from '@angular/router';
 import {StaffCommonModule} from '@eg/staff/common.module';
@@ -6,6 +8,7 @@ import {IdlService, IdlObject} from '@eg/core/idl.service';
 import {PcrudService} from '@eg/core/pcrud.service';
 import {AcqProviderSummaryPaneComponent} from './summary-pane.component';
 import {ProviderDetailsComponent} from './provider-details.component';
+import {ProviderResultsComponent} from './provider-results.component';
 import {ProviderRecordService} from './provider-record.service';
 import {FmRecordEditorComponent} from '@eg/share/fm-editor/fm-editor.component';
 import {StringComponent} from '@eg/share/string/string.component';
@@ -25,6 +28,7 @@ export class AcqProviderComponent implements OnInit, AfterViewInit {
     validTabTypes = ['details', 'addresses', 'contacts', 'attributes', 'holdings', 'edi_accounts', 'purchase_orders', 'invoices'];
     defaultTabType = 'details';
     @ViewChild('acqSearchProviderSummary', { static: true }) providerSummaryPane: AcqProviderSummaryPaneComponent;
+    @ViewChild('acqProviderResults', { static: true }) acqProviderResults: ProviderResultsComponent;
     @ViewChild('providerDetails', { static: false }) providerDetails: ProviderDetailsComponent;
     @ViewChild('createDialog', { static: true }) createDialog: FmRecordEditorComponent;
     @ViewChild('createString', { static: false }) createString: StringComponent;
@@ -35,6 +39,9 @@ export class AcqProviderComponent implements OnInit, AfterViewInit {
     onDesireSummarize: ($event: number, updateSummaryOnly?: boolean) => void;
     onSummaryToggled: ($event: boolean) => void;
 
+    previousUrl: string = null;
+    public destroyed = new Subject<any>();
+
     constructor(
         private router: Router,
         private route: ActivatedRoute,
@@ -46,6 +53,19 @@ export class AcqProviderComponent implements OnInit, AfterViewInit {
         private store: StoreService,
         private changeDetector: ChangeDetectorRef
     ) {
+        this.router.events.pipe(
+            filter((event: RouterEvent) => event instanceof NavigationEnd),
+            takeUntil(this.destroyed)
+        ).subscribe(routeEvent => {
+            if (routeEvent instanceof NavigationEnd) {
+                if (this.previousUrl != null &&
+                    routeEvent.url === '/staff/acq/provider' &&
+                    this.previousUrl === routeEvent.url) {
+                    this.acqProviderResults.resetSearch();
+                }
+                this.previousUrl = routeEvent.url
+            }
+        });
     }
 
     ngOnInit() {
@@ -113,6 +133,11 @@ export class AcqProviderComponent implements OnInit, AfterViewInit {
         this.changeDetector.detectChanges();
     }
 
+    ngOnDestroy(): void {
+        this.destroyed.next();
+        this.destroyed.complete();
+    }
+
     setDefaultTab() {
         this.defaultTabType = this.activeTab;
         this.store.setLocalItem('eg.acq.provider.default_tab', this.activeTab);
index 1c670b0..e5dba5b 100644 (file)
@@ -60,6 +60,11 @@ export class ProviderResultsComponent implements OnInit {
         }
     }
 
+    resetSearch() {
+        this.providerSearchForm.clearSearch();
+        setTimeout(x => this.providerSearchForm.submitSearch());
+    }
+
     doSearch(search: AcqProviderSearch) {
         setTimeout(() => {
             this.providerSearch.setSearch(search);