import {BibRecordService, BibRecordSummary} from '@eg/share/catalog/bib-record.service';
import {StaffCatalogService} from '../catalog.service';
import {BibSummaryComponent} from '@eg/staff/share/bib-summary/bib-summary.component';
+import {StoreService} from '@eg/core/store.service';
@Component({
selector: 'eg-catalog-record',
summary: BibRecordSummary;
searchContext: CatalogSearchContext;
@ViewChild('recordTabs') recordTabs: NgbTabset;
+ defaultTab: string; // eg.cat.default_record_tab
constructor(
private router: Router,
private pcrud: PcrudService,
private bib: BibRecordService,
private cat: CatalogService,
- private staffCat: StaffCatalogService
+ private staffCat: StaffCatalogService,
+ private store: StoreService
) {}
ngOnInit() {
this.searchContext = this.staffCat.searchContext;
+ this.defaultTab =
+ this.store.getLocalItem('eg.cat.default_record_tab')
+ || 'catalog';
+
// Watch for URL record ID changes
+ // This includes the initial route.
+ // When applying the default configured tab, no navigation occurs
+ // to apply the tab name to the URL, it displays as the default.
+ // This is done so no intermediate redirect is required, which
+ // messes with browser back/forward navigation.
this.route.paramMap.subscribe((params: ParamMap) => {
- this.recordTab = params.get('tab') || 'copy_table';
+ this.recordTab = params.get('tab');
this.recordId = +params.get('id');
this.searchContext = this.staffCat.searchContext;
+
+ if (!this.recordTab) {
+ this.recordTab = this.defaultTab || 'catalog';
+ }
+
this.loadRecord();
});
}
+ setDefaultTab() {
+ this.defaultTab = this.recordTab;
+ this.store.setLocalItem('eg.cat.default_record_tab', this.recordTab);
+ }
+
// Changing a tab in the UI means changing the route.
// Changing the route ultimately results in changing the tab.
onTabChange(evt: NgbTabChangeEvent) {
// prevent tab changing until after route navigation
evt.preventDefault();
- let url = '/staff/catalog/record/' + this.recordId;
- if (this.recordTab !== 'copy_table') {
- url += '/' + this.recordTab;
- }
+ this.routeToTab();
+ }
+
+ routeToTab() {
+ const url =
+ `/staff/catalog/record/${this.recordId}/${this.recordTab}`;
// Retain search parameters
this.router.navigate([url], {queryParamsHandling: 'merge'});