LP1904036 Tracking/showing recent patrons
authorBill Erickson <berickxx@gmail.com>
Thu, 29 Apr 2021 21:24:58 +0000 (17:24 -0400)
committerGalen Charlton <gmc@equinoxOLI.org>
Fri, 28 Oct 2022 00:13:34 +0000 (20:13 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Jane Sandberg <js7389@princeton.edu>
Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
Open-ILS/src/eg2/src/app/staff/circ/patron/patron.component.html
Open-ILS/src/eg2/src/app/staff/circ/patron/patron.component.ts
Open-ILS/src/eg2/src/app/staff/circ/patron/patron.service.ts
Open-ILS/src/eg2/src/app/staff/circ/patron/routing.module.ts
Open-ILS/src/eg2/src/app/staff/share/patron/search.component.ts

index f2c2aa7..9dfc6b3 100644 (file)
           <ng-template ngbNavContent>
             <div class="">
               <eg-patron-search
+                [patronIds]="recentPatronIds()"
                 [startWithSearch]="context.lastPatronSearch"
                 (searchFired)="patronSearchFired($event)"
                 (selectionChange)="patronSelectionChange($event)"
index 5aa70fd..4917db2 100644 (file)
@@ -7,6 +7,7 @@ import {NetService} from '@eg/core/net.service';
 import {AuthService} from '@eg/core/auth.service';
 import {PcrudService} from '@eg/core/pcrud.service';
 import {EventService} from '@eg/core/event.service';
+import {StoreService} from '@eg/core/store.service';
 import {ServerStoreService} from '@eg/core/server-store.service';
 import {PatronService} from '@eg/staff/share/patron/patron.service';
 import {PatronContextService, BillGridEntry} from './patron.service';
@@ -34,6 +35,7 @@ export class PatronComponent implements OnInit, AfterViewInit {
     billingHistoryTab: string;
     showSummary = true;
     loading = true;
+    showRecentPatrons = false;
 
     /* eg-patron-edit is unable to find #editorToolbar directly
      * within the template.  Adding a ref here allows it to
@@ -58,7 +60,8 @@ export class PatronComponent implements OnInit, AfterViewInit {
         private auth: AuthService,
         private pcrud: PcrudService,
         private evt: EventService,
-        private store: ServerStoreService,
+        private store: StoreService,
+        private serverStore: ServerStoreService,
         public patronService: PatronService,
         public context: PatronContextService
     ) {}
@@ -99,15 +102,27 @@ export class PatronComponent implements OnInit, AfterViewInit {
 
     fetchSettings(): Promise<any> {
 
-        return this.store.getItemBatch([
+        return this.serverStore.getItemBatch([
             'eg.circ.patron.summary.collapse'
         ]).then(prefs => {
             this.showSummary = !prefs['eg.circ.patron.summary.collapse'];
         });
     }
 
+    recentPatronIds(): number[] {
+        if (this.patronTab === 'search' && this.showRecentPatrons) {
+            return this.store.getLoginSessionItem('eg.circ.recent_patrons') || [];
+        } else {
+            return null;
+        }
+    }
+
     watchForTabChange() {
 
+        this.route.data.subscribe(data => {
+            this.showRecentPatrons = (data && data.showRecentPatrons);
+        });
+
         this.route.paramMap.subscribe((params: ParamMap) => {
             this.patronTab = params.get('tab') || 'search';
             this.patronId = +params.get('id');
@@ -188,7 +203,7 @@ export class PatronComponent implements OnInit, AfterViewInit {
     }
 
     toggleSummaryPane() {
-        this.store.setItem( // collapse is the opposite of show
+        this.serverStore.setItem( // collapse is the opposite of show
             'eg.circ.patron.summary.collapse', this.showSummary);
         this.showSummary = !this.showSummary;
     }
index ac31438..41940b6 100644 (file)
@@ -89,7 +89,7 @@ export class PatronContextService {
         .then(p => this.summary = new PatronSummary(p))
         .then(_ => this.getPatronStats(id))
         .then(_ => this.compileAlerts())
-        .then(_ => this.addRecentPatron())
+        .then(_ => this.addRecentPatron());
     }
 
     addRecentPatron(): Promise<any> {
index 04fec6b..4d49e4f 100644 (file)
@@ -40,6 +40,11 @@ const routes: Routes = [{
     component: PatronComponent,
     resolve: {resolver : PatronResolver}
   }, {
+    path: 'search/recents',
+    component: PatronComponent,
+    resolve: {resolver : PatronResolver},
+    data: {showRecentPatrons: true}
+  }, {
     path: 'bcsearch',
     component: BcSearchComponent
   }, {
index 67b7369..8ca36a9 100644 (file)
@@ -1,8 +1,8 @@
 import {Component, Input, Output, OnInit, AfterViewInit,
     EventEmitter, ViewChild} from '@angular/core';
 import {ActivatedRoute, ParamMap} from '@angular/router';
-import {Observable, of} from 'rxjs';
-import {map} from 'rxjs/operators';
+import {Observable, of, from} from 'rxjs';
+import {map, concatMap} from 'rxjs/operators';
 import {IdlObject} from '@eg/core/idl.service';
 import {NetService} from '@eg/core/net.service';
 import {AuthService} from '@eg/core/auth.service';
@@ -58,6 +58,9 @@ export class PatronSearchComponent implements OnInit, AfterViewInit {
     startWithFired = false;
     @Input() startWithSearch: PatronSearch;
 
+    // If set, load a batch of patrons by ID.
+    @Input() patronIds: number[];
+
     // Fires on dbl-click or Enter while one or more search result
     // rows are selected.
     @Output() patronsActivated: EventEmitter<any>;
@@ -162,8 +165,11 @@ export class PatronSearchComponent implements OnInit, AfterViewInit {
 
         let observable: Observable<IdlObject>;
 
-        if (this.search.id) {
-            observable = this.searchById();
+        if (this.patronIds) {
+            observable = this.searchById(this.patronIds);
+            this.patronIds = null;
+        } else if (this.search.id) {
+            observable = this.searchById([this.search.id]);
         } else {
             observable = this.searchByForm(pager, sort);
         }
@@ -223,12 +229,14 @@ export class PatronSearchComponent implements OnInit, AfterViewInit {
         );
     }
 
-    searchById(): Observable<IdlObject> {
-        return this.net.request(
-            'open-ils.actor',
-            'open-ils.actor.user.fleshed.retrieve',
-            this.auth.token(), this.search.id, DEFAULT_FLESH
-        );
+    searchById(patronIds: number[]): Observable<IdlObject> {
+        return from(patronIds).pipe(concatMap(id => {
+            return this.net.request(
+                'open-ils.actor',
+                'open-ils.actor.user.fleshed.retrieve',
+                this.auth.token(), id, DEFAULT_FLESH
+            );
+        }));
     }
 
     compileSort(sort: any[]): string[] {