From 622bcfd45c7321f9e343d18b50211908d4782fce Mon Sep 17 00:00:00 2001 From: Jane Sandberg Date: Tue, 1 Sep 2020 11:26:21 -0700 Subject: [PATCH] LP1849212: more work on simplified editor Signed-off-by: Jane Sandberg --- .../simplified-editor-field.directive.ts | 24 +++++++++++++--------- .../simplified-editor-subfield.directive.ts | 11 ++++++++-- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/staff/share/marc-edit/simplified-editor/simplified-editor-field.directive.ts b/Open-ILS/src/eg2/src/app/staff/share/marc-edit/simplified-editor/simplified-editor-field.directive.ts index 833fa0010d..a5e7e0a76f 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/marc-edit/simplified-editor/simplified-editor-field.directive.ts +++ b/Open-ILS/src/eg2/src/app/staff/share/marc-edit/simplified-editor/simplified-editor-field.directive.ts @@ -1,4 +1,4 @@ -import {Directive, Host, Input, OnInit, ViewChildren, QueryList, AfterViewInit} from '@angular/core'; +import {Directive, Host, Input, OnInit, AfterViewInit} from '@angular/core'; import {MarcSimplifiedEditorComponent} from './simplified-editor.component'; import {MarcField, MarcSubfield} from '../marcrecord'; import {MarcSimplifiedEditorSubfieldDirective} from './simplified-editor-subfield.directive'; @@ -17,11 +17,12 @@ export class MarcSimplifiedEditorFieldDirective implements OnInit, AfterViewInit @Input() ind1 = ' '; @Input() ind2 = ' '; - @ViewChildren(MarcSimplifiedEditorSubfieldDirective) - subfields: QueryList; + subfieldIndex = 1; marcVersion: MarcField; + addSubfield: (code: string, defaultValue?: string) => void; + constructor(@Host() private editor: MarcSimplifiedEditorComponent) {} ngOnInit() { @@ -35,18 +36,21 @@ export class MarcSimplifiedEditorFieldDirective implements OnInit, AfterViewInit indicator: (ind: number) => (ind === 1) ? this.ind1 : this.ind2, deleteExactSubfields: (...subfield: MarcSubfield[]) => 0, // not used by the simplified editor }; - } - ngAfterViewInit() { - this.subfields.forEach((subfield: MarcSimplifiedEditorSubfieldDirective, index: number) => { + this.addSubfield = (code: string, defaultValue?: string) => { this.marcVersion.subfields.push( [ - subfield.code, - subfield.defaultValue ? subfield.defaultValue : '', - index + code, + defaultValue ? defaultValue : '', + this.subfieldIndex ] ); - }); + this.subfieldIndex += 1; + + } + } + + ngAfterViewInit() { this.editor.addField(this.marcVersion); } diff --git a/Open-ILS/src/eg2/src/app/staff/share/marc-edit/simplified-editor/simplified-editor-subfield.directive.ts b/Open-ILS/src/eg2/src/app/staff/share/marc-edit/simplified-editor/simplified-editor-subfield.directive.ts index d6ff39fa8c..d9474a85c5 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/marc-edit/simplified-editor/simplified-editor-subfield.directive.ts +++ b/Open-ILS/src/eg2/src/app/staff/share/marc-edit/simplified-editor/simplified-editor-subfield.directive.ts @@ -1,4 +1,5 @@ -import {Directive, Input} from '@angular/core'; +import {Directive, Input, Host, OnInit} from '@angular/core'; +import {MarcSimplifiedEditorFieldDirective} from './simplified-editor-field.directive'; /** * A subfield that a user can edit, which will later be @@ -8,9 +9,15 @@ import {Directive, Input} from '@angular/core'; @Directive({ selector: 'eg-marc-simplified-editor-subfield', }) -export class MarcSimplifiedEditorSubfieldDirective { +export class MarcSimplifiedEditorSubfieldDirective implements OnInit { @Input() code: string; @Input() defaultValue: string; + constructor(@Host() private field: MarcSimplifiedEditorFieldDirective) {} + + ngOnInit() { + this.field.addSubfield(this.code, this.defaultValue); + } + } -- 2.11.0