From de96ddf2e0a9a56ae44e11b176abdd6cc8601363 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Mon, 17 Aug 2020 17:25:08 -0400 Subject: [PATCH] clear search form and redo default search if same-URL-navigated Signed-off-by: Galen Charlton --- .../staff/acq/provider/acq-provider.component.html | 2 +- .../staff/acq/provider/acq-provider.component.ts | 27 +++++++++++++++++++++- .../acq/provider/provider-results.component.ts | 5 ++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider.component.html b/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider.component.html index bf25eae379..a1167b4ebd 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider.component.html +++ b/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider.component.html @@ -24,7 +24,7 @@
- +
diff --git a/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider.component.ts b/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider.component.ts index 3130ccbe7e..a3aa44fe96 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider.component.ts @@ -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(); + 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); diff --git a/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-results.component.ts b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-results.component.ts index 1c670b0964..e5dba5b9f2 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-results.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-results.component.ts @@ -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); -- 2.11.0