]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/share/marc-edit/rich-editor.component.ts
LP1852782 Context menu nagivation and FF repairs
[working/Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / share / marc-edit / rich-editor.component.ts
1 import {Component, Input, Output, OnInit, AfterViewInit, EventEmitter,
2     OnDestroy} from '@angular/core';
3 import {filter} from 'rxjs/operators';
4 import {IdlService} from '@eg/core/idl.service';
5 import {OrgService} from '@eg/core/org.service';
6 import {TagTableService} from './tagtable.service';
7 import {MarcRecord, MarcField} from './marcrecord';
8 import {MarcEditContext} from './editor-context';
9
10
11 /**
12  * MARC Record rich editor interface.
13  */
14
15 @Component({
16   selector: 'eg-marc-rich-editor',
17   templateUrl: './rich-editor.component.html',
18   styleUrls: ['rich-editor.component.css']
19 })
20
21 export class MarcRichEditorComponent implements OnInit {
22
23     @Input() context: MarcEditContext;
24     get record(): MarcRecord { return this.context.record; }
25
26     dataLoaded: boolean;
27     showHelp: boolean;
28     randId = Math.floor(Math.random() * 100000);
29     stackSubfields: boolean;
30
31     constructor(
32         private idl: IdlService,
33         private org: OrgService,
34         private tagTable: TagTableService
35     ) {}
36
37     ngOnInit() {
38         this.init().then(_ =>
39             this.context.recordChange.subscribe(__ => this.init()));
40
41         // Changing the Type fixed field means loading new meta-metadata.
42         this.record.fixedFieldChange.pipe(filter(code => code === 'Type'))
43         .subscribe(_ => this.init());
44     }
45
46     init(): Promise<any> {
47         this.dataLoaded = false;
48
49         if (!this.record) { return Promise.resolve(); }
50
51         return Promise.all([
52             this.tagTable.loadTagTable({marcRecordType: this.context.recordType}),
53             this.tagTable.getFfPosTable(this.record.recordType()),
54             this.tagTable.getFfValueTable(this.record.recordType())
55         ]).then(_ =>
56             // setTimeout forces all of our sub-components to rerender
57             // themselves each time init() is called.  Without this,
58             // changing the record Type would only re-render the fixed
59             // fields editor when data had to be fetched from the
60             // network.  (Sometimes the data is cached).
61             setTimeout(() => this.dataLoaded = true)
62         );
63     }
64
65     undoCount(): number {
66         return this.context.undoStack.length;
67     }
68
69     redoCount(): number {
70         return this.context.redoStack.length;
71     }
72
73     undo() {
74         this.context.requestUndo();
75     }
76
77     redo() {
78         this.context.requestRedo();
79     }
80
81     controlFields(): MarcField[] {
82         return this.record.fields.filter(f => f.isControlfield());
83     }
84
85     dataFields(): MarcField[] {
86         return this.record.fields.filter(f => !f.isControlfield());
87     }
88 }
89
90
91