import {AfterViewInit, Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
-import {FormGroup, FormControl, ValidationErrors, ValidatorFn, FormArray} from '@angular/forms';
+import {FormGroup, FormControl} from '@angular/forms';
import {MarcField, MarcRecord} from '../marcrecord';
import {TagTableService} from '../tagtable.service';
+import {NetService} from '@eg/core/net.service';
+import { ComboboxEntry } from '@eg/share/combobox/combobox.component';
+import { Observable, of } from 'rxjs';
+import { switchMap } from 'rxjs/operators';
+
+const DEFAULT_RECORD_TYPE = 'BKS';
/**
* A simplified editor for basic MARC records, which
@Input() buttonLabel: string;
@Output() xmlRecordEvent = new EventEmitter<string>();
+ @Input() defaultMarcForm: string;
fields: MarcField[] = [];
editor: FormGroup;
+ marcForms: ComboboxEntry[];
+ marcTypes: ComboboxEntry[];
// DOM id prefix to prevent id collisions.
idPrefix: string;
editorFieldIdentifier: (field: MarcField, subfield: Array<any>) => string;
constructor(
+ private net: NetService,
private tagTable: TagTableService
) {}
ngOnInit() {
// Add some randomness to the generated DOM IDs to ensure against clobbering
this.idPrefix = 'marc-simplified-editor-' + Math.floor(Math.random() * 100000);
- this.editor = new FormGroup({});
+ this.editor = new FormGroup({
+ marcForm: new FormControl(),
+ marcType: new FormControl()
+ });
// Add a fieldId, and then add a new field to the array
this.addField = (field: MarcField) => {
return field.tag + subfield[0]; // e.g. 245a
}
+ this.net.request('open-ils.cat',
+ 'open-ils.cat.biblio.fixed_field_values.by_rec_type',
+ DEFAULT_RECORD_TYPE, 'Form')
+ .subscribe((forms) => {
+ this.marcForms = forms['Form'].map((form) => {
+ return {id: form[0], label: form[1]}
+ })
+ });
+
+ this.net.request('open-ils.cat',
+ 'open-ils.cat.biblio.fixed_field_values.by_rec_type',
+ DEFAULT_RECORD_TYPE, 'Type')
+ .subscribe((types) => {
+ this.marcTypes = types['Type'].map((type) => {
+ return {id: type[0], label: type[1]}
+ })
+ });
+
}
ngAfterViewInit() {
})
});
record.fields = this.fields;
+ record.setFixedField('Type', this.appropriateMarcType);
+ record.setFixedField('Form', this.appropriateMarcForm);
this.xmlRecordEvent.emit(record.toXml());
}
+ get appropriateMarcType(): string {
+ return this.editor.get('marcType').value ? this.editor.get('marcType').value.id : 'a';
+ }
+
+ get appropriateMarcForm(): string {
+ if (this.editor.get('marcForm').value) {
+ return this.editor.get('marcForm').value.id;
+ }
+ return this.defaultMarcForm ? this.defaultMarcForm : ' ';
+ }
+
+
}