1 import {Component, OnInit, AfterViewInit, Input, Output, EventEmitter} from '@angular/core';
2 import {Router, ActivatedRoute, ParamMap} from '@angular/router';
3 import {tap} from 'rxjs/operators';
4 import {Pager} from '@eg/share/util/pager';
5 import {IdlObject} from '@eg/core/idl.service';
6 import {NetService} from '@eg/core/net.service';
7 import {AuthService} from '@eg/core/auth.service';
8 import {LineitemService, BatchLineitemStruct} from './lineitem.service';
9 import {ComboboxEntry} from '@eg/share/combobox/combobox.component';
12 templateUrl: 'detail.component.html'
14 export class LineitemDetailComponent implements OnInit {
21 private route: ActivatedRoute,
22 private net: NetService,
23 private auth: AuthService,
24 private liService: LineitemService
29 this.route.paramMap.subscribe((params: ParamMap) => {
30 const id = +params.get('lineitemId');
31 if (id !== this.lineitemId) {
33 if (id) { this.load(); }
37 this.liService.getLiAttrDefs();
42 // Avoid pulling from cache since li's do not have marc()
43 // fleshed by default.
44 return this.liService.getFleshedLineitems([this.lineitemId], {
45 toCache: true, // OK to cache with marc()
46 fleshMore: {clear_marc: false}
47 }).pipe(tap(liStruct => this.lineitem = liStruct.lineitem)).toPromise();
50 attrLabel(attr: IdlObject): string {
51 if (!this.liService.liAttrDefs) { return; }
53 const def = this.liService.liAttrDefs.filter(
54 d => d.id() === attr.definition())[0];
56 return def ? def.description() : '';
59 saveMarcChanges(changes) { // MarcSavedEvent
60 const xml = changes.marcXml;
61 this.lineitem.marc(xml);
62 this.liService.updateLineitems([this.lineitem]).toPromise()
63 .then(_ => this.load());