-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';
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,
// 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) {