angular flat marc edit
authorBill Erickson <berickxx@gmail.com>
Thu, 27 Jun 2019 21:18:44 +0000 (17:18 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 27 Jun 2019 21:18:44 +0000 (17:18 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/staff/share/marc-edit/editor.component.html
Open-ILS/src/eg2/src/app/staff/share/marc-edit/editor.component.ts
Open-ILS/src/eg2/src/app/staff/share/marc-edit/flat-editor.component.html
Open-ILS/src/eg2/src/app/staff/share/marc-edit/flat-editor.component.ts
Open-ILS/src/eg2/src/app/staff/share/marc-edit/marc-edit.module.ts

index 4b1171a..5b8de51 100644 (file)
@@ -2,6 +2,13 @@
 
 <div class="row d-flex p-2 m-2">
   <div class="flex-1"></div>
+  <div class="mr-2">
+    <eg-combobox #sourceSelector
+      [entries]="sources"
+      placeholder="Select a Source..."
+      i18n-placeholder>
+    </eg-combobox>
+  </div>
   <button class="btn btn-success" (click)="saveRecord()" i18n>
     Save Changes</button>
 </div>
index f0ec986..e2a91f4 100644 (file)
@@ -1,4 +1,4 @@
-import {Component, Input, Output, OnInit, EventEmitter} from '@angular/core';
+import {Component, Input, Output, OnInit, EventEmitter, ViewChild} from '@angular/core';
 import {IdlService} from '@eg/core/idl.service';
 import {EventService} from '@eg/core/event.service';
 import {NetService} from '@eg/core/net.service';
@@ -6,6 +6,8 @@ import {AuthService} from '@eg/core/auth.service';
 import {OrgService} from '@eg/core/org.service';
 import {PcrudService} from '@eg/core/pcrud.service';
 import {MarcRecord} from './marcrecord';
+import {ComboboxEntry, ComboboxComponent
+  } from '@eg/share/combobox/combobox.component';
 
 /**
  * MARC Record editor main interface.
@@ -20,6 +22,7 @@ export class MarcEditorComponent implements OnInit {
 
     record: MarcRecord;
     editorTab: 'rich' | 'flat';
+    sources: ComboboxEntry[];
 
     @Input() set recordId(id: number) {
         if (!id) { return; }
@@ -41,6 +44,8 @@ export class MarcEditorComponent implements OnInit {
     // the record is successfully saved.
     @Output() recordSaved: EventEmitter<string>;
 
+    @ViewChild('sourceSelector') sourceSelector: ComboboxComponent;
+
     constructor(
         private evt: EventService,
         private idl: IdlService,
@@ -49,13 +54,23 @@ export class MarcEditorComponent implements OnInit {
         private org: OrgService,
         private pcrud: PcrudService
     ) {
+        this.sources = [];
         this.recordSaved = new EventEmitter<string>();
     }
 
-
     ngOnInit() {
         // Default to flat for now since it's all that's supported.
         this.editorTab = 'flat';
+
+        this.pcrud.retrieveAll('cbs').subscribe(
+            src => this.sources.push({id: +src.id(), label: src.source()}),
+            _ => {},
+            () => {
+                this.sources = this.sources.sort((a, b) => 
+                    a.label.toLowerCase() < b.label.toLowerCase() ? -1 : 1
+                );
+            }
+        );
     }
 
     saveRecord(): Promise<any> {
@@ -67,14 +82,15 @@ export class MarcEditorComponent implements OnInit {
             return Promise.resolve();
         }
 
+        const source = this.sourceSelector.selected ?
+            this.sourceSelector.selected.label : null; // 'label' not a typo
+
         if (this.record.id) { // Editing an existing record
 
             const method = 'open-ils.cat.biblio.record.marc.replace';
 
-            return this.net.request(
-                'open-ils.cat', method,
-                this.auth.token(), this.record.id,
-                xml, null /* TODO: record source */
+            return this.net.request('open-ils.cat', method,
+                this.auth.token(), this.record.id, xml, source
             ).toPromise().then(response => {
 
                 const evt = this.evt.parse(response);
@@ -98,6 +114,9 @@ export class MarcEditorComponent implements OnInit {
         .toPromise().then(bib => {
             this.record = new MarcRecord(bib.marc());
             this.record.id = id;
+            if (bib.source()) {
+                this.sourceSelector.applyEntryId(+bib.source());
+            }
         });
     }
 
index 57f725b..eaf54a9 100644 (file)
@@ -2,6 +2,6 @@
 <div *ngIf="record">
   <textarea class="form-control flat-editor-content" 
     (blur)="record.absorbBreakerChanges()"
-    [(ngModel)]="record.breakerText" rows="40" spellcheck="false">
+    [(ngModel)]="record.breakerText" rows="{{rowCount()}}" spellcheck="false">
   </textarea>
 </div>
index f51214e..74b0729 100644 (file)
@@ -30,6 +30,15 @@ export class MarcFlatEditorComponent implements OnInit {
     }
 
     ngOnInit() {}
+
+    // When we have breaker text, limit the vertical expansion of the 
+    // text area to the size of the data plus a little padding.
+    rowCount(): number {
+        if (this.record && this.record.breakerText) {
+            return this.record.breakerText.split(/\n/).length + 2; 
+        }
+        return 40;
+    }
 }
 
 
index 796fb96..1992fcb 100644 (file)
@@ -1,5 +1,5 @@
 import {NgModule} from '@angular/core';
-import {EgCommonModule} from '@eg/common.module';
+import {StaffCommonModule} from '@eg/staff/common.module';                     
 import {MarcEditorComponent} from './editor.component';
 import {MarcRichEditorComponent} from './rich-editor.component';
 import {MarcFlatEditorComponent} from './flat-editor.component';
@@ -11,7 +11,7 @@ import {MarcFlatEditorComponent} from './flat-editor.component';
         MarcFlatEditorComponent
     ],
     imports: [
-        EgCommonModule
+        StaffCommonModule
     ],
     exports: [
         MarcEditorComponent