From: Galen Charlton Date: Tue, 13 Jul 2021 14:11:29 +0000 (-0400) Subject: LP#1912852: add jump-on-one-hit support to Angular staff catalog X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=efdf28d789eabf616ca5284014d605b8757f6576;p=working%2FEvergreen.git LP#1912852: add jump-on-one-hit support to Angular staff catalog 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 Signed-off-by: Jason Boyer Signed-off-by: Jason Etheridge --- diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/catalog.service.ts b/Open-ILS/src/eg2/src/app/staff/catalog/catalog.service.ts index 9c2155fdcc..04eb852de5 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/catalog.service.ts +++ b/Open-ILS/src/eg2/src/app/staff/catalog/catalog.service.ts @@ -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, diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/resolver.service.ts b/Open-ILS/src/eg2/src/app/staff/catalog/resolver.service.ts index f7e956224d..11c46ff4c2 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/resolver.service.ts +++ b/Open-ILS/src/eg2/src/app/staff/catalog/resolver.service.ts @@ -58,7 +58,8 @@ export class CatalogResolver implements Resolve> { '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> { 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; }); } } diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/result/results.component.ts b/Open-ILS/src/eg2/src/app/staff/catalog/result/results.component.ts index 61be085848..f4e42c1073 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/result/results.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/catalog/result/results.component.ts @@ -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() {