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';
13 const ANGJS_TABS: any = {
21 selector: 'eg-catalog-record',
22 templateUrl: 'record.component.html'
24 export class RecordComponent implements OnInit {
28 summary: BibRecordSummary;
29 searchContext: CatalogSearchContext;
30 @ViewChild('recordTabs') recordTabs: NgbTabset;
31 defaultTab: string; // eg.cat.default_record_tab
34 private router: Router,
35 private route: ActivatedRoute,
36 private pcrud: PcrudService,
37 private bib: BibRecordService,
38 private cat: CatalogService,
39 private staffCat: StaffCatalogService,
40 private store: StoreService
44 this.searchContext = this.staffCat.searchContext;
47 this.store.getLocalItem('eg.cat.default_record_tab')
50 // TODO: Implement default tab handling for tabs that require
51 // and AngJS redirect.
53 // Watch for URL record ID changes
54 // This includes the initial route.
55 // When applying the default configured tab, no navigation occurs
56 // to apply the tab name to the URL, it displays as the default.
57 // This is done so no intermediate redirect is required, which
58 // messes with browser back/forward navigation.
59 this.route.paramMap.subscribe((params: ParamMap) => {
60 this.recordTab = params.get('tab');
61 this.recordId = +params.get('id');
62 this.searchContext = this.staffCat.searchContext;
64 if (!this.recordTab) {
65 this.recordTab = this.defaultTab || 'catalog';
66 // On initial load, if the default tab is set to one of
67 // the AngularJS tabs, redirect the user there.
68 if (this.recordTab in ANGJS_TABS) {
69 return this.routeToTab();
78 this.defaultTab = this.recordTab;
79 this.store.setLocalItem('eg.cat.default_record_tab', this.recordTab);
82 // Changing a tab in the UI means changing the route.
83 // Changing the route ultimately results in changing the tab.
84 onTabChange(evt: NgbTabChangeEvent) {
85 this.recordTab = evt.nextId;
87 // prevent tab changing until after route navigation
95 // Route to the AngularJS catalog tab
96 if (this.recordTab in ANGJS_TABS) {
97 const angjsBase = '/eg/staff/cat/catalog/record';
99 window.location.href =
100 `${angjsBase}/${this.recordId}/${this.recordTab}`;
105 `/staff/catalog/record/${this.recordId}/${this.recordTab}`;
107 // Retain search parameters
108 this.router.navigate([url], {queryParamsHandling: 'merge'});
113 // Avoid re-fetching the same record summary during tab navigation.
114 if (this.staffCat.currentDetailRecordSummary &&
115 this.recordId === this.staffCat.currentDetailRecordSummary.id) {
116 this.summary = this.staffCat.currentDetailRecordSummary;
121 this.bib.getBibSummary(
123 this.searchContext.searchOrg.id(),
124 this.searchContext.searchOrg.ou_type().depth()).toPromise()
127 this.staffCat.currentDetailRecordSummary = summary;
128 this.bib.fleshBibUsers([summary.record]);