LP1849212: marc simplified editor field and subfield as directives
authorJane Sandberg <sandbej@linnbenton.edu>
Tue, 1 Sep 2020 17:56:29 +0000 (10:56 -0700)
committerJane Sandberg <sandbej@linnbenton.edu>
Tue, 1 Sep 2020 17:56:29 +0000 (10:56 -0700)
Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
Open-ILS/src/eg2/src/app/staff/share/marc-edit/simplified-editor/simplified-editor-field.component.ts [deleted file]
Open-ILS/src/eg2/src/app/staff/share/marc-edit/simplified-editor/simplified-editor-field.directive.ts [new file with mode: 0644]
Open-ILS/src/eg2/src/app/staff/share/marc-edit/simplified-editor/simplified-editor-subfield.component.ts [deleted file]
Open-ILS/src/eg2/src/app/staff/share/marc-edit/simplified-editor/simplified-editor-subfield.directive.ts [new file with mode: 0644]
Open-ILS/src/eg2/src/app/staff/share/marc-edit/simplified-editor/simplified-editor.component.ts
Open-ILS/src/eg2/src/app/staff/share/marc-edit/simplified-editor/simplified-editor.module.ts

diff --git a/Open-ILS/src/eg2/src/app/staff/share/marc-edit/simplified-editor/simplified-editor-field.component.ts b/Open-ILS/src/eg2/src/app/staff/share/marc-edit/simplified-editor/simplified-editor-field.component.ts
deleted file mode 100644 (file)
index 0638ec5..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-import {Component, Host, Input, OnInit, Output, ViewChildren, QueryList, AfterViewInit} from '@angular/core';
-import {MarcSimplifiedEditorComponent} from './simplified-editor.component';
-import {MarcField, MarcSubfield} from '../marcrecord';
-import { MarcSimplifiedEditorSubfieldComponent } from './simplified-editor-subfield.component';
-
-/**
- * A field that a user can edit, which will later be
- * compiled into MARC
- */
-
-@Component({
-  selector: 'eg-marc-simplified-editor-field',
-  template: '<ng-template></ng-template>'
-})
-export class MarcSimplifiedEditorFieldComponent implements OnInit, AfterViewInit {
-
-  @Input() tag = 'a';
-  @Input() ind1 = ' ';
-  @Input() ind2 = ' ';
-
-  @ViewChildren(MarcSimplifiedEditorSubfieldComponent)
-    subfields: QueryList<MarcSimplifiedEditorSubfieldComponent>;
-
-  marcVersion: MarcField;
-
-  addSubfield: (subfield: MarcSubfield) => void;
-
-  constructor(@Host() private editor: MarcSimplifiedEditorComponent) {}
-
-  ngOnInit() {
-    this.marcVersion = {
-      tag: this.tag,
-      authValid: false,
-      authChecked: false,
-      isCtrlField: false,
-      isControlfield: () => false,
-      indicator: (ind: number) => (ind === 1) ? this.ind1 : this.ind2,
-      deleteExactSubfields: (...subfield: MarcSubfield[]) => 0, // not used by the simplified editor
-    };
-  }
-
-  ngAfterViewInit() {
-    this.subfields.forEach((subfield: MarcSimplifiedEditorSubfieldComponent, index: number) => {
-      this.marcVersion.subfields.push(
-        [
-          subfield.code,
-          subfield.defaultValue ? subfield.defaultValue : '',
-          index
-        ]
-      );
-    });
-    this.editor.addField(this.marcVersion);
-  }
-
-}
-
-
-
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
new file mode 100644 (file)
index 0000000..833fa00
--- /dev/null
@@ -0,0 +1,56 @@
+import {Directive, Host, Input, OnInit, ViewChildren, QueryList, AfterViewInit} from '@angular/core';
+import {MarcSimplifiedEditorComponent} from './simplified-editor.component';
+import {MarcField, MarcSubfield} from '../marcrecord';
+import {MarcSimplifiedEditorSubfieldDirective} from './simplified-editor-subfield.directive';
+
+/**
+ * A field that a user can edit, which will later be
+ * compiled into MARC
+ */
+
+@Directive({
+  selector: 'eg-marc-simplified-editor-field',
+})
+export class MarcSimplifiedEditorFieldDirective implements OnInit, AfterViewInit {
+
+  @Input() tag = 'a';
+  @Input() ind1 = ' ';
+  @Input() ind2 = ' ';
+
+  @ViewChildren(MarcSimplifiedEditorSubfieldDirective)
+    subfields: QueryList<MarcSimplifiedEditorSubfieldDirective>;
+
+  marcVersion: MarcField;
+
+  constructor(@Host() private editor: MarcSimplifiedEditorComponent) {}
+
+  ngOnInit() {
+    this.marcVersion = {
+      tag: this.tag,
+      subfields: [],
+      authValid: false,
+      authChecked: false,
+      isCtrlField: false,
+      isControlfield: () => false,
+      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.marcVersion.subfields.push(
+        [
+          subfield.code,
+          subfield.defaultValue ? subfield.defaultValue : '',
+          index
+        ]
+      );
+    });
+    this.editor.addField(this.marcVersion);
+  }
+
+}
+
+
+
diff --git a/Open-ILS/src/eg2/src/app/staff/share/marc-edit/simplified-editor/simplified-editor-subfield.component.ts b/Open-ILS/src/eg2/src/app/staff/share/marc-edit/simplified-editor/simplified-editor-subfield.component.ts
deleted file mode 100644 (file)
index 93195cf..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-import {Component, Input} from '@angular/core';
-
-/**
- * A subfield that a user can edit, which will later be
- * compiled into MARC
- */
-
-@Component({
-  selector: 'eg-marc-simplified-editor-subfield',
-  template: '<ng-template></ng-template>'
-})
-export class MarcSimplifiedEditorSubfieldComponent {
-
-  @Input() code: string;
-  @Input() defaultValue: string;
-
-}
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
new file mode 100644 (file)
index 0000000..d6ff39f
--- /dev/null
@@ -0,0 +1,16 @@
+import {Directive, Input} from '@angular/core';
+
+/**
+ * A subfield that a user can edit, which will later be
+ * compiled into MARC
+ */
+
+@Directive({
+  selector: 'eg-marc-simplified-editor-subfield',
+})
+export class MarcSimplifiedEditorSubfieldDirective {
+
+  @Input() code: string;
+  @Input() defaultValue: string;
+
+}
index 80f900a..ca3d142 100644 (file)
@@ -59,9 +59,11 @@ export class MarcSimplifiedEditorComponent implements AfterViewInit, OnInit {
         const record = new MarcRecord('<record xmlns="http://www.loc.gov/MARC21/slim"></record>');
         // need to add the value to field.subfields[0][1]
         this.fields.forEach((field) => {
-            if (field.subfields[0][1] === '') { // Default value has not been applied
-                field.subfields[0][1] = this.editor.get(String(field.fieldId)).value;
-            }
+            field.subfields.forEach((subfield) => {
+                if (subfield[1] === '') { // Default value has not been applied
+                    subfield[1] = this.editor.get(String(field.fieldId)).value;
+                }  
+            })
         });
         record.fields = this.fields;
         this.xmlRecordEvent.emit(record.toXml());
index 3c0fe7a..e17ad0e 100644 (file)
@@ -2,15 +2,15 @@ import {NgModule} from '@angular/core';
 import {StaffCommonModule} from '@eg/staff/common.module';
 import {CommonWidgetsModule} from '@eg/share/common-widgets.module';
 import {MarcSimplifiedEditorComponent} from './simplified-editor.component';
-import {MarcSimplifiedEditorFieldComponent} from './simplified-editor-field.component';
-import {MarcSimplifiedEditorSubfieldComponent} from './simplified-editor-subfield.component';
+import {MarcSimplifiedEditorFieldDirective} from './simplified-editor-field.directive';
+import {MarcSimplifiedEditorSubfieldDirective} from './simplified-editor-subfield.directive';
 import {TagTableService} from '../tagtable.service';
 
 @NgModule({
     declarations: [
         MarcSimplifiedEditorComponent,
-        MarcSimplifiedEditorFieldComponent,
-        MarcSimplifiedEditorSubfieldComponent,
+        MarcSimplifiedEditorFieldDirective,
+        MarcSimplifiedEditorSubfieldDirective,
     ],
     imports: [
         StaffCommonModule,
@@ -18,8 +18,8 @@ import {TagTableService} from '../tagtable.service';
     ],
     exports: [
         MarcSimplifiedEditorComponent,
-        MarcSimplifiedEditorFieldComponent,
-        MarcSimplifiedEditorSubfieldComponent
+        MarcSimplifiedEditorFieldDirective,
+        MarcSimplifiedEditorSubfieldDirective
     ],
     providers: [
         TagTableService