Docs: merge 3.2 release notes
[working/Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / catalog / record / record.component.ts
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
12 @Component({
13   selector: 'eg-catalog-record',
14   templateUrl: 'record.component.html'
15 })
16 export class RecordComponent implements OnInit {
17
18     recordId: number;
19     recordTab: string;
20     summary: BibRecordSummary;
21     searchContext: CatalogSearchContext;
22     @ViewChild('recordTabs') recordTabs: NgbTabset;
23
24     constructor(
25         private router: Router,
26         private route: ActivatedRoute,
27         private pcrud: PcrudService,
28         private bib: BibRecordService,
29         private cat: CatalogService,
30         private staffCat: StaffCatalogService
31     ) {}
32
33     ngOnInit() {
34         this.searchContext = this.staffCat.searchContext;
35
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;
41             this.loadRecord();
42         });
43     }
44
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;
49
50         // prevent tab changing until after route navigation
51         evt.preventDefault();
52
53         let url = '/staff/catalog/record/' + this.recordId;
54         if (this.recordTab !== 'copy_table') {
55             url += '/' + this.recordTab;
56         }
57
58         // Retain search parameters
59         this.router.navigate([url], {queryParamsHandling: 'merge'});
60     }
61
62     loadRecord(): void {
63
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;
68             return;
69         }
70
71         this.summary = null;
72         this.bib.getBibSummary(
73             this.recordId,
74             this.searchContext.searchOrg.id(),
75             this.searchContext.searchOrg.ou_type().depth()).toPromise()
76         .then(summary => {
77             this.summary =
78                 this.staffCat.currentDetailRecordSummary = summary;
79             this.bib.fleshBibUsers([summary.record]);
80         });
81     }
82 }
83
84