-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';
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';
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;
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,
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() {
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);