LP1849212: try to add comboboxes to simplified editor
authorJane Sandberg <sandbej@linnbenton.edu>
Tue, 1 Sep 2020 19:45:57 +0000 (12:45 -0700)
committerJane Sandberg <sandbej@linnbenton.edu>
Tue, 1 Sep 2020 22:24:24 +0000 (15:24 -0700)
Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-associate-material.component.html
Open-ILS/src/eg2/src/app/staff/share/marc-edit/simplified-editor/simplified-editor.component.html
Open-ILS/src/eg2/src/app/staff/share/marc-edit/simplified-editor/simplified-editor.component.ts

index da60360..2b3cdfa 100644 (file)
                     placeholder="e.g. Required" class="flex-grow-1" />
                 </div>
               </div>
-              <eg-marc-simplified-editor (xmlRecordEvent)="associateBriefRecord($event)" buttonLabel="Add material" i18n-buttonLabel>
+              <eg-marc-simplified-editor (xmlRecordEvent)="associateBriefRecord($event)"
+              buttonLabel="Add material" i18n-buttonLabel defaultMarcForm="o">
                 <eg-marc-simplified-editor-field tag="245" ind1="0" ind2="0">
                   <eg-marc-simplified-editor-subfield code="a"></eg-marc-simplified-editor-subfield>
                 </eg-marc-simplified-editor-field>
index aeecb1c..df23cb9 100644 (file)
@@ -1,5 +1,17 @@
-<ng-container *ngIf="editor && subfieldLabels">
+<ng-container *ngIf="editor && subfieldLabels && marcForms && marcTypes">
   <form [formGroup]="editor">
+    <div class="row">
+      <div class="col-lg-3" i18n>Form</div>
+      <div class="col-lg-9">
+        <eg-combobox #formCombobox [entries]="marcForms" formControlName="marcForm"></eg-combobox>
+      </div>
+    </div>
+    <div class="row">
+      <div class="col-lg-3" i18n>Type</div>
+      <div class="col-lg-9">
+        <eg-combobox #typeCombobox [entries]="marcTypes" formControlName="marcType"></eg-combobox>
+      </div>
+    </div>   
     <ng-container *ngFor="let field of fields">
       <div class="row" *ngFor="let subfield of field.subfields">
         <ng-container *ngIf="!subfield[1]">
index 2675f25..15db235 100644 (file)
@@ -1,7 +1,13 @@
 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
@@ -16,9 +22,12 @@ export class MarcSimplifiedEditorComponent implements AfterViewInit, OnInit {
 
     @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;
@@ -31,13 +40,17 @@ export class MarcSimplifiedEditorComponent implements AfterViewInit, OnInit {
     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) => {
@@ -53,6 +66,24 @@ export class MarcSimplifiedEditorComponent implements AfterViewInit, OnInit {
             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() {
@@ -76,9 +107,23 @@ export class MarcSimplifiedEditorComponent implements AfterViewInit, OnInit {
             })
         });
         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 : ' ';
+    }
+
+
 }