From: Bill Erickson Date: Tue, 9 Nov 2021 18:49:07 +0000 (-0500) Subject: LP1904036 Refresh patron data when returning to patron X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=200d527b15caf3c228d83dc3af149e2fd0ab94d6;p=Evergreen.git LP1904036 Refresh patron data when returning to patron Since patron data is cached at the service level within Angular navigation. Signed-off-by: Bill Erickson Signed-off-by: Jane Sandberg Signed-off-by: Galen Charlton --- diff --git a/Open-ILS/src/eg2/src/app/staff/circ/patron/patron.component.ts b/Open-ILS/src/eg2/src/app/staff/circ/patron/patron.component.ts index 38af2b8fd1..0684348e54 100644 --- a/Open-ILS/src/eg2/src/app/staff/circ/patron/patron.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/circ/patron/patron.component.ts @@ -1,8 +1,8 @@ import {Component, ViewChild, OnInit, AfterViewInit, HostListener} from '@angular/core'; -import {Router, ActivatedRoute, ParamMap} from '@angular/router'; +import {Router, ActivatedRoute, ParamMap, RoutesRecognized} from '@angular/router'; import {NgbNav, NgbNavChangeEvent} from '@ng-bootstrap/ng-bootstrap'; import {Observable, throwError, empty} from 'rxjs'; -import {concatMap, tap} from 'rxjs/operators'; +import {filter, pairwise, concatMap, tap} from 'rxjs/operators'; import {NetService} from '@eg/core/net.service'; import {AuthService} from '@eg/core/auth.service'; import {PcrudService} from '@eg/core/pcrud.service'; @@ -36,6 +36,7 @@ export class PatronComponent implements OnInit, AfterViewInit { showSummary = true; loading = true; showRecentPatrons = false; + refreshing = false; /* eg-patron-edit is unable to find #editorToolbar directly * within the template. Adding a ref here allows it to @@ -119,6 +120,24 @@ export class PatronComponent implements OnInit, AfterViewInit { watchForTabChange() { + // When routing to a patron UI from a non-patron UI, refresh the + // patron's data so we pick up an external changes (e.g. holds + // placement). This is needed because the last active patron, + // if one exists, will still be cached in the patron service, + // which survives route changes. Route events occur in series + // and often repeat, though, so avoid refreshing the patron if + // we are already mid-refresh. + this.router.events + .pipe(filter((evt: any) => evt instanceof RoutesRecognized), pairwise()) + .subscribe((events: RoutesRecognized[]) => { + const prevUrl = events[0].urlAfterRedirects; + + if (!prevUrl.startsWith('/staff/circ/patron') && !this.refreshing) { + this.refreshing = true; + this.context.refreshPatron().then(_ => this.refreshing = false); + } + }); + this.route.data.subscribe(data => { this.showRecentPatrons = (data && data.showRecentPatrons); });