LP#1912852: add jump-on-one-hit support to Angular staff catalog
authorGalen Charlton <gmc@equinoxOLI.org>
Tue, 13 Jul 2021 14:11:29 +0000 (10:11 -0400)
committerJason Etheridge <jason@EquinoxOLI.org>
Fri, 13 Aug 2021 20:32:55 +0000 (16:32 -0400)
This patch add support for the opac.staff.jump_to_details_on_single_hit
library setting to the Angular staff catalog.

To test
-------
[1] Apply the patch.
[2] Ensure that the opac.staff.jump_to_details_on_single_hit setting
    is off for your workstation.
[3] Perform searches using the Angular staff catalog. Verifying that
    searches that return any number of results display them on the
    results page.
[4] Set the library setting to true and reload the staff catalog.
[5] Perform keyword, numeric, and MARC searches using terms that
    result in a single-record result set. Verify that the interface
    redirects to the single-record page for that hit.
[6] Perform searches that would return zero results. Verify that
    the results page indicates zero hits fuond.
[7] Perform searches that would return more than one result. Verify
    that the results are displayed on the results page.

Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
Signed-off-by: Jason Boyer <JBoyer@equinoxOLI.org>
Signed-off-by: Jason Etheridge <jason@EquinoxOLI.org>
Open-ILS/src/eg2/src/app/staff/catalog/catalog.service.ts
Open-ILS/src/eg2/src/app/staff/catalog/resolver.service.ts
Open-ILS/src/eg2/src/app/staff/catalog/result/results.component.ts

index 9c2155f..04eb852 100644 (file)
@@ -52,6 +52,10 @@ export class StaffCatalogService {
     // re-run the browse search on each navigation.
     browsePagerData: any[];
 
+    // whether to redirect to record page upon a single search
+    // result
+    jumpOnSingleHit = false;
+
     constructor(
         private router: Router,
         private route: ActivatedRoute,
index f7e9562..11c46ff 100644 (file)
@@ -58,7 +58,8 @@ export class CatalogResolver implements Resolve<Promise<any[]>> {
             'eg.staffcat.exclude_electronic',
             'eg.catalog.search.form.open',
             'eg.staff.catalog.results.show_more',
-            'circ.staff_placed_holds_fallback_to_ws_ou'
+            'circ.staff_placed_holds_fallback_to_ws_ou',
+            'opac.staff.jump_to_details_on_single_hit',
         ]).then(settings => {
             this.staffCat.defaultSearchOrg =
                 this.org.get(settings['eg.search.search_lib']);
@@ -73,6 +74,8 @@ export class CatalogResolver implements Resolve<Promise<any[]>> {
                 settings['opac.search.enable_bookplate_search'];
             this.staffCat.showExcludeElectronic =
                 settings['eg.staffcat.exclude_electronic'] === true;
+            this.staffCat.jumpOnSingleHit =
+                settings['opac.staff.jump_to_details_on_single_hit'] === true;
         });
     }
 }
index 61be085..f4e42c1 100644 (file)
@@ -1,7 +1,7 @@
 import {Component, OnInit, OnDestroy, Input} from '@angular/core';
 import {Observable, Subscription} from 'rxjs';
 import {tap, map, switchMap, distinctUntilChanged} from 'rxjs/operators';
-import {ActivatedRoute, ParamMap} from '@angular/router';
+import {Router, ActivatedRoute, ParamMap} from '@angular/router';
 import {CatalogService} from '@eg/share/catalog/catalog.service';
 import {BibRecordService} from '@eg/share/catalog/bib-record.service';
 import {CatalogUrlService} from '@eg/share/catalog/catalog-url.service';
@@ -39,7 +39,8 @@ export class ResultsComponent implements OnInit, OnDestroy {
         private catUrl: CatalogUrlService,
         private staffCat: StaffCatalogService,
         private serverStore: ServerStoreService,
-        private basket: BasketService
+        private basket: BasketService,
+        private router: Router
     ) {}
 
     ngOnInit() {
@@ -66,9 +67,12 @@ export class ResultsComponent implements OnInit, OnDestroy {
         });
 
         // After each completed search, update the record selector.
-        this.searchSub = this.cat.onSearchComplete.subscribe(ctx => {
-            this.applyRecordSelection();
-        });
+        this.searchSub = this.cat.onSearchComplete.subscribe(
+            ctx => {
+                this.jumpIfNecessary();
+                this.applyRecordSelection();
+            }
+        );
 
         // Watch for basket changes applied by other components.
         this.basketSub = this.basket.onChange.subscribe(
@@ -83,6 +87,16 @@ export class ResultsComponent implements OnInit, OnDestroy {
         }
     }
 
+    // Jump to record page if only a single hit is returned
+    // and the jump is enabled by library setting
+    jumpIfNecessary() {
+        const ids = this.searchContext.currentResultIds();
+        if (this.staffCat.jumpOnSingleHit && ids.length === 1) {
+           // this.router.navigate(['/staff/catalog/record/' + ids[0], { queryParams: this.catUrl.toUrlParams(this.searchContext) }]);
+            this.router.navigate(['/staff/catalog/record/' + ids[0]], {queryParamsHandling: 'merge'});
+        }
+    }
+
     // Apply the select-all checkbox when all visible records
     // are selected.
     applyRecordSelection() {