1 import {Component, OnInit, Input, ViewChild} from '@angular/core';
2 import {NgbTabset, NgbTabChangeEvent} from '@ng-bootstrap/ng-bootstrap';
3 import {Router, ActivatedRoute, ParamMap} from '@angular/router';
4 import {PcrudService} from '@eg/core/pcrud.service';
5 import {IdlObject} from '@eg/core/idl.service';
6 import {CatalogSearchContext, CatalogSearchState} from '@eg/share/catalog/search-context';
7 import {CatalogService} from '@eg/share/catalog/catalog.service';
8 import {BibRecordService, BibRecordSummary} from '@eg/share/catalog/bib-record.service';
9 import {StaffCatalogService} from '../catalog.service';
10 import {BibSummaryComponent} from '@eg/staff/share/bib-summary/bib-summary.component';
13 selector: 'eg-catalog-record',
14 templateUrl: 'record.component.html'
16 export class RecordComponent implements OnInit {
20 summary: BibRecordSummary;
21 searchContext: CatalogSearchContext;
22 @ViewChild('recordTabs') recordTabs: NgbTabset;
25 private router: Router,
26 private route: ActivatedRoute,
27 private pcrud: PcrudService,
28 private bib: BibRecordService,
29 private cat: CatalogService,
30 private staffCat: StaffCatalogService
34 this.searchContext = this.staffCat.searchContext;
36 // Watch for URL record ID changes
37 this.route.paramMap.subscribe((params: ParamMap) => {
38 this.recordTab = params.get('tab') || 'copy_table';
39 this.recordId = +params.get('id');
40 this.searchContext = this.staffCat.searchContext;
45 // Changing a tab in the UI means changing the route.
46 // Changing the route ultimately results in changing the tab.
47 onTabChange(evt: NgbTabChangeEvent) {
48 this.recordTab = evt.nextId;
50 // prevent tab changing until after route navigation
53 let url = '/staff/catalog/record/' + this.recordId;
54 if (this.recordTab !== 'copy_table') {
55 url += '/' + this.recordTab;
58 // Retain search parameters
59 this.router.navigate([url], {queryParamsHandling: 'merge'});
64 // Avoid re-fetching the same record summary during tab navigation.
65 if (this.staffCat.currentDetailRecordSummary &&
66 this.recordId === this.staffCat.currentDetailRecordSummary.id) {
67 this.summary = this.staffCat.currentDetailRecordSummary;
72 this.bib.getBibSummary(
74 this.searchContext.searchOrg.id(),
75 this.searchContext.searchOrg.ou_type().depth()).toPromise()
78 this.staffCat.currentDetailRecordSummary = summary;
79 this.bib.fleshBibUsers([summary.record]);