From 22e0a8114bfd7ddcb32ce00f27b7534285452883 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Sat, 2 Jun 2018 13:06:09 -0400 Subject: [PATCH] P#1626157 Catalog record tabs continued Signed-off-by: Bill Erickson --- .../eg2/src/app/staff/catalog/catalog.service.ts | 5 +++ .../app/staff/catalog/record/record.component.html | 2 +- .../app/staff/catalog/record/record.component.ts | 40 ++++++++++++++++++---- .../eg2/src/app/staff/catalog/routing.module.ts | 7 ++-- 4 files changed, 45 insertions(+), 9 deletions(-) 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 151972980d..fb8eace456 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 @@ -21,6 +21,11 @@ export class StaffCatalogService { // TODO: does unapi support pref-lib for result-page copy counts? prefOrg: EgIdlObject; + // Cache the currently selected detail record (i.g. catalog/record/123) + // summary so the record detail component can avoid duplicate fetches + // during record tab navigation. + currentDetailRecordSummary: any; + constructor( private router: Router, private route: ActivatedRoute, diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/record/record.component.html b/Open-ILS/src/eg2/src/app/staff/catalog/record/record.component.html index 520367768c..263375bc91 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/record/record.component.html +++ b/Open-ILS/src/eg2/src/app/staff/catalog/record/record.component.html @@ -11,7 +11,7 @@
- + diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/record/record.component.ts b/Open-ILS/src/eg2/src/app/staff/catalog/record/record.component.ts index b07d21ee1b..0875cb9abb 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/record/record.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/catalog/record/record.component.ts @@ -1,5 +1,6 @@ -import {Component, OnInit, Input} from '@angular/core'; -import {ActivatedRoute, ParamMap} from '@angular/router'; +import {Component, OnInit, Input, ViewChild} from '@angular/core'; +import {NgbTabset, NgbTabChangeEvent} from '@ng-bootstrap/ng-bootstrap'; +import {Router, ActivatedRoute, ParamMap} from '@angular/router'; import {EgPcrudService} from '@eg/core/pcrud.service'; import {EgIdlObject} from '@eg/core/idl.service'; import {CatalogSearchContext, CatalogSearchState} from '@eg/share/catalog/search-context'; @@ -14,10 +15,13 @@ import {EgBibSummaryComponent} from '@eg/staff/share/bib-summary/bib-summary.com export class RecordComponent implements OnInit { recordId: number; + recordTab: string; bibSummary: any; searchContext: CatalogSearchContext; + @ViewChild('recordTabs') recordTabs: NgbTabset; constructor( + private router: Router, private route: ActivatedRoute, private pcrud: EgPcrudService, private cat: EgCatalogService, @@ -29,23 +33,47 @@ export class RecordComponent implements OnInit { // Watch for URL record ID changes this.route.paramMap.subscribe((params: ParamMap) => { + this.recordTab = params.get('tab') || 'copy_table'; this.recordId = +params.get('id'); + this.searchContext = this.staffCat.searchContext; this.loadRecord(); }); } + // Changing a tab in the UI means changing the route. + // Changing the route ultimately results in changing the tab. + onTabChange(evt: NgbTabChangeEvent) { + this.recordTab = evt.nextId; + + // prevent tab changing until after route navigation + evt.preventDefault(); + + let url = '/staff/catalog/record/' + this.recordId; + if (this.recordTab !== 'copy_table') { + url += '/' + this.recordTab; + } + + // Retain search parameters + this.router.navigate([url], {queryParamsHandling: "merge"}); + } + loadRecord(): void { - this.searchContext = this.staffCat.searchContext; - // If a search is encoded in the URL, be sure we have the - // relevant search + // Avoid re-fetching the same record summary during tab navigation. + if (this.staffCat.currentDetailRecordSummary && + this.recordId === this.staffCat.currentDetailRecordSummary.id) { + this.bibSummary = this.staffCat.currentDetailRecordSummary; + return; + } + this.bibSummary = null; this.cat.getBibSummary( this.recordId, this.searchContext.searchOrg.id(), this.searchContext.searchOrg.ou_type().depth() ).then(summary => { - this.bibSummary = summary; + this.bibSummary = + this.staffCat.currentDetailRecordSummary = summary; this.pcrud.search('au', {id: [summary.creator, summary.editor]}) .subscribe(user => { if (user.id() === summary.creator) { diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/routing.module.ts b/Open-ILS/src/eg2/src/app/staff/catalog/routing.module.ts index 068d033a72..12bf1733c4 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/routing.module.ts +++ b/Open-ILS/src/eg2/src/app/staff/catalog/routing.module.ts @@ -11,10 +11,13 @@ const routes: Routes = [{ resolve: {catResolver : EgCatalogResolver}, children : [{ path: 'search', - component: ResultsComponent, + component: ResultsComponent }, { path: 'record/:id', - component: RecordComponent, + component: RecordComponent + }, { + path: 'record/:id/:tab', + component: RecordComponent }] }]; -- 2.11.0