--- /dev/null
+
+<input
+ id='marc-editable-content-{{randId}}'
+ class="p-0 pl-1 pr-1 rounded-0 form-control"
+ [size]="inputSize()"
+ [maxlength]="maxLength || ''"
+ [disabled]="readOnly"
+ (blur)="propagateTouch()"
+ [(ngModel)]="content"
+/>
+
--- /dev/null
+import {Component, Input, Output, OnInit, EventEmitter, forwardRef} from '@angular/core';
+import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms';
+import {MarcRecord} from './marcrecord';
+import {MarcEditContext} from './editor-context';
+
+/**
+ * MARC Tag Editor Component
+ */
+
+@Component({
+ selector: 'eg-marc-editable-content',
+ templateUrl: './editable-content.component.html',
+ providers: [{
+ provide: NG_VALUE_ACCESSOR,
+ useExisting: forwardRef(() => EditableContentComponent),
+ multi: true
+ }]
+})
+
+export class EditableContentComponent implements OnInit, ControlValueAccessor {
+
+ @Input() context: MarcEditContext;
+ @Input() readOnly: boolean;
+ @Input() content: string;
+ @Input() maxLength: number;
+
+ get record(): MarcRecord { return this.context.record; }
+
+ randId: string;
+
+ // Stub functions required by ControlValueAccessor
+ propagateChange = (_: any) => {};
+ propagateTouch = () => {};
+
+ constructor() {
+ this.randId = Math.random().toFixed(5);
+ }
+
+ ngOnInit() {}
+
+ inputSize(): number {
+ return (this.content || ' ').length * 1.1;
+ }
+
+ valueChange() {
+ this.propagateChange(this.content);
+ }
+
+ writeValue(content: string) {
+ this.content = content;
+ }
+
+ registerOnChange(fn) {
+ this.propagateChange = fn;
+ }
+
+ registerOnTouched(fn) {
+ this.propagateTouch = fn;
+ }
+}
+
}
// NgbPopovers don't always close when we want them to,
- // specifcially when context-clicking.
+ // specifcially when context-clicking to open other popovers.
closePopovers() {
this.popOvers.forEach(p => p.close());
}
-
}
<ng-template #menuContent>
<div *ngFor="let value of fieldValues" class="menu-entry">
- <a (click)="fieldValue=value.value">
+ <a (click)="valueChange(value.value)">
<span class="font-monospace">{{value.label}}</span>
</a>
</div>
<label for='fixed-field-input-{{field}}' class="pr-2 flex-1">
{{fieldLabel}}
</label>
-
- <input id='fixed-field-input-{{field}}' type="text"
- (change)="valueChange($event)"
- class="form-control p-1 flex-1" [(ngModel)]="fieldValue"
- [attr.maxlength]="fieldSize" [attr.size]="fieldSize"
+ <input id='fixed-field-input-{{fieldCode}}-{{randId}}'
+ class="form-control rounded-0 flex-1 pl-1" type="text"
+ (change)="valueChange()"
+ [(ngModel)]="fieldValue"
+ [attr.maxlength]="fieldLength" [attr.size]="fieldLength"
[ngbPopover]="menuContent"
#p="ngbPopover" triggers="manual"
(contextmenu)="contextMenu($event, p)"
- />
+ />
</div>
+
</ng-container>
fieldValue: string;
fieldMeta: any;
- fieldSize: number = null;
+ fieldLength: number = null;
fieldValues: FixedFieldValue[] = null;
popOver: NgbPopover;
+ randId: string;
constructor(
private tagTable: TagTableService
- ) {}
+ ) {
+ this.randId = Math.random().toFixed(5);
+ }
ngOnInit() {
this.init().then(_ =>
return;
}
- this.fieldSize = this.fieldMeta.length || 1;
+ this.fieldLength = this.fieldMeta.length || 1;
this.fieldValue =
this.context.record.extractFixedField(this.fieldCode);
// Shuffling may occur with our fixed field as a result of
// external changes.
- this.record.fixedFieldChange.subscribe(_ =>
+ this.record.fixedFieldChange.subscribe(_ => {
this.fieldValue =
this.context.record.extractFixedField(this.fieldCode)
- );
+ });
return this.tagTable.getFFValueTable(this.record.recordType());
});
}
- valueChange(newVal) {
+ valueChange(newVal?: string) {
+ if (newVal !== undefined) {
+ // needed for context menu
+ this.fieldValue = newVal;
+ }
this.context.record.setFixedField(this.fieldCode, this.fieldValue);
}
import {FixedFieldsEditorComponent} from './fixed-fields-editor.component';
import {FixedFieldComponent} from './fixed-field.component';
import {TagTableService} from './tagtable.service';
+import {EditableContentComponent} from './editable-content.component';
@NgModule({
declarations: [
MarcRichEditorComponent,
MarcFlatEditorComponent,
FixedFieldsEditorComponent,
- FixedFieldComponent
+ FixedFieldComponent,
+ EditableContentComponent
],
imports: [
StaffCommonModule
// Emits the fixed field code.
fixedFieldChange: EventEmitter<string>;
+ get leader(): string {
+ return this.record.leader;
+ }
+
+ set leader(l: string) {
+ this.record.leader = l;
+ }
+
+ get fields(): any[] {
+ return this.record.fields;
+ }
+
+ set fields(f: any[]) {
+ this.record.fields = f;
+ }
+
constructor(xml: string) {
this.record = new MARC21.Record({marcxml: xml, delimiter: DELIMITER});
this.breakerText = this.record.toBreaker();
<div class="mt-3 text-monospace"
(contextmenu)="$event.preventDefault()">
<div class="row">
- <div class="col-lg-10">
+ <div class="col-lg-9">
<eg-fixed-fields-editor [context]="context"></eg-fixed-fields-editor>
</div>
</div>
+ <div class="row pt-0 pb-0 pl-3 form-horizontal">
+ <eg-marc-editable-content [context]="context" [ngModel]="'LDR'"
+ [maxLength]="3" [readOnly]="true"></eg-marc-editable-content>
+ <eg-marc-editable-content [context]="context" [(ngModel)]="record.leader"
+ [maxLength]="record.leader.length"></eg-marc-editable-content>
+ </div>
+ <div class="row pt-0 pb-0 pl-3 form-horizontal"
+ *ngFor="let field of controlFields()">
+ <eg-marc-editable-content [context]="context" [(ngModel)]="field.tag"
+ [maxLength]="3"></eg-marc-editable-content>
+ <eg-marc-editable-content [context]="context" [(ngModel)]="field.data">
+ </eg-marc-editable-content>
+ </div>
+ <div class="row pt-0 pb-0 pl-3 form-horizontal"
+ *ngFor="let field of dataFields()">
+ <eg-marc-editable-content [context]="context" [(ngModel)]="field.tag"
+ [maxLength]="3"></eg-marc-editable-content>
+ <eg-marc-editable-content [context]="context" [(ngModel)]="field.ind1"
+ [maxLength]="1"></eg-marc-editable-content>
+ <eg-marc-editable-content [context]="context" [(ngModel)]="field.ind2"
+ [maxLength]="1"></eg-marc-editable-content>
+
+ <ng-container *ngFor="let subfield of field.subfields">
+ <!-- subfield character -->
+ <eg-marc-editable-content [context]="context" [(ngModel)]="subfield[0]"
+ [maxLength]="1"></eg-marc-editable-content>
+ <!-- subfield value -->
+ <eg-marc-editable-content [context]="context" [(ngModel)]="subfield[1]">
+ </eg-marc-editable-content>
+ </ng-container>
+ </div>
</div>
</ng-container>
this.tagTable.getFFValueTable(this.record.recordType())
]).then(_ => this.dataLoaded = true);
}
+
+ controlFields(): any[] {
+ return this.record.fields.filter(f => f.isControlfield());
+ }
+
+ dataFields(): any[] {
+ return this.record.fields.filter(f => !f.isControlfield());
+ }
+
}