LP1849212: more work on simplified editor
authorJane Sandberg <sandbej@linnbenton.edu>
Tue, 1 Sep 2020 18:26:21 +0000 (11:26 -0700)
committerJane Sandberg <sandbej@linnbenton.edu>
Tue, 1 Sep 2020 18:26:21 +0000 (11:26 -0700)
Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
Open-ILS/src/eg2/src/app/staff/share/marc-edit/simplified-editor/simplified-editor-field.directive.ts
Open-ILS/src/eg2/src/app/staff/share/marc-edit/simplified-editor/simplified-editor-subfield.directive.ts

index 833fa00..a5e7e0a 100644 (file)
@@ -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<MarcSimplifiedEditorSubfieldDirective>;
+  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);
   }
 
index d6ff39f..d9474a8 100644 (file)
@@ -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);
+  }
+
 }