From: Galen Charlton Date: Wed, 9 Sep 2020 16:31:28 +0000 (-0400) Subject: LP#1857150: adjust routing and single vs. double-click actions X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=421d912c9d081aea64b5fd0b0c5aab566309c5dd;p=evergreen%2Fmasslnc.git LP#1857150: adjust routing and single vs. double-click actions This patch adjusts the routing to use a custom matcher so that the base AcqProviderComponent doesn't get reinitalized unecessarily when moving from the search form to a provider record and back. It also ensures that when starting from the search form, single-clicking a result won't hide the search form, while double-clicking will. Signed-off-by: Galen Charlton Signed-off-by: Ruth Frasur Signed-off-by: Bill Erickson Signed-off-by: Jason Etheridge --- 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 69aebda85c..74137070fc 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 @@ -36,7 +36,7 @@

{{providerRecord.currentProvider?.record.name()}} ({{providerRecord.currentProvider?.record.code()}})

-
+
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 895407bc7d..7eb6899aa0 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 @@ -64,9 +64,10 @@ export class AcqProviderComponent implements OnInit, AfterViewInit, OnDestroy { ).subscribe(routeEvent => { if (routeEvent instanceof NavigationEnd) { if (this.previousUrl != null && - routeEvent.url === '/staff/acq/provider' && - this.previousUrl === routeEvent.url) { + routeEvent.url === '/staff/acq/provider') { this.acqProviderResults.resetSearch(); + this.showSearchForm = true; + this.id = null; } this.previousUrl = routeEvent.url; } @@ -82,8 +83,17 @@ export class AcqProviderComponent implements OnInit, AfterViewInit, OnDestroy { this.defaultTabType = this.store.getLocalItem('eg.acq.provider.default_tab') || 'details'; + const keepSearchForm = history.state.hasOwnProperty('keepSearchForm') ? + history.state.keepSearchForm : + false; + if (keepSearchForm) { + this.showSearchForm = true; + } + if (idParam) { - this.showSearchForm = false; + if (!keepSearchForm) { + this.showSearchForm = false; + } this.id = idParam; if (!tabTypeParam) { this.activeTab = this.defaultTabType; @@ -92,7 +102,9 @@ export class AcqProviderComponent implements OnInit, AfterViewInit, OnDestroy { } if (tabTypeParam) { - this.showSearchForm = false; + if (!keepSearchForm) { + this.showSearchForm = false; + } if (this.validTabTypes.includes(tabTypeParam)) { this.activeTab = tabTypeParam; } else { @@ -132,7 +144,10 @@ export class AcqProviderComponent implements OnInit, AfterViewInit, OnDestroy { this.showSearchForm = false; } this.activeTab = this.defaultTabType; - this.router.navigate(['/staff', 'acq', 'provider', this.id, this.activeTab]); + this.router.navigate( + ['/staff', 'acq', 'provider', this.id, this.activeTab], + { state: { keepSearchForm: !hideSearchForm } } + ); }); }; diff --git a/Open-ILS/src/eg2/src/app/staff/acq/provider/routing.module.ts b/Open-ILS/src/eg2/src/app/staff/acq/provider/routing.module.ts index c8e0686816..32f678580d 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/provider/routing.module.ts +++ b/Open-ILS/src/eg2/src/app/staff/acq/provider/routing.module.ts @@ -1,19 +1,37 @@ import {NgModule} from '@angular/core'; -import {RouterModule, Routes} from '@angular/router'; +import {RouterModule, Routes, UrlMatchResult} from '@angular/router'; import {AcqProviderComponent} from './acq-provider.component'; import {ProviderResolver, CanLeaveAcqProviderGuard} from './resolver.service'; const routes: Routes = [ - { path: '', - component: AcqProviderComponent, - runGuardsAndResolvers: 'always' - }, - { path: ':id', - component: AcqProviderComponent, - resolve: { providerResolver : ProviderResolver }, - runGuardsAndResolvers: 'always' - }, - { path: ':id/:tab', + { matcher: (segments) => { + // using a custom matcher so that we + // don't force a component re-initialization + // when navigating from the search form to a + // provider record + if (segments.length === 0) { + return { + consumed: segments, + posParams: {} + }; + } else if (segments.length === 1) { + return { + consumed: segments, + posParams: { + id: segments[0], + } + }; + } else if (segments.length > 1) { + return { + consumed: segments, + posParams: { + id: segments[0], + tab: segments[1], + } + }; + } + return (null as any); + }, component: AcqProviderComponent, resolve: { providerResolver : ProviderResolver }, canDeactivate: [CanLeaveAcqProviderGuard],