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';
11 import {StoreService} from '@eg/core/store.service';
14 selector: 'eg-catalog-record',
15 templateUrl: 'record.component.html'
17 export class RecordComponent implements OnInit {
21 summary: BibRecordSummary;
22 searchContext: CatalogSearchContext;
23 @ViewChild('recordTabs') recordTabs: NgbTabset;
24 defaultTab: string; // eg.cat.default_record_tab
27 private router: Router,
28 private route: ActivatedRoute,
29 private pcrud: PcrudService,
30 private bib: BibRecordService,
31 private cat: CatalogService,
32 private staffCat: StaffCatalogService,
33 private store: StoreService
37 this.searchContext = this.staffCat.searchContext;
40 this.store.getLocalItem('eg.cat.default_record_tab')
43 // Watch for URL record ID changes
44 // This includes the initial route.
45 // When applying the default configured tab, no navigation occurs
46 // to apply the tab name to the URL, it displays as the default.
47 // This is done so no intermediate redirect is required, which
48 // messes with browser back/forward navigation.
49 this.route.paramMap.subscribe((params: ParamMap) => {
50 this.recordTab = params.get('tab');
51 this.recordId = +params.get('id');
52 this.searchContext = this.staffCat.searchContext;
54 if (!this.recordTab) {
55 this.recordTab = this.defaultTab || 'catalog';
63 this.defaultTab = this.recordTab;
64 this.store.setLocalItem('eg.cat.default_record_tab', this.recordTab);
67 // Changing a tab in the UI means changing the route.
68 // Changing the route ultimately results in changing the tab.
69 onTabChange(evt: NgbTabChangeEvent) {
70 this.recordTab = evt.nextId;
72 // prevent tab changing until after route navigation
80 `/staff/catalog/record/${this.recordId}/${this.recordTab}`;
82 // Retain search parameters
83 this.router.navigate([url], {queryParamsHandling: 'merge'});
88 // Avoid re-fetching the same record summary during tab navigation.
89 if (this.staffCat.currentDetailRecordSummary &&
90 this.recordId === this.staffCat.currentDetailRecordSummary.id) {
91 this.summary = this.staffCat.currentDetailRecordSummary;
96 this.bib.getBibSummary(
98 this.searchContext.searchOrg.id(),
99 this.searchContext.searchOrg.ou_type().depth()).toPromise()
102 this.staffCat.currentDetailRecordSummary = summary;
103 this.bib.fleshBibUsers([summary.record]);
107 currentSearchOrg(): IdlObject {
108 if (this.staffCat && this.staffCat.searchContext) {
109 return this.staffCat.searchContext.searchOrg;