LP#1775466 Catalog record tabs continued
authorBill Erickson <berickxx@gmail.com>
Sat, 2 Jun 2018 17:06:09 +0000 (13:06 -0400)
committerBill Erickson <berickxx@gmail.com>
Wed, 6 Jun 2018 20:59:42 +0000 (16:59 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/staff/catalog/catalog.service.ts
Open-ILS/src/eg2/src/app/staff/catalog/record/record.component.html
Open-ILS/src/eg2/src/app/staff/catalog/record/record.component.ts
Open-ILS/src/eg2/src/app/staff/catalog/routing.module.ts

index 1519729..fb8eace 100644 (file)
@@ -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,
index 5203677..263375b 100644 (file)
@@ -11,7 +11,7 @@
     </eg-bib-summary>
   </div>
   <div id='staff-catalog-bib-tabs-container' class='mt-3'>
-    <ngb-tabset>
+    <ngb-tabset #recordTabs [activeId]="recordTab" (tabChange)="onTabChange($event)">
       <ngb-tab title="Copy Table" i18n-title id="copy_table">
         <ng-template ngbTabContent>
           <eg-catalog-copies [recordId]="recordId"></eg-catalog-copies>
index b07d21e..0875cb9 100644 (file)
@@ -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) {
index 068d033..12bf173 100644 (file)
@@ -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
   }]
 }];